From 05b818e709da9ebb25f02a163eb9f13adc6cb3d5 Mon Sep 17 00:00:00 2001 From: wusheng Date: Sun, 10 Dec 2017 16:32:39 +0800 Subject: [PATCH] Update package name to org.apache.skywalking --- java.header => CHECKSTYLE_HEAD | 0 ApacheCopyright => HEADER | 0 .../apm-toolkit-log4j-1.x/pom.xml | 2 +- .../log4j/v1/x/TraceIdPatternConverter.java | 54 + .../log/log4j/v1/x/TraceIdPatternLayout.java | 53 + .../log/log4j/v1/x/TraceIdPatternParser.java | 59 ++ .../log4j/v1/x/TraceIdPatternConverter.java | 36 - .../log/log4j/v1/x/TraceIdPatternLayout.java | 35 - .../log/log4j/v1/x/TraceIdPatternParser.java | 41 - .../apm-toolkit-log4j-2.x/pom.xml | 2 +- .../log/log4j/v2/x/Log4j2OutputAppender.java | 52 + .../log/log4j/v2/x/TraceIdConverter.java | 74 ++ .../log/log4j/v2/x/Log4j2OutputAppender.java | 34 - .../log/log4j/v2/x/TraceIdConverter.java | 56 - .../apm-toolkit-logback-1.x/pom.xml | 2 +- .../logback/v1/x/LogbackPatternConverter.java | 57 ++ .../v1/x/TraceIdPatternLogbackLayout.java | 52 + .../v1/x/mdc/LogbackMDCPatternConverter.java | 66 ++ .../x/mdc/TraceIdMDCPatternLogbackLayout.java | 49 + .../logback/v1/x/LogbackPatternConverter.java | 39 - .../v1/x/TraceIdPatternLogbackLayout.java | 34 - .../v1/x/mdc/LogbackMDCPatternConverter.java | 48 - .../x/mdc/TraceIdMDCPatternLogbackLayout.java | 31 - .../apm-toolkit-opentracing/pom.xml | 2 +- .../opentracing/ByteBufferContext.java | 64 ++ .../opentracing/NeedSnifferActivation.java | 54 + .../opentracing/SkywalkingActiveSpan.java | 20 +- .../opentracing/SkywalkingContext.java | 57 ++ .../opentracing/SkywalkingContinuation.java | 57 ++ .../toolkit/opentracing/SkywalkingSpan.java | 20 +- .../opentracing/SkywalkingSpanBuilder.java | 20 +- .../toolkit/opentracing/SkywalkingTracer.java | 79 ++ .../apm/toolkit/opentracing/Tag.java | 58 ++ .../toolkit/opentracing/TextMapContext.java | 54 + .../opentracing/ByteBufferContext.java | 46 - .../opentracing/NeedSnifferActivation.java | 36 - .../opentracing/SkywalkingContext.java | 39 - .../opentracing/SkywalkingContinuation.java | 39 - .../toolkit/opentracing/SkywalkingTracer.java | 61 -- .../apm/toolkit/opentracing/Tag.java | 40 - .../toolkit/opentracing/TextMapContext.java | 36 - .../META-INF.services/io.opentracing.Tracer | 2 +- .../apm-toolkit-trace/pom.xml | 2 +- .../apm/toolkit/trace/ActiveSpan.java | 52 + .../skywalking/apm/toolkit/trace/Trace.java | 58 ++ .../apm/toolkit/trace/TraceContext.java | 57 ++ .../apm/toolkit/trace/ActiveSpan.java | 34 - .../skywalking/apm/toolkit/trace/Trace.java | 40 - .../apm/toolkit/trace/TraceContext.java | 39 - .../collector/agent/grpc/AgentGRPCModule.java | 55 + .../collector/agent/grpc/AgentGRPCModule.java | 37 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../agent/grpc/AgentModuleGRPCProvider.java | 116 +++ .../grpc/AgentModuleGRPCRegistration.java | 58 ++ .../ApplicationRegisterServiceHandler.java | 82 ++ .../InstanceDiscoveryServiceHandler.java | 101 ++ .../handler/JVMMetricsServiceHandler.java | 119 +++ .../ServiceNameDiscoveryServiceHandler.java | 87 ++ .../handler/TraceSegmentServiceHandler.java | 80 ++ .../naming/AgentGRPCNamingHandler.java | 71 ++ .../naming/AgentGRPCNamingListener.java | 61 ++ .../agent/grpc/AgentModuleGRPCProvider.java | 98 -- .../grpc/AgentModuleGRPCRegistration.java | 40 - .../ApplicationRegisterServiceHandler.java | 64 -- .../InstanceDiscoveryServiceHandler.java | 83 -- .../handler/JVMMetricsServiceHandler.java | 101 -- .../ServiceNameDiscoveryServiceHandler.java | 69 -- .../handler/TraceSegmentServiceHandler.java | 62 -- .../naming/AgentGRPCNamingHandler.java | 53 - .../naming/AgentGRPCNamingListener.java | 43 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - ...icationRegisterServiceHandlerTestCase.java | 64 ++ ...icationRegisterServiceHandlerTestCase.java | 46 - .../agent/jetty/AgentJettyModule.java | 55 + .../agent/jetty/AgentJettyModule.java | 37 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../agent/jetty/AgentModuleJettyProvider.java | 115 +++ .../jetty/AgentModuleJettyRegistration.java | 59 ++ .../ApplicationRegisterServletHandler.java | 94 ++ .../InstanceDiscoveryServletHandler.java | 97 ++ .../ServiceNameDiscoveryServiceHandler.java | 101 ++ .../handler/TraceSegmentServletHandler.java | 98 ++ .../naming/AgentJettyNamingHandler.java | 71 ++ .../naming/AgentJettyNamingListener.java | 61 ++ .../reader/KeyWithStringValueJsonReader.java | 72 ++ .../jetty/handler/reader/LogJsonReader.java | 73 ++ .../handler/reader/ReferenceJsonReader.java | 22 +- .../handler/reader/SegmentJsonReader.java | 22 +- .../jetty/handler/reader/SpanJsonReader.java | 22 +- .../handler/reader/StreamJsonReader.java | 47 + .../jetty/handler/reader/TraceSegment.java | 65 ++ .../reader/TraceSegmentJsonReader.java | 83 ++ .../handler/reader/UniqueIdJsonReader.java | 58 ++ .../agent/jetty/AgentModuleJettyProvider.java | 97 -- .../jetty/AgentModuleJettyRegistration.java | 41 - .../ApplicationRegisterServletHandler.java | 76 -- .../InstanceDiscoveryServletHandler.java | 79 -- .../ServiceNameDiscoveryServiceHandler.java | 83 -- .../handler/TraceSegmentServletHandler.java | 80 -- .../naming/AgentJettyNamingHandler.java | 53 - .../naming/AgentJettyNamingListener.java | 43 - .../reader/KeyWithStringValueJsonReader.java | 54 - .../jetty/handler/reader/LogJsonReader.java | 55 - .../handler/reader/StreamJsonReader.java | 29 - .../jetty/handler/reader/TraceSegment.java | 47 - .../reader/TraceSegmentJsonReader.java | 65 -- .../handler/reader/UniqueIdJsonReader.java | 40 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../handler/ApplicationRegisterPost.java | 51 + .../agent/jetty/handler/HttpClientTools.java | 20 +- .../jetty/handler/InstanceRegisterPost.java | 51 + .../agent/jetty/handler/JsonFileReader.java | 60 ++ .../agent/jetty/handler/SegmentPost.java | 68 ++ .../handler/ServiceNameRegisterPost.java | 51 + .../handler/ApplicationRegisterPost.java | 33 - .../jetty/handler/InstanceRegisterPost.java | 33 - .../agent/jetty/handler/JsonFileReader.java | 42 - .../agent/jetty/handler/SegmentPost.java | 50 - .../handler/ServiceNameRegisterPost.java | 33 - .../agent/stream/AgentStreamModule.java | 86 ++ .../graph/ApplicationGraphNodeIdDefine.java | 46 + .../graph/InstanceGraphNodeIdDefine.java | 46 + .../graph/JvmMetricStreamGraphDefine.java | 48 + .../graph/RegisterStreamGraphDefine.java | 46 + .../graph/ServiceGraphNodeIdDefine.java | 46 + .../stream/service/jvm/ICpuMetricService.java | 46 + .../stream/service/jvm/IGCMetricService.java | 46 + .../jvm/IInstanceHeartBeatService.java | 46 + .../service/jvm/IMemoryMetricService.java | 46 + .../service/jvm/IMemoryPoolMetricService.java | 46 + .../register/IApplicationIDService.java | 46 + .../service/register/IInstanceIDService.java | 48 + .../service/register/IServiceNameService.java | 46 + .../service/trace/ITraceSegmentService.java | 47 + .../stream/service/trace/MetricSource.java | 44 + .../agent/stream/AgentStreamModule.java | 68 -- .../graph/ApplicationGraphNodeIdDefine.java | 28 - .../graph/InstanceGraphNodeIdDefine.java | 28 - .../graph/JvmMetricStreamGraphDefine.java | 30 - .../graph/RegisterStreamGraphDefine.java | 28 - .../graph/ServiceGraphNodeIdDefine.java | 28 - .../stream/service/jvm/ICpuMetricService.java | 28 - .../stream/service/jvm/IGCMetricService.java | 28 - .../jvm/IInstanceHeartBeatService.java | 28 - .../service/jvm/IMemoryMetricService.java | 28 - .../service/jvm/IMemoryPoolMetricService.java | 28 - .../register/IApplicationIDService.java | 28 - .../service/register/IInstanceIDService.java | 30 - .../service/register/IServiceNameService.java | 28 - .../service/trace/ITraceSegmentService.java | 29 - .../stream/service/trace/MetricSource.java | 26 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../agent/stream/AgentStreamBootStartup.java | 98 ++ .../stream/AgentStreamModuleProvider.java | 115 +++ .../agent/stream/IdAutoIncrement.java | 60 ++ .../agent/stream/buffer/BufferFileConfig.java | 20 +- .../collector/agent/stream/buffer/Offset.java | 20 +- .../agent/stream/buffer/OffsetManager.java | 28 +- .../stream/buffer/SegmentBufferManager.java | 30 +- .../stream/buffer/SegmentBufferReader.java | 32 +- .../agent/stream/graph/GraphDefine.java | 45 + .../stream/graph/JvmMetricStreamGraph.java | 109 ++ .../stream/graph/RegisterStreamGraph.java | 103 ++ .../agent/stream/graph/TraceStreamGraph.java | 208 ++++ .../stream/parser/EntrySpanListener.java | 46 + .../agent/stream/parser/ExitSpanListener.java | 46 + .../stream/parser/FirstSpanListener.java | 46 + .../stream/parser/GlobalTraceIdsListener.java | 46 + .../stream/parser/LocalSpanListener.java | 46 + .../agent/stream/parser/SegmentParse.java | 254 +++++ .../agent/stream/parser/SpanListener.java | 44 + .../parser/standardization/IdExchanger.java | 44 + .../standardization/ReferenceDecorator.java | 26 +- .../standardization/ReferenceIdExchanger.java | 34 +- .../standardization/SegmentDecorator.java | 92 ++ .../SegmentStandardization.java | 60 ++ .../SegmentStandardizationWorker.java | 94 ++ .../parser/standardization/SpanDecorator.java | 26 +- .../standardization/SpanIdExchanger.java | 97 ++ .../standardization/StandardBuilder.java | 44 + .../agent/stream/util/FileUtils.java | 22 +- .../worker/AgentStreamRemoteDataRegister.java | 71 ++ .../jvm/CpuMetricPersistenceWorker.java | 84 ++ .../stream/worker/jvm/CpuMetricService.java | 74 ++ .../worker/jvm/GCMetricPersistenceWorker.java | 84 ++ .../stream/worker/jvm/GCMetricService.java | 76 ++ .../jvm/InstHeartBeatPersistenceWorker.java | 84 ++ .../worker/jvm/InstanceHeartBeatService.java | 73 ++ .../jvm/MemoryMetricPersistenceWorker.java | 84 ++ .../worker/jvm/MemoryMetricService.java | 79 ++ .../MemoryPoolMetricPersistenceWorker.java | 84 ++ .../worker/jvm/MemoryPoolMetricService.java | 79 ++ .../worker/register/ApplicationIDService.java | 92 ++ .../ApplicationRegisterRemoteWorker.java | 83 ++ .../ApplicationRegisterSerialWorker.java | 116 +++ .../worker/register/InstanceIDService.java | 120 +++ .../InstanceRegisterRemoteWorker.java | 83 ++ .../InstanceRegisterSerialWorker.java | 115 +++ .../ServiceNameRegisterRemoteWorker.java | 82 ++ .../ServiceNameRegisterSerialWorker.java | 119 +++ .../worker/register/ServiceNameService.java | 93 ++ .../worker/trace/TraceSegmentService.java | 59 ++ ...ApplicationComponentAggregationWorker.java | 73 ++ ...ApplicationComponentPersistenceWorker.java | 84 ++ .../ApplicationComponentRemoteWorker.java | 78 ++ .../ApplicationComponentSpanListener.java | 104 ++ .../ApplicationMappingAggregationWorker.java | 73 ++ .../ApplicationMappingPersistenceWorker.java | 84 ++ .../ApplicationMappingRemoteWorker.java | 77 ++ .../ApplicationMappingSpanListener.java | 91 ++ .../ApplicationMetricAggregationWorker.java | 92 ++ .../ApplicationMetricPersistenceWorker.java | 84 ++ .../ApplicationMetricRemoteWorker.java | 77 ++ ...ationReferenceMetricAggregationWorker.java | 110 ++ ...ationReferenceMetricPersistenceWorker.java | 86 ++ ...pplicationReferenceMetricRemoteWorker.java | 78 ++ ...pplicationReferenceMetricSpanListener.java | 46 +- .../global/GlobalTracePersistenceWorker.java | 84 ++ .../trace/global/GlobalTraceSpanListener.java | 96 ++ .../InstanceMetricPersistenceWorker.java | 84 ++ .../instance/InstanceMetricSpanListener.java | 95 ++ ...tanceReferenceMetricAggregationWorker.java | 102 ++ .../InstanceReferenceMetricRemoteWorker.java | 79 ++ .../InstanceReferencePersistenceWorker.java | 85 ++ .../segment/SegmentCostPersistenceWorker.java | 84 ++ .../segment/SegmentCostSpanListener.java | 123 +++ .../segment/SegmentPersistenceWorker.java | 83 ++ .../ServiceEntryAggregationWorker.java | 73 ++ .../ServiceEntryPersistenceWorker.java | 83 ++ .../service/ServiceEntryRemoteWorker.java | 78 ++ .../service/ServiceEntrySpanListener.java | 106 ++ .../ServiceMetricAggregationWorker.java | 89 ++ .../ServiceMetricPersistenceWorker.java | 84 ++ .../service/ServiceMetricRemoteWorker.java | 77 ++ ...rviceReferenceMetricAggregationWorker.java | 74 ++ ...rviceReferenceMetricPersistenceWorker.java | 85 ++ .../ServiceReferenceMetricRemoteWorker.java | 79 ++ .../ServiceReferenceMetricSpanListener.java | 48 +- .../agent/stream/AgentStreamBootStartup.java | 80 -- .../stream/AgentStreamModuleProvider.java | 97 -- .../agent/stream/IdAutoIncrement.java | 42 - .../agent/stream/graph/GraphDefine.java | 27 - .../stream/graph/JvmMetricStreamGraph.java | 91 -- .../stream/graph/RegisterStreamGraph.java | 85 -- .../agent/stream/graph/TraceStreamGraph.java | 190 ---- .../stream/parser/EntrySpanListener.java | 28 - .../agent/stream/parser/ExitSpanListener.java | 28 - .../stream/parser/FirstSpanListener.java | 28 - .../stream/parser/GlobalTraceIdsListener.java | 28 - .../stream/parser/LocalSpanListener.java | 28 - .../agent/stream/parser/SegmentParse.java | 236 ----- .../agent/stream/parser/SpanListener.java | 26 - .../parser/standardization/IdExchanger.java | 26 - .../standardization/SegmentDecorator.java | 74 -- .../SegmentStandardization.java | 42 - .../SegmentStandardizationWorker.java | 76 -- .../standardization/SpanIdExchanger.java | 79 -- .../standardization/StandardBuilder.java | 26 - .../worker/AgentStreamRemoteDataRegister.java | 53 - .../jvm/CpuMetricPersistenceWorker.java | 66 -- .../stream/worker/jvm/CpuMetricService.java | 56 - .../worker/jvm/GCMetricPersistenceWorker.java | 66 -- .../stream/worker/jvm/GCMetricService.java | 58 -- .../jvm/InstHeartBeatPersistenceWorker.java | 66 -- .../worker/jvm/InstanceHeartBeatService.java | 55 - .../jvm/MemoryMetricPersistenceWorker.java | 66 -- .../worker/jvm/MemoryMetricService.java | 61 -- .../MemoryPoolMetricPersistenceWorker.java | 66 -- .../worker/jvm/MemoryPoolMetricService.java | 61 -- .../worker/register/ApplicationIDService.java | 74 -- .../ApplicationRegisterRemoteWorker.java | 65 -- .../ApplicationRegisterSerialWorker.java | 98 -- .../worker/register/InstanceIDService.java | 102 -- .../InstanceRegisterRemoteWorker.java | 65 -- .../InstanceRegisterSerialWorker.java | 97 -- .../ServiceNameRegisterRemoteWorker.java | 64 -- .../ServiceNameRegisterSerialWorker.java | 101 -- .../worker/register/ServiceNameService.java | 75 -- .../worker/trace/TraceSegmentService.java | 41 - ...ApplicationComponentAggregationWorker.java | 55 - ...ApplicationComponentPersistenceWorker.java | 66 -- .../ApplicationComponentRemoteWorker.java | 60 -- .../ApplicationComponentSpanListener.java | 86 -- .../ApplicationMappingAggregationWorker.java | 55 - .../ApplicationMappingPersistenceWorker.java | 66 -- .../ApplicationMappingRemoteWorker.java | 59 -- .../ApplicationMappingSpanListener.java | 73 -- .../ApplicationMetricAggregationWorker.java | 74 -- .../ApplicationMetricPersistenceWorker.java | 66 -- .../ApplicationMetricRemoteWorker.java | 59 -- ...ationReferenceMetricAggregationWorker.java | 92 -- ...ationReferenceMetricPersistenceWorker.java | 68 -- ...pplicationReferenceMetricRemoteWorker.java | 60 -- .../global/GlobalTracePersistenceWorker.java | 66 -- .../trace/global/GlobalTraceSpanListener.java | 78 -- .../InstanceMetricPersistenceWorker.java | 66 -- .../instance/InstanceMetricSpanListener.java | 77 -- ...tanceReferenceMetricAggregationWorker.java | 84 -- .../InstanceReferenceMetricRemoteWorker.java | 61 -- .../InstanceReferencePersistenceWorker.java | 67 -- .../segment/SegmentCostPersistenceWorker.java | 66 -- .../segment/SegmentCostSpanListener.java | 105 -- .../segment/SegmentPersistenceWorker.java | 65 -- .../ServiceEntryAggregationWorker.java | 55 - .../ServiceEntryPersistenceWorker.java | 65 -- .../service/ServiceEntryRemoteWorker.java | 60 -- .../service/ServiceEntrySpanListener.java | 88 -- .../ServiceMetricAggregationWorker.java | 71 -- .../ServiceMetricPersistenceWorker.java | 66 -- .../service/ServiceMetricRemoteWorker.java | 59 -- ...rviceReferenceMetricAggregationWorker.java | 56 - ...rviceReferenceMetricPersistenceWorker.java | 67 -- .../ServiceReferenceMetricRemoteWorker.java | 61 -- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../collector/alerting/AlertingModule.java | 55 + .../collector/alerting/AlertingModule.java | 37 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../alerting/AlertingModuleProvider.java | 74 ++ .../worker/AlertingListAggregationWorker.java | 60 ++ .../worker/AlertingListPersistenceWorker.java | 84 ++ .../alerting/AlertingModuleProvider.java | 56 - .../worker/AlertingListAggregationWorker.java | 42 - .../worker/AlertingListPersistenceWorker.java | 66 -- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../baseline/computing/ComputingModule.java | 56 + .../baseline/computing/ComputingModule.java | 38 - ...kywalking.apm.collector.core.module.Module | 2 +- .../computing/provider/ComputingProvider.java | 76 ++ .../computing/provider/ComputingProvider.java | 58 -- ...g.apm.collector.core.module.ModuleProvider | 2 +- .../bin/collectorService.bat | 2 +- .../bin/collectorService.sh | 2 +- .../docker/collectorService.sh | 2 +- .../apm-collector-boot/docker/log4j2.xml | 4 +- .../src/main/assembly/log4j2.xml | 4 +- .../collector/boot/CollectorBootStartUp.java | 77 ++ .../boot/config/ApplicationConfigLoader.java | 24 +- .../config/ConfigFileNotFoundException.java | 53 + .../collector/boot/config/ConfigLoader.java | 44 + .../collector/boot/CollectorBootStartUp.java | 59 -- .../config/ConfigFileNotFoundException.java | 35 - .../collector/boot/config/ConfigLoader.java | 26 - .../src/main/resources/log4j2.xml | 4 +- .../apm/collector/cache/CacheModule.java | 59 ++ .../service/ApplicationCacheService.java | 48 + .../cache/service/InstanceCacheService.java | 48 + .../cache/service/ServiceIdCacheService.java | 46 + .../service/ServiceNameCacheService.java | 48 + .../apm/collector/cache/CacheModule.java | 41 - .../service/ApplicationCacheService.java | 30 - .../cache/service/InstanceCacheService.java | 30 - .../cache/service/ServiceIdCacheService.java | 28 - .../service/ServiceNameCacheService.java | 30 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../cache/guava/CacheModuleGuavaProvider.java | 84 ++ .../service/ApplicationCacheGuavaService.java | 109 ++ .../service/InstanceCacheGuavaService.java | 111 ++ .../service/ServiceIdCacheGuavaService.java | 89 ++ .../service/ServiceNameCacheGuavaService.java | 104 ++ .../cache/guava/CacheModuleGuavaProvider.java | 66 -- .../service/ApplicationCacheGuavaService.java | 91 -- .../service/InstanceCacheGuavaService.java | 93 -- .../service/ServiceIdCacheGuavaService.java | 71 -- .../service/ServiceNameCacheGuavaService.java | 86 -- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../collector/cluster/ClusterException.java | 53 + .../apm/collector/cluster/ClusterModule.java | 58 ++ .../cluster/ClusterModuleListener.java | 70 ++ .../cluster/ClusterNodeExistException.java | 51 + .../apm/collector/cluster/DataMonitor.java | 59 ++ .../collector/cluster/ModuleRegistration.java | 73 ++ .../service/ModuleListenerService.java | 47 + .../service/ModuleRegisterService.java | 47 + .../collector/cluster/ClusterException.java | 35 - .../apm/collector/cluster/ClusterModule.java | 40 - .../cluster/ClusterModuleListener.java | 52 - .../cluster/ClusterNodeExistException.java | 33 - .../apm/collector/cluster/DataMonitor.java | 41 - .../collector/cluster/ModuleRegistration.java | 55 - .../service/ModuleListenerService.java | 29 - .../service/ModuleRegisterService.java | 29 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../redis/ClusterModuleRedisProvider.java | 75 ++ .../service/RedisModuleRegisterService.java | 50 + .../redis/ClusterModuleRedisProvider.java | 57 -- .../service/RedisModuleRegisterService.java | 32 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../ClusterModuleStandaloneProvider.java | 108 ++ .../ClusterStandaloneDataMonitor.java | 109 ++ .../StandaloneModuleListenerService.java | 57 ++ .../StandaloneModuleRegisterService.java | 58 ++ .../ClusterModuleStandaloneProvider.java | 90 -- .../ClusterStandaloneDataMonitor.java | 91 -- .../StandaloneModuleListenerService.java | 39 - .../StandaloneModuleRegisterService.java | 40 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../ClusterModuleZookeeperProvider.java | 108 ++ .../zookeeper/ClusterZKDataMonitor.java | 40 +- .../ZookeeperModuleListenerService.java | 57 ++ .../ZookeeperModuleRegisterService.java | 58 ++ .../ClusterModuleZookeeperProvider.java | 90 -- .../ZookeeperModuleListenerService.java | 39 - .../ZookeeperModuleRegisterService.java | 40 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../apm/collector/client/Client.java | 46 + .../apm/collector/client/ClientException.java | 52 + .../elasticsearch/ElasticSearchClient.java | 24 +- .../ElasticSearchClientException.java | 52 + .../apm/collector/client/grpc/GRPCClient.java | 75 ++ .../client/grpc/GRPCClientException.java | 53 + .../apm/collector/client/h2/H2Client.java | 22 +- .../client/h2/H2ClientException.java | 53 + .../collector/client/redis/RedisClient.java | 69 ++ .../client/redis/RedisClientException.java | 53 + .../client/zookeeper/ZookeeperClient.java | 22 +- .../zookeeper/ZookeeperClientException.java | 52 + .../client/zookeeper/util/PathUtils.java | 52 + .../apm/collector/client/Client.java | 28 - .../apm/collector/client/ClientException.java | 34 - .../ElasticSearchClientException.java | 34 - .../apm/collector/client/grpc/GRPCClient.java | 57 -- .../client/grpc/GRPCClientException.java | 35 - .../client/h2/H2ClientException.java | 35 - .../collector/client/redis/RedisClient.java | 51 - .../client/redis/RedisClientException.java | 35 - .../zookeeper/ZookeeperClientException.java | 34 - .../client/zookeeper/util/PathUtils.java | 34 - .../apm/collector/server/Server.java | 53 + .../apm/collector/server/ServerException.java | 53 + .../apm/collector/server/ServerHandler.java | 43 + .../collector/server/grpc/GRPCHandler.java | 45 + .../apm/collector/server/grpc/GRPCServer.java | 91 ++ .../server/grpc/GRPCServerException.java | 53 + .../server/jetty/ArgumentsParseException.java | 53 + .../collector/server/jetty/JettyHandler.java | 24 +- .../collector/server/jetty/JettyServer.java | 104 ++ .../server/jetty/JettyServerException.java | 53 + .../apm/collector/server/Server.java | 35 - .../apm/collector/server/ServerException.java | 35 - .../apm/collector/server/ServerHandler.java | 25 - .../collector/server/grpc/GRPCHandler.java | 27 - .../apm/collector/server/grpc/GRPCServer.java | 73 -- .../server/grpc/GRPCServerException.java | 35 - .../server/jetty/ArgumentsParseException.java | 35 - .../collector/server/jetty/JettyServer.java | 86 -- .../server/jetty/JettyServerException.java | 35 - .../configuration/ConfigurationModule.java | 56 + .../service/IApdexThresholdService.java | 53 + .../configuration/ConfigurationModule.java | 38 - .../service/IApdexThresholdService.java | 35 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../ConfigurationModuleProvider.java | 74 ++ .../service/ApdexThresholdService.java | 53 + .../ConfigurationModuleProvider.java | 56 - .../service/ApdexThresholdService.java | 35 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../collector/core/CollectorException.java | 51 + .../collector/core/UnexpectedException.java | 46 + .../apm/collector/core/cache/Collection.java | 61 ++ .../apm/collector/core/cache/Window.java | 104 ++ .../core/data/AbstractHashMessage.java | 61 ++ .../apm/collector/core/data/Attribute.java | 64 ++ .../collector/core/data/AttributeType.java | 44 + .../apm/collector/core/data/Column.java | 58 ++ .../apm/collector/core/data/ColumnDefine.java | 58 ++ .../apm/collector/core/data/CommonTable.java | 46 + .../apm/collector/core/data/Data.java | 20 +- .../core/data/EndOfBatchQueueMessage.java | 58 ++ .../apm/collector/core/data/Operation.java | 54 + .../core/data/StorageDefineLoader.java | 66 ++ .../core/data/StorageDefinitionFile.java | 48 + .../apm/collector/core/data/TableDefine.java | 67 ++ .../core/data/operator/AddOperation.java | 69 ++ .../core/data/operator/CoverOperation.java | 68 ++ .../core/data/operator/NonOperation.java | 68 ++ .../core/define/DefineException.java | 53 + .../collector/core/define/DefinitionFile.java | 51 + .../core/define/DefinitionLoader.java | 20 +- .../apm/collector/core/define/Loader.java | 44 + .../collector/core/framework/Executor.java | 46 + .../apm/collector/core/graph/DirectWay.java | 50 + .../apm/collector/core/graph/Graph.java | 90 ++ .../collector/core/graph/GraphManager.java | 77 ++ .../collector/core/graph/GraphNodeFinder.java | 61 ++ .../core/graph/GraphNotFoundException.java | 46 + .../apm/collector/core/graph/Next.java | 68 ++ .../apm/collector/core/graph/Node.java | 79 ++ .../core/graph/NodeNotFoundException.java | 46 + .../collector/core/graph/NodeProcessor.java | 51 + .../graph/PotentialCyclicGraphException.java | 46 + .../apm/collector/core/graph/WayToNode.java | 63 ++ .../core/module/ApplicationConfiguration.java | 20 +- .../collector/core/module/BootstrapFlow.java | 22 +- .../core/module/CycleDependencyException.java | 46 + .../module/DuplicateProviderException.java | 43 + .../apm/collector/core/module/Module.java | 20 +- .../collector/core/module/ModuleManager.java | 20 +- .../core/module/ModuleNotFoundException.java | 48 + .../ModuleNotFoundRuntimeException.java | 51 + .../collector/core/module/ModuleProvider.java | 20 +- .../module/ProviderNotFoundException.java | 47 + .../apm/collector/core/module/Service.java | 47 + .../module/ServiceNotProvidedException.java | 43 + .../ServiceNotProvidedRuntimeException.java | 43 + .../core/util/ApdexThresholdUtils.java | 57 ++ .../apm/collector/core/util/BytesUtils.java | 61 ++ .../collector/core/util/CollectionUtils.java | 75 ++ .../collector/core/util/ColumnNameUtils.java | 62 ++ .../apm/collector/core/util/Const.java | 54 + .../apm/collector/core/util/ObjectUtils.java | 50 + .../collector/core/util/ResourceUtils.java | 58 ++ .../apm/collector/core/util/StringUtils.java | 53 + .../collector/core/util/TimeBucketUtils.java | 22 +- .../collector/core/CollectorException.java | 33 - .../collector/core/UnexpectedException.java | 28 - .../apm/collector/core/cache/Collection.java | 43 - .../apm/collector/core/cache/Window.java | 86 -- .../core/data/AbstractHashMessage.java | 43 - .../apm/collector/core/data/Attribute.java | 46 - .../collector/core/data/AttributeType.java | 26 - .../apm/collector/core/data/Column.java | 40 - .../apm/collector/core/data/ColumnDefine.java | 40 - .../apm/collector/core/data/CommonTable.java | 28 - .../core/data/EndOfBatchQueueMessage.java | 40 - .../apm/collector/core/data/Operation.java | 36 - .../core/data/StorageDefineLoader.java | 48 - .../core/data/StorageDefinitionFile.java | 30 - .../apm/collector/core/data/TableDefine.java | 49 - .../core/data/operator/AddOperation.java | 51 - .../core/data/operator/CoverOperation.java | 50 - .../core/data/operator/NonOperation.java | 50 - .../core/define/DefineException.java | 35 - .../collector/core/define/DefinitionFile.java | 33 - .../apm/collector/core/define/Loader.java | 26 - .../collector/core/framework/Executor.java | 28 - .../apm/collector/core/graph/DirectWay.java | 32 - .../apm/collector/core/graph/Graph.java | 72 -- .../collector/core/graph/GraphManager.java | 59 -- .../collector/core/graph/GraphNodeFinder.java | 43 - .../core/graph/GraphNotFoundException.java | 28 - .../apm/collector/core/graph/Next.java | 50 - .../apm/collector/core/graph/Node.java | 61 -- .../core/graph/NodeNotFoundException.java | 28 - .../collector/core/graph/NodeProcessor.java | 33 - .../graph/PotentialCyclicGraphException.java | 28 - .../apm/collector/core/graph/WayToNode.java | 45 - .../core/module/CycleDependencyException.java | 28 - .../module/DuplicateProviderException.java | 25 - .../core/module/ModuleNotFoundException.java | 30 - .../ModuleNotFoundRuntimeException.java | 33 - .../module/ProviderNotFoundException.java | 29 - .../apm/collector/core/module/Service.java | 29 - .../module/ServiceNotProvidedException.java | 25 - .../ServiceNotProvidedRuntimeException.java | 25 - .../core/util/ApdexThresholdUtils.java | 39 - .../apm/collector/core/util/BytesUtils.java | 43 - .../collector/core/util/CollectionUtils.java | 57 -- .../collector/core/util/ColumnNameUtils.java | 44 - .../apm/collector/core/util/Const.java | 36 - .../apm/collector/core/util/ObjectUtils.java | 32 - .../collector/core/util/ResourceUtils.java | 40 - .../apm/collector/core/util/StringUtils.java | 35 - .../core/data/AbstractHashMessageTest.java | 57 ++ .../core/define/DefinitionLoaderTest.java | 2 +- .../collector/core/define/ServiceImpl.java | 43 + .../core/define/ServiceInterface.java | 43 + .../collector/core/define/TestDefineFile.java | 46 + .../core/graph/GraphManagerTest.java | 20 +- .../collector/core/graph/Node1Processor.java | 51 + .../collector/core/graph/Node2Processor.java | 51 + .../collector/core/graph/Node3Processor.java | 52 + .../collector/core/graph/Node4Processor.java | 52 + .../collector/core/graph/OutputProcessor.java | 48 + .../module/ApplicationConfigurationTest.java | 59 ++ .../collector/core/module/BaseModuleA.java | 58 ++ .../collector/core/module/BaseModuleB.java | 58 ++ .../core/module/ModuleABusiness1Impl.java | 46 + .../core/module/ModuleABusiness2Impl.java | 44 + .../core/module/ModuleAProvider.java | 68 ++ .../core/module/ModuleBBusiness1Impl.java | 43 + .../core/module/ModuleBBusiness2Impl.java | 43 + .../core/module/ModuleBProvider.java | 68 ++ .../core/module/ModuleManagerTest.java | 59 ++ .../apm/collector/core/module/TestModule.java | 50 + .../core/module/TestModuleProvider.java | 68 ++ .../collector/core/util/BytesUtilsTest.java | 50 + .../core/util/CollectionUtilsTest.java | 69 ++ .../core/util/ColumnNameUtilsTest.java | 51 + .../collector/core/util/ObjectUtilsTest.java | 51 + .../core/util/ResourceUtilsTest.java | 60 ++ .../collector/core/util/StringUtilsTest.java | 53 + .../core/util/TimeBucketUtilsTest.java | 74 ++ .../core/data/AbstractHashMessageTest.java | 39 - .../collector/core/define/ServiceImpl.java | 25 - .../core/define/ServiceInterface.java | 25 - .../collector/core/define/TestDefineFile.java | 28 - .../collector/core/graph/Node1Processor.java | 33 - .../collector/core/graph/Node2Processor.java | 33 - .../collector/core/graph/Node3Processor.java | 34 - .../collector/core/graph/Node4Processor.java | 34 - .../collector/core/graph/OutputProcessor.java | 30 - .../module/ApplicationConfigurationTest.java | 41 - .../collector/core/module/BaseModuleA.java | 40 - .../collector/core/module/BaseModuleB.java | 40 - .../core/module/ModuleABusiness1Impl.java | 28 - .../core/module/ModuleABusiness2Impl.java | 26 - .../core/module/ModuleAProvider.java | 50 - .../core/module/ModuleBBusiness1Impl.java | 25 - .../core/module/ModuleBBusiness2Impl.java | 25 - .../core/module/ModuleBProvider.java | 50 - .../core/module/ModuleManagerTest.java | 41 - .../apm/collector/core/module/TestModule.java | 32 - .../core/module/TestModuleProvider.java | 50 - .../collector/core/util/BytesUtilsTest.java | 32 - .../core/util/CollectionUtilsTest.java | 51 - .../core/util/ColumnNameUtilsTest.java | 33 - .../collector/core/util/ObjectUtilsTest.java | 33 - .../core/util/ResourceUtilsTest.java | 42 - .../collector/core/util/StringUtilsTest.java | 35 - .../core/util/TimeBucketUtilsTest.java | 56 - .../META-INF/defines/test_define.define | 2 +- ...kywalking.apm.collector.core.module.Module | 22 + ...g.apm.collector.core.module.ModuleProvider | 22 + ...kywalking.apm.collector.core.module.Module | 39 - ...g.apm.collector.core.module.ModuleProvider | 39 - .../grpc/manager/GRPCManagerModule.java | 56 + .../manager/service/GRPCManagerService.java | 47 + .../grpc/manager/GRPCManagerModule.java | 38 - .../manager/service/GRPCManagerService.java | 29 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../grpc/manager/GRPCManagerProvider.java | 90 ++ .../service/GRPCManagerServiceImpl.java | 74 ++ .../grpc/manager/GRPCManagerProvider.java | 72 -- .../service/GRPCManagerServiceImpl.java | 56 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../collector/instrument/MetricCollector.java | 20 +- .../instrument/ServiceInstrumentation.java | 22 +- .../instrument/ServiceMetricTracing.java | 76 ++ .../collector/instrument/TracedService.java | 47 + .../instrument/ServiceMetricTracing.java | 58 -- .../collector/instrument/TracedService.java | 29 - .../jetty/manager/JettyManagerModule.java | 56 + .../manager/service/JettyManagerService.java | 50 + .../jetty/manager/JettyManagerModule.java | 38 - .../manager/service/JettyManagerService.java | 32 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../jetty/manager/JettyManagerProvider.java | 90 ++ .../service/JettyManagerServiceImpl.java | 85 ++ .../jetty/manager/JettyManagerProvider.java | 72 -- .../service/JettyManagerServiceImpl.java | 67 -- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../apm/collector/naming/NamingModule.java | 57 ++ .../service/NamingHandlerRegisterService.java | 47 + .../apm/collector/naming/NamingModule.java | 39 - .../service/NamingHandlerRegisterService.java | 29 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../jetty/NamingModuleJettyProvider.java | 88 ++ .../NamingJettyHandlerRegisterService.java | 68 ++ .../jetty/NamingModuleJettyProvider.java | 70 -- .../NamingJettyHandlerRegisterService.java | 50 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../QueueModuleDataCarrierProvider.java | 75 ++ .../DataCarrierQueueCreatorService.java | 51 + .../QueueModuleDataCarrierProvider.java | 57 -- .../DataCarrierQueueCreatorService.java | 33 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../apm/collector/queue/QueueModule.java | 56 + .../queue/base/DaemonThreadFactory.java | 53 + .../collector/queue/base/MessageHolder.java | 58 ++ .../collector/queue/base/QueueCreator.java | 44 + .../queue/base/QueueEventHandler.java | 44 + .../collector/queue/base/QueueExecutor.java | 45 + .../queue/service/QueueCreatorService.java | 48 + .../apm/collector/queue/QueueModule.java | 38 - .../queue/base/DaemonThreadFactory.java | 35 - .../collector/queue/base/MessageHolder.java | 40 - .../collector/queue/base/QueueCreator.java | 26 - .../queue/base/QueueEventHandler.java | 26 - .../collector/queue/base/QueueExecutor.java | 27 - .../queue/service/QueueCreatorService.java | 30 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../QueueModuleDisruptorProvider.java | 75 ++ .../disruptor/base/DisruptorEventHandler.java | 93 ++ .../disruptor/base/DisruptorQueueCreator.java | 89 ++ .../disruptor/base/MessageHolderFactory.java | 52 + .../service/DisruptorQueueCreatorService.java | 58 ++ .../QueueModuleDisruptorProvider.java | 57 -- .../disruptor/base/DisruptorEventHandler.java | 75 -- .../disruptor/base/DisruptorQueueCreator.java | 71 -- .../disruptor/base/MessageHolderFactory.java | 34 - .../service/DisruptorQueueCreatorService.java | 40 - ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../apm/collector/remote/RemoteException.java | 53 + .../apm/collector/remote/RemoteModule.java | 57 ++ .../apm/collector/remote/RoutingRule.java | 44 + .../CommonRemoteDataRegisterService.java | 22 +- .../remote/service/RemoteClient.java | 50 + .../remote/service/RemoteClientService.java | 46 + .../remote/service/RemoteDataIDGetter.java | 46 + .../RemoteDataInstanceCreatorGetter.java | 45 + ...eDataInstanceCreatorNotFoundException.java | 48 + .../RemoteDataMappingIdNotFoundException.java | 48 + .../service/RemoteDataRegisterService.java | 51 + .../service/RemoteDeserializeService.java | 46 + .../remote/service/RemoteSenderService.java | 51 + .../service/RemoteSerializeService.java | 46 + .../collector/remote/service/Selector.java | 44 + .../apm/collector/remote/RemoteException.java | 35 - .../apm/collector/remote/RemoteModule.java | 39 - .../apm/collector/remote/RoutingRule.java | 26 - .../remote/service/RemoteClient.java | 32 - .../remote/service/RemoteClientService.java | 28 - .../remote/service/RemoteDataIDGetter.java | 28 - .../RemoteDataInstanceCreatorGetter.java | 27 - ...eDataInstanceCreatorNotFoundException.java | 30 - .../RemoteDataMappingIdNotFoundException.java | 30 - .../service/RemoteDataRegisterService.java | 33 - .../service/RemoteDeserializeService.java | 28 - .../remote/service/RemoteSenderService.java | 33 - .../service/RemoteSerializeService.java | 28 - .../collector/remote/service/Selector.java | 26 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../remote/grpc/RemoteModuleGRPCProvider.java | 113 ++ .../grpc/RemoteModuleGRPCRegistration.java | 58 ++ .../handler/RemoteCommonServiceHandler.java | 99 ++ .../remote/grpc/service/GRPCRemoteClient.java | 204 ++++ .../grpc/service/GRPCRemoteClientService.java | 69 ++ .../service/GRPCRemoteDeserializeService.java | 65 ++ .../grpc/service/GRPCRemoteSenderService.java | 138 +++ .../service/GRPCRemoteSerializeService.java | 70 ++ .../selector/ForeverFirstSelector.java | 56 + .../service/selector/HashCodeSelector.java | 53 + .../selector/RemoteClientSelector.java | 48 + .../service/selector/RollingSelector.java | 56 + .../remote/grpc/RemoteModuleGRPCProvider.java | 95 -- .../grpc/RemoteModuleGRPCRegistration.java | 40 - .../handler/RemoteCommonServiceHandler.java | 81 -- .../remote/grpc/service/GRPCRemoteClient.java | 171 ---- .../grpc/service/GRPCRemoteClientService.java | 51 - .../service/GRPCRemoteDeserializeService.java | 47 - .../grpc/service/GRPCRemoteSenderService.java | 120 --- .../service/GRPCRemoteSerializeService.java | 52 - .../selector/ForeverFirstSelector.java | 38 - .../service/selector/HashCodeSelector.java | 35 - .../selector/RemoteClientSelector.java | 30 - .../service/selector/RollingSelector.java | 38 - .../src/main/proto/RemoteCommonService.proto | 4 +- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../collector/storage/StorageException.java | 53 + .../storage/StorageInstallException.java | 51 + .../collector/storage/StorageInstaller.java | 84 ++ .../apm/collector/storage/StorageModule.java | 160 +++ .../storage/base/dao/AbstractDAO.java | 54 + .../apm/collector/storage/base/dao/DAO.java | 45 + .../collector/storage/base/dao/IBatchDAO.java | 46 + .../storage/base/dao/IPersistenceDAO.java | 52 + .../storage/base/sql/SqlBuilder.java | 75 ++ .../dao/IAlertingListPersistenceDAO.java | 46 + .../storage/dao/IApplicationCacheDAO.java | 48 + .../IApplicationComponentPersistenceDAO.java | 46 + .../dao/IApplicationComponentUIDAO.java | 47 + .../IApplicationMappingPersistenceDAO.java | 46 + .../storage/dao/IApplicationMappingUIDAO.java | 47 + .../dao/IApplicationMetricPersistenceDAO.java | 46 + ...licationReferenceMetricPersistenceDAO.java | 46 + .../dao/IApplicationReferenceMetricUIDAO.java | 47 + .../storage/dao/IApplicationRegisterDAO.java | 51 + .../storage/dao/ICpuMetricPersistenceDAO.java | 46 + .../storage/dao/ICpuMetricUIDAO.java | 49 + .../storage/dao/IGCMetricPersistenceDAO.java | 46 + .../collector/storage/dao/IGCMetricUIDAO.java | 82 ++ .../dao/IGlobalTracePersistenceDAO.java | 46 + .../storage/dao/IGlobalTraceUIDAO.java | 49 + .../storage/dao/IInstanceCacheDAO.java | 48 + .../dao/IInstanceHeartBeatPersistenceDAO.java | 46 + .../dao/IInstanceMetricPersistenceDAO.java | 46 + .../storage/dao/IInstanceMetricUIDAO.java | 79 ++ ...InstanceReferenceMetricPersistenceDAO.java | 46 + .../storage/dao/IInstanceRegisterDAO.java | 53 + .../collector/storage/dao/IInstanceUIDAO.java | 75 ++ .../dao/IMemoryMetricPersistenceDAO.java | 46 + .../storage/dao/IMemoryMetricUIDAO.java | 49 + .../dao/IMemoryPoolMetricPersistenceDAO.java | 46 + .../storage/dao/IMemoryPoolMetricUIDAO.java | 49 + .../dao/ISegmentCostPersistenceDAO.java | 46 + .../storage/dao/ISegmentCostUIDAO.java | 57 ++ .../storage/dao/ISegmentPersistenceDAO.java | 46 + .../collector/storage/dao/ISegmentUIDAO.java | 47 + .../dao/IServiceEntryPersistenceDAO.java | 46 + .../storage/dao/IServiceEntryUIDAO.java | 47 + .../dao/IServiceMetricPersistenceDAO.java | 46 + .../storage/dao/IServiceNameCacheDAO.java | 48 + .../storage/dao/IServiceNameRegisterDAO.java | 51 + ...IServiceReferenceMetricPersistenceDAO.java | 46 + .../storage/dao/IServiceReferenceUIDAO.java | 48 + .../storage/table/CommonMetricTable.java | 58 ++ .../storage/table/alerting/AlertingList.java | 131 +++ .../table/alerting/AlertingListTable.java | 53 + .../application/ApplicationComponent.java | 92 ++ .../ApplicationComponentTable.java | 48 + .../table/application/ApplicationMapping.java | 92 ++ .../application/ApplicationMappingTable.java | 48 + .../table/application/ApplicationMetric.java | 30 +- .../application/ApplicationMetricTable.java | 50 + .../ApplicationReferenceMetric.java | 30 +- .../ApplicationReferenceMetricTable.java | 51 + .../storage/table/global/GlobalTrace.java | 92 ++ .../table/global/GlobalTraceTable.java | 48 + .../table/instance/InstanceMetric.java | 30 +- .../table/instance/InstanceMetricTable.java | 48 + .../instance/InstanceReferenceMetric.java | 28 +- .../InstanceReferenceMetricTable.java | 48 + .../storage/table/jvm/CpuMetric.java | 96 ++ .../storage/table/jvm/CpuMetricTable.java | 48 + .../collector/storage/table/jvm/GCMetric.java | 113 ++ .../storage/table/jvm/GCMetricTable.java | 50 + .../storage/table/jvm/MemoryMetric.java | 132 +++ .../storage/table/jvm/MemoryMetricTable.java | 52 + .../storage/table/jvm/MemoryPoolMetric.java | 131 +++ .../table/jvm/MemoryPoolMetricTable.java | 52 + .../storage/table/register/Application.java | 82 ++ .../table/register/ApplicationTable.java | 48 + .../storage/table/register/Instance.java | 123 +++ .../storage/table/register/InstanceTable.java | 52 + .../storage/table/register/ServiceName.java | 91 ++ .../table/register/ServiceNameTable.java | 49 + .../storage/table/segment/Segment.java | 84 ++ .../storage/table/segment/SegmentCost.java | 138 +++ .../table/segment/SegmentCostTable.java | 53 + .../storage/table/segment/SegmentTable.java | 47 + .../storage/table/service/ServiceEntry.java | 110 ++ .../table/service/ServiceEntryTable.java | 51 + .../storage/table/service/ServiceMetric.java | 28 +- .../table/service/ServiceMetricTable.java | 47 + .../table/service/ServiceReferenceMetric.java | 28 +- .../service/ServiceReferenceMetricTable.java | 52 + .../collector/storage/StorageException.java | 35 - .../storage/StorageInstallException.java | 33 - .../collector/storage/StorageInstaller.java | 66 -- .../apm/collector/storage/StorageModule.java | 142 --- .../storage/base/dao/AbstractDAO.java | 36 - .../apm/collector/storage/base/dao/DAO.java | 27 - .../collector/storage/base/dao/IBatchDAO.java | 28 - .../storage/base/dao/IPersistenceDAO.java | 34 - .../storage/base/sql/SqlBuilder.java | 57 -- .../dao/IAlertingListPersistenceDAO.java | 28 - .../storage/dao/IApplicationCacheDAO.java | 30 - .../IApplicationComponentPersistenceDAO.java | 28 - .../dao/IApplicationComponentUIDAO.java | 29 - .../IApplicationMappingPersistenceDAO.java | 28 - .../storage/dao/IApplicationMappingUIDAO.java | 29 - .../dao/IApplicationMetricPersistenceDAO.java | 28 - ...licationReferenceMetricPersistenceDAO.java | 28 - .../dao/IApplicationReferenceMetricUIDAO.java | 29 - .../storage/dao/IApplicationRegisterDAO.java | 33 - .../storage/dao/ICpuMetricPersistenceDAO.java | 28 - .../storage/dao/ICpuMetricUIDAO.java | 31 - .../storage/dao/IGCMetricPersistenceDAO.java | 28 - .../collector/storage/dao/IGCMetricUIDAO.java | 64 -- .../dao/IGlobalTracePersistenceDAO.java | 28 - .../storage/dao/IGlobalTraceUIDAO.java | 31 - .../storage/dao/IInstanceCacheDAO.java | 30 - .../dao/IInstanceHeartBeatPersistenceDAO.java | 28 - .../dao/IInstanceMetricPersistenceDAO.java | 28 - .../storage/dao/IInstanceMetricUIDAO.java | 61 -- ...InstanceReferenceMetricPersistenceDAO.java | 28 - .../storage/dao/IInstanceRegisterDAO.java | 35 - .../collector/storage/dao/IInstanceUIDAO.java | 57 -- .../dao/IMemoryMetricPersistenceDAO.java | 28 - .../storage/dao/IMemoryMetricUIDAO.java | 31 - .../dao/IMemoryPoolMetricPersistenceDAO.java | 28 - .../storage/dao/IMemoryPoolMetricUIDAO.java | 31 - .../dao/ISegmentCostPersistenceDAO.java | 28 - .../storage/dao/ISegmentCostUIDAO.java | 39 - .../storage/dao/ISegmentPersistenceDAO.java | 28 - .../collector/storage/dao/ISegmentUIDAO.java | 29 - .../dao/IServiceEntryPersistenceDAO.java | 28 - .../storage/dao/IServiceEntryUIDAO.java | 29 - .../dao/IServiceMetricPersistenceDAO.java | 28 - .../storage/dao/IServiceNameCacheDAO.java | 30 - .../storage/dao/IServiceNameRegisterDAO.java | 33 - ...IServiceReferenceMetricPersistenceDAO.java | 28 - .../storage/dao/IServiceReferenceUIDAO.java | 30 - .../storage/table/CommonMetricTable.java | 40 - .../storage/table/alerting/AlertingList.java | 113 -- .../table/alerting/AlertingListTable.java | 35 - .../application/ApplicationComponent.java | 74 -- .../ApplicationComponentTable.java | 30 - .../table/application/ApplicationMapping.java | 74 -- .../application/ApplicationMappingTable.java | 30 - .../application/ApplicationMetricTable.java | 32 - .../ApplicationReferenceMetricTable.java | 33 - .../storage/table/global/GlobalTrace.java | 74 -- .../table/global/GlobalTraceTable.java | 30 - .../table/instance/InstanceMetricTable.java | 30 - .../InstanceReferenceMetricTable.java | 30 - .../storage/table/jvm/CpuMetric.java | 78 -- .../storage/table/jvm/CpuMetricTable.java | 30 - .../collector/storage/table/jvm/GCMetric.java | 95 -- .../storage/table/jvm/GCMetricTable.java | 32 - .../storage/table/jvm/MemoryMetric.java | 114 --- .../storage/table/jvm/MemoryMetricTable.java | 34 - .../storage/table/jvm/MemoryPoolMetric.java | 113 -- .../table/jvm/MemoryPoolMetricTable.java | 34 - .../storage/table/register/Application.java | 64 -- .../table/register/ApplicationTable.java | 30 - .../storage/table/register/Instance.java | 105 -- .../storage/table/register/InstanceTable.java | 34 - .../storage/table/register/ServiceName.java | 73 -- .../table/register/ServiceNameTable.java | 31 - .../storage/table/segment/Segment.java | 66 -- .../storage/table/segment/SegmentCost.java | 120 --- .../table/segment/SegmentCostTable.java | 35 - .../storage/table/segment/SegmentTable.java | 29 - .../storage/table/service/ServiceEntry.java | 92 -- .../table/service/ServiceEntryTable.java | 33 - .../table/service/ServiceMetricTable.java | 29 - .../service/ServiceReferenceMetricTable.java | 34 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../storage/es/DataTTLKeeperTimer.java | 136 +++ .../es/StorageModuleEsNamingListener.java | 60 ++ .../storage/es/StorageModuleEsProvider.java | 258 +++++ .../es/StorageModuleEsRegistration.java | 58 ++ .../storage/es/base/dao/BatchEsDAO.java | 82 ++ .../collector/storage/es/base/dao/EsDAO.java | 95 ++ .../define/ElasticSearchColumnDefine.java | 52 + .../define/ElasticSearchStorageInstaller.java | 30 +- .../base/define/ElasticSearchTableDefine.java | 55 + .../es/dao/AlertingListEsPersistenceDAO.java | 32 +- .../ApplicationComponentEsPersistenceDAO.java | 32 +- .../es/dao/ApplicationComponentEsUIDAO.java | 28 +- .../storage/es/dao/ApplicationEsCacheDAO.java | 93 ++ .../es/dao/ApplicationEsRegisterDAO.java | 80 ++ .../ApplicationMappingEsPersistenceDAO.java | 32 +- .../es/dao/ApplicationMappingEsUIDAO.java | 28 +- .../ApplicationMetricEsPersistenceDAO.java | 32 +- ...cationReferenceMetricEsPersistenceDAO.java | 32 +- .../ApplicationReferenceMetricEsUIDAO.java | 28 +- .../es/dao/CpuMetricEsPersistenceDAO.java | 94 ++ .../storage/es/dao/CpuMetricEsUIDAO.java | 93 ++ .../es/dao/GCMetricEsPersistenceDAO.java | 95 ++ .../storage/es/dao/GCMetricEsUIDAO.java | 34 +- .../es/dao/GlobalTraceEsPersistenceDAO.java | 94 ++ .../storage/es/dao/GlobalTraceEsUIDAO.java | 101 ++ .../storage/es/dao/InstanceEsCacheDAO.java | 92 ++ .../storage/es/dao/InstanceEsRegisterDAO.java | 100 ++ .../storage/es/dao/InstanceEsUIDAO.java | 32 +- .../InstanceHeartBeatEsPersistenceDAO.java | 91 ++ .../dao/InstanceMetricEsPersistenceDAO.java | 32 +- .../storage/es/dao/InstanceMetricEsUIDAO.java | 32 +- .../es/dao/MemoryMetricEsPersistenceDAO.java | 97 ++ .../storage/es/dao/MemoryMetricEsUIDAO.java | 107 ++ .../dao/MemoryPoolMetricEsPersistenceDAO.java | 97 ++ .../es/dao/MemoryPoolMetricEsUIDAO.java | 106 ++ .../es/dao/SegmentCostEsPersistenceDAO.java | 99 ++ .../storage/es/dao/SegmentCostEsUIDAO.java | 32 +- .../es/dao/SegmentEsPersistenceDAO.java | 93 ++ .../storage/es/dao/SegmentEsUIDAO.java | 77 ++ .../es/dao/ServiceEntryEsPersistenceDAO.java | 98 ++ .../storage/es/dao/ServiceEntryEsUIDAO.java | 32 +- .../es/dao/ServiceMetricEsPersistenceDAO.java | 32 +- .../storage/es/dao/ServiceNameEsCacheDAO.java | 92 ++ .../es/dao/ServiceNameEsRegisterDAO.java | 81 ++ .../es/dao/ServiceReferenceEsUIDAO.java | 32 +- ...erviceReferenceMetricEsPersistenceDAO.java | 32 +- .../es/define/AlertingListEsTableDefine.java | 65 ++ .../ApplicationComponentEsTableDefine.java | 61 ++ .../es/define/ApplicationEsTableDefine.java | 60 ++ .../ApplicationMappingEsTableDefine.java | 61 ++ ...plicationReferenceMetricEsTableDefine.java | 26 +- .../es/define/CpuMetricEsTableDefine.java | 61 ++ .../es/define/GCMetricEsTableDefine.java | 63 ++ .../es/define/GlobalTraceEsTableDefine.java | 61 ++ .../es/define/InstanceEsTableDefine.java | 64 ++ .../define/InstanceMetricEsTableDefine.java | 77 ++ .../es/define/MemoryMetricEsTableDefine.java | 65 ++ .../define/MemoryPoolMetricEsTableDefine.java | 65 ++ .../es/define/SegmentCostEsTableDefine.java | 66 ++ .../es/define/SegmentEsTableDefine.java | 60 ++ .../es/define/ServiceEntryEsTableDefine.java | 63 ++ .../es/define/ServiceMetricEsTableDefine.java | 76 ++ .../es/define/ServiceNameEsTableDefine.java | 61 ++ .../ServiceReferenceMetricEsTableDefine.java | 26 +- .../storage/es/DataTTLKeeperTimer.java | 118 --- .../es/StorageModuleEsNamingListener.java | 42 - .../storage/es/StorageModuleEsProvider.java | 240 ----- .../es/StorageModuleEsRegistration.java | 40 - .../storage/es/base/dao/BatchEsDAO.java | 64 -- .../collector/storage/es/base/dao/EsDAO.java | 77 -- .../define/ElasticSearchColumnDefine.java | 34 - .../base/define/ElasticSearchTableDefine.java | 37 - .../storage/es/dao/ApplicationEsCacheDAO.java | 75 -- .../es/dao/ApplicationEsRegisterDAO.java | 62 -- .../es/dao/CpuMetricEsPersistenceDAO.java | 76 -- .../storage/es/dao/CpuMetricEsUIDAO.java | 75 -- .../es/dao/GCMetricEsPersistenceDAO.java | 77 -- .../es/dao/GlobalTraceEsPersistenceDAO.java | 76 -- .../storage/es/dao/GlobalTraceEsUIDAO.java | 83 -- .../storage/es/dao/InstanceEsCacheDAO.java | 74 -- .../storage/es/dao/InstanceEsRegisterDAO.java | 82 -- .../InstanceHeartBeatEsPersistenceDAO.java | 73 -- .../es/dao/MemoryMetricEsPersistenceDAO.java | 79 -- .../storage/es/dao/MemoryMetricEsUIDAO.java | 89 -- .../dao/MemoryPoolMetricEsPersistenceDAO.java | 79 -- .../es/dao/MemoryPoolMetricEsUIDAO.java | 88 -- .../es/dao/SegmentCostEsPersistenceDAO.java | 81 -- .../es/dao/SegmentEsPersistenceDAO.java | 75 -- .../storage/es/dao/SegmentEsUIDAO.java | 59 -- .../es/dao/ServiceEntryEsPersistenceDAO.java | 80 -- .../storage/es/dao/ServiceNameEsCacheDAO.java | 74 -- .../es/dao/ServiceNameEsRegisterDAO.java | 63 -- .../es/define/AlertingListEsTableDefine.java | 47 - .../ApplicationComponentEsTableDefine.java | 43 - .../es/define/ApplicationEsTableDefine.java | 42 - .../ApplicationMappingEsTableDefine.java | 43 - .../es/define/CpuMetricEsTableDefine.java | 43 - .../es/define/GCMetricEsTableDefine.java | 45 - .../es/define/GlobalTraceEsTableDefine.java | 43 - .../es/define/InstanceEsTableDefine.java | 46 - .../define/InstanceMetricEsTableDefine.java | 59 -- .../es/define/MemoryMetricEsTableDefine.java | 47 - .../define/MemoryPoolMetricEsTableDefine.java | 47 - .../es/define/SegmentCostEsTableDefine.java | 48 - .../es/define/SegmentEsTableDefine.java | 42 - .../es/define/ServiceEntryEsTableDefine.java | 45 - .../es/define/ServiceMetricEsTableDefine.java | 58 -- .../es/define/ServiceNameEsTableDefine.java | 43 - .../resources/META-INF/defines/storage.define | 36 +- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../storage/h2/StorageModuleH2Provider.java | 235 +++++ .../storage/h2/base/dao/BatchH2DAO.java | 109 ++ .../collector/storage/h2/base/dao/H2DAO.java | 84 ++ .../h2/base/define/H2ColumnDefine.java | 53 + .../storage/h2/base/define/H2SqlEntity.java | 61 ++ .../h2/base/define/H2StorageInstaller.java | 128 +++ .../storage/h2/base/define/H2TableDefine.java | 49 + .../h2/dao/AlertingListH2PersistenceDAO.java | 36 +- .../ApplicationComponentH2PersistenceDAO.java | 118 +++ .../h2/dao/ApplicationComponentH2UIDAO.java | 91 ++ .../storage/h2/dao/ApplicationH2CacheDAO.java | 94 ++ .../h2/dao/ApplicationH2RegisterDAO.java | 88 ++ .../ApplicationMappingH2PersistenceDAO.java | 116 +++ .../h2/dao/ApplicationMappingH2UIDAO.java | 86 ++ .../ApplicationMetricH2PersistenceDAO.java | 36 +- ...cationReferenceMetricH2PersistenceDAO.java | 36 +- .../ApplicationReferenceMetricH2UIDAO.java | 26 +- .../h2/dao/CpuMetricH2PersistenceDAO.java | 87 ++ .../storage/h2/dao/CpuMetricH2UIDAO.java | 110 ++ .../h2/dao/GCMetricH2PersistenceDAO.java | 84 ++ .../storage/h2/dao/GCMetricH2UIDAO.java | 38 +- .../h2/dao/GlobalTraceH2PersistenceDAO.java | 88 ++ .../storage/h2/dao/GlobalTraceH2UIDAO.java | 101 ++ .../storage/h2/dao/InstanceH2CacheDAO.java | 94 ++ .../storage/h2/dao/InstanceH2RegisterDAO.java | 102 ++ .../storage/h2/dao/InstanceH2UIDAO.java | 36 +- .../InstanceHeartBeatH2PersistenceDAO.java | 105 ++ .../dao/InstanceMetricH2PersistenceDAO.java | 36 +- .../storage/h2/dao/InstanceMetricH2UIDAO.java | 36 +- .../h2/dao/MemoryMetricH2PersistenceDAO.java | 86 ++ .../storage/h2/dao/MemoryMetricH2UIDAO.java | 124 +++ .../dao/MemoryPoolMetricH2PersistenceDAO.java | 86 ++ .../h2/dao/MemoryPoolMetricH2UIDAO.java | 124 +++ .../h2/dao/SegmentCostH2PersistenceDAO.java | 93 ++ .../storage/h2/dao/SegmentCostH2UIDAO.java | 36 +- .../h2/dao/SegmentH2PersistenceDAO.java | 86 ++ .../storage/h2/dao/SegmentH2UIDAO.java | 82 ++ .../h2/dao/ServiceEntryH2PersistenceDAO.java | 36 +- .../storage/h2/dao/ServiceEntryH2UIDAO.java | 119 +++ .../h2/dao/ServiceMetricH2PersistenceDAO.java | 36 +- .../storage/h2/dao/ServiceNameH2CacheDAO.java | 96 ++ .../h2/dao/ServiceNameH2RegisterDAO.java | 90 ++ .../h2/dao/ServiceReferenceH2UIDAO.java | 36 +- ...erviceReferenceMetricH2PersistenceDAO.java | 36 +- .../h2/define/AlertingListH2TableDefine.java | 64 ++ .../ApplicationComponentH2TableDefine.java | 58 ++ .../h2/define/ApplicationH2TableDefine.java | 57 ++ .../ApplicationMappingH2TableDefine.java | 58 ++ ...plicationReferenceMetricH2TableDefine.java | 26 +- .../h2/define/CpuMetricH2TableDefine.java | 58 ++ .../h2/define/GCMetricH2TableDefine.java | 60 ++ .../h2/define/GlobalTraceH2TableDefine.java | 58 ++ .../h2/define/InstanceH2TableDefine.java | 61 ++ .../define/InstanceMetricH2TableDefine.java | 74 ++ .../h2/define/MemoryMetricH2TableDefine.java | 62 ++ .../define/MemoryPoolMetricH2TableDefine.java | 62 ++ .../h2/define/SegmentCostH2TableDefine.java | 63 ++ .../h2/define/SegmentH2TableDefine.java | 57 ++ .../h2/define/ServiceEntryH2TableDefine.java | 60 ++ .../h2/define/ServiceMetricH2TableDefine.java | 73 ++ .../h2/define/ServiceNameH2TableDefine.java | 58 ++ .../ServiceReferenceMetricH2TableDefine.java | 26 +- .../storage/h2/StorageModuleH2Provider.java | 217 ---- .../storage/h2/base/dao/BatchH2DAO.java | 91 -- .../collector/storage/h2/base/dao/H2DAO.java | 66 -- .../h2/base/define/H2ColumnDefine.java | 35 - .../storage/h2/base/define/H2SqlEntity.java | 43 - .../h2/base/define/H2StorageInstaller.java | 110 -- .../storage/h2/base/define/H2TableDefine.java | 31 - .../ApplicationComponentH2PersistenceDAO.java | 100 -- .../h2/dao/ApplicationComponentH2UIDAO.java | 73 -- .../storage/h2/dao/ApplicationH2CacheDAO.java | 76 -- .../h2/dao/ApplicationH2RegisterDAO.java | 70 -- .../ApplicationMappingH2PersistenceDAO.java | 98 -- .../h2/dao/ApplicationMappingH2UIDAO.java | 68 -- .../h2/dao/CpuMetricH2PersistenceDAO.java | 69 -- .../storage/h2/dao/CpuMetricH2UIDAO.java | 92 -- .../h2/dao/GCMetricH2PersistenceDAO.java | 66 -- .../h2/dao/GlobalTraceH2PersistenceDAO.java | 70 -- .../storage/h2/dao/GlobalTraceH2UIDAO.java | 83 -- .../storage/h2/dao/InstanceH2CacheDAO.java | 76 -- .../storage/h2/dao/InstanceH2RegisterDAO.java | 84 -- .../InstanceHeartBeatH2PersistenceDAO.java | 87 -- .../h2/dao/MemoryMetricH2PersistenceDAO.java | 68 -- .../storage/h2/dao/MemoryMetricH2UIDAO.java | 106 -- .../dao/MemoryPoolMetricH2PersistenceDAO.java | 68 -- .../h2/dao/MemoryPoolMetricH2UIDAO.java | 106 -- .../h2/dao/SegmentCostH2PersistenceDAO.java | 75 -- .../h2/dao/SegmentH2PersistenceDAO.java | 68 -- .../storage/h2/dao/SegmentH2UIDAO.java | 64 -- .../storage/h2/dao/ServiceEntryH2UIDAO.java | 101 -- .../storage/h2/dao/ServiceNameH2CacheDAO.java | 78 -- .../h2/dao/ServiceNameH2RegisterDAO.java | 72 -- .../h2/define/AlertingListH2TableDefine.java | 46 - .../ApplicationComponentH2TableDefine.java | 40 - .../h2/define/ApplicationH2TableDefine.java | 39 - .../ApplicationMappingH2TableDefine.java | 40 - .../h2/define/CpuMetricH2TableDefine.java | 40 - .../h2/define/GCMetricH2TableDefine.java | 42 - .../h2/define/GlobalTraceH2TableDefine.java | 40 - .../h2/define/InstanceH2TableDefine.java | 43 - .../define/InstanceMetricH2TableDefine.java | 56 - .../h2/define/MemoryMetricH2TableDefine.java | 44 - .../define/MemoryPoolMetricH2TableDefine.java | 44 - .../h2/define/SegmentCostH2TableDefine.java | 45 - .../h2/define/SegmentH2TableDefine.java | 39 - .../h2/define/ServiceEntryH2TableDefine.java | 42 - .../h2/define/ServiceMetricH2TableDefine.java | 55 - .../h2/define/ServiceNameH2TableDefine.java | 40 - .../resources/META-INF/defines/storage.define | 36 +- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../stream/timer/PersistenceTimer.java | 89 ++ .../worker/base/AbstractLocalAsyncWorker.java | 53 + .../AbstractLocalAsyncWorkerProvider.java | 68 ++ .../worker/base/AbstractRemoteWorker.java | 59 ++ .../base/AbstractRemoteWorkerProvider.java | 74 ++ .../stream/worker/base/AbstractWorker.java | 84 ++ .../worker/base/AbstractWorkerProvider.java | 57 ++ .../worker/base/LocalAsyncWorkerRef.java | 70 ++ .../stream/worker/base/Provider.java | 45 + .../base/ProviderNotFoundException.java | 43 + .../stream/worker/base/RemoteWorkerRef.java | 77 ++ .../worker/base/UsedRoleNameException.java | 43 + .../worker/base/WorkerCreateListener.java | 63 ++ .../stream/worker/base/WorkerException.java | 57 ++ .../worker/base/WorkerInvokeException.java | 54 + .../worker/base/WorkerNotFoundException.java | 43 + .../stream/worker/base/WorkerRef.java | 49 + .../stream/worker/impl/AggregationWorker.java | 106 ++ .../stream/worker/impl/FlushAndSwitch.java | 43 + .../stream/worker/impl/PersistenceWorker.java | 38 +- .../stream/worker/impl/data/DataCache.java | 77 ++ .../worker/impl/data/DataCollection.java | 105 ++ .../stream/timer/PersistenceTimer.java | 71 -- .../worker/base/AbstractLocalAsyncWorker.java | 35 - .../AbstractLocalAsyncWorkerProvider.java | 50 - .../worker/base/AbstractRemoteWorker.java | 41 - .../base/AbstractRemoteWorkerProvider.java | 56 - .../stream/worker/base/AbstractWorker.java | 66 -- .../worker/base/AbstractWorkerProvider.java | 39 - .../worker/base/LocalAsyncWorkerRef.java | 52 - .../stream/worker/base/Provider.java | 27 - .../base/ProviderNotFoundException.java | 25 - .../stream/worker/base/RemoteWorkerRef.java | 59 -- .../worker/base/UsedRoleNameException.java | 25 - .../worker/base/WorkerCreateListener.java | 45 - .../stream/worker/base/WorkerException.java | 39 - .../worker/base/WorkerInvokeException.java | 36 - .../worker/base/WorkerNotFoundException.java | 25 - .../stream/worker/base/WorkerRef.java | 31 - .../stream/worker/impl/AggregationWorker.java | 88 -- .../stream/worker/impl/FlushAndSwitch.java | 25 - .../stream/worker/impl/data/DataCache.java | 59 -- .../worker/impl/data/DataCollection.java | 87 -- .../skywalking/apm/collector/ui/UIModule.java | 55 + .../skywalking/apm/collector/ui/UIModule.java | 37 - ...kywalking.apm.collector.core.module.Module | 20 + ...kywalking.apm.collector.core.module.Module | 37 - .../ui/jetty/UIModuleJettyProvider.java | 134 +++ .../ui/jetty/UIModuleJettyRegistration.java | 59 ++ .../jetty/handler/SegmentTopGetHandler.java | 32 +- .../ui/jetty/handler/SpanGetHandler.java | 83 ++ .../ui/jetty/handler/TraceDagGetHandler.java | 94 ++ .../jetty/handler/TraceStackGetHandler.java | 75 ++ .../application/ApplicationsGetHandler.java | 94 ++ .../InstanceHealthGetHandler.java | 102 ++ ...InstanceMetricGetOneTimeBucketHandler.java | 103 ++ ...stanceMetricGetRangeTimeBucketHandler.java | 111 ++ .../InstanceOsInfoGetHandler.java | 82 ++ .../handler/naming/UIJettyNamingHandler.java | 71 ++ .../handler/naming/UIJettyNamingListener.java | 61 ++ .../servicetree/EntryServiceGetHandler.java | 28 +- .../ServiceTreeGetByIdHandler.java | 102 ++ .../time/AllInstanceLastTimeGetHandler.java | 88 ++ .../time/OneInstanceLastTimeGetHandler.java | 87 ++ .../ui/service/ApplicationService.java | 71 ++ .../ui/service/InstanceHealthService.java | 38 +- .../ui/service/InstanceJVMService.java | 44 +- .../ui/service/SegmentTopService.java | 92 ++ .../ui/service/ServiceTreeService.java | 44 +- .../apm/collector/ui/service/SpanService.java | 46 +- .../ui/service/TimeSynchronousService.java | 65 ++ .../ui/service/TraceDagDataBuilder.java | 38 +- .../collector/ui/service/TraceDagService.java | 81 ++ .../ui/service/TraceStackService.java | 46 +- .../ui/jetty/UIModuleJettyProvider.java | 116 --- .../ui/jetty/UIModuleJettyRegistration.java | 41 - .../ui/jetty/handler/SpanGetHandler.java | 65 -- .../ui/jetty/handler/TraceDagGetHandler.java | 76 -- .../jetty/handler/TraceStackGetHandler.java | 57 -- .../application/ApplicationsGetHandler.java | 76 -- .../InstanceHealthGetHandler.java | 84 -- ...InstanceMetricGetOneTimeBucketHandler.java | 85 -- ...stanceMetricGetRangeTimeBucketHandler.java | 93 -- .../InstanceOsInfoGetHandler.java | 64 -- .../handler/naming/UIJettyNamingHandler.java | 53 - .../handler/naming/UIJettyNamingListener.java | 43 - .../ServiceTreeGetByIdHandler.java | 84 -- .../time/AllInstanceLastTimeGetHandler.java | 70 -- .../time/OneInstanceLastTimeGetHandler.java | 69 -- .../ui/service/ApplicationService.java | 53 - .../ui/service/SegmentTopService.java | 74 -- .../ui/service/TimeSynchronousService.java | 47 - .../collector/ui/service/TraceDagService.java | 63 -- ...g.apm.collector.core.module.ModuleProvider | 20 + ...g.apm.collector.core.module.ModuleProvider | 37 - .../apm/commons/datacarrier/DataCarrier.java | 32 +- .../commons/datacarrier/buffer/Buffer.java | 97 ++ .../datacarrier/buffer/BufferStrategy.java | 46 + .../commons/datacarrier/buffer/Channels.java | 22 +- .../common/AtomicRangeInteger.java | 88 ++ .../ConsumerCannotBeCreatedException.java | 46 + .../datacarrier/consumer/ConsumerPool.java | 24 +- .../datacarrier/consumer/ConsumerThread.java | 22 +- .../datacarrier/consumer/IConsumer.java | 52 + .../partition/IDataPartitioner.java | 53 + .../partition/ProducerThreadPartitioner.java | 63 ++ .../partition/SimpleRollingPartitioner.java | 57 ++ .../commons/datacarrier/buffer/Buffer.java | 79 -- .../datacarrier/buffer/BufferStrategy.java | 28 - .../common/AtomicRangeInteger.java | 70 -- .../ConsumerCannotBeCreatedException.java | 28 - .../datacarrier/consumer/IConsumer.java | 34 - .../partition/IDataPartitioner.java | 35 - .../partition/ProducerThreadPartitioner.java | 45 - .../partition/SimpleRollingPartitioner.java | 39 - .../commons/datacarrier/DataCarrierTest.java | 32 +- .../apm/commons/datacarrier/SampleData.java | 64 ++ .../common/AtomicRangeIntegerTest.java | 59 ++ .../consumer/ConsumerPoolTest.java | 77 ++ .../datacarrier/consumer/ConsumerTest.java | 24 +- .../datacarrier/consumer/SampleConsumer.java | 70 ++ .../ProducerThreadPartitionerTest.java | 55 + .../SimpleRollingPartitionerTest.java | 54 + .../apm/commons/datacarrier/SampleData.java | 46 - .../common/AtomicRangeIntegerTest.java | 41 - .../consumer/ConsumerPoolTest.java | 59 -- .../datacarrier/consumer/SampleConsumer.java | 52 - .../ProducerThreadPartitionerTest.java | 37 - .../SimpleRollingPartitionerTest.java | 36 - .../apm/util/ConfigInitializer.java | 20 +- .../skywalking/apm/util/MachineInfo.java | 20 +- .../skywalking/apm/util/StringUtil.java | 74 ++ .../org/skywalking/apm/util/StringUtil.java | 56 - .../apm/util/ConfigInitializerTest.java | 20 +- .../skywalking/apm/util/StringUtilTest.java | 60 ++ .../skywalking/apm/util/StringUtilTest.java | 42 - .../network/trace/component/Component.java | 51 + .../trace/component/ComponentsDefine.java | 24 +- .../trace/component/OfficialComponent.java | 60 ++ .../network/trace/component/Component.java | 33 - .../trace/component/OfficialComponent.java | 42 - .../proto/ApplicationRegisterService.proto | 4 +- .../src/main/proto/DiscoveryService.proto | 2 +- apm-network/src/main/proto/Downstream.proto | 2 +- .../src/main/proto/JVMMetricsService.proto | 2 +- .../src/main/proto/KeyWithIntegerValue.proto | 2 +- .../src/main/proto/KeyWithStringValue.proto | 2 +- .../src/main/proto/TraceSegmentService.proto | 2 +- .../network/trace/proto/GRPCNoServerTest.java | 85 ++ .../network/trace/proto/GRPCNoServerTest.java | 67 -- apm-sniffer/apm-agent-core/pom.xml | 8 +- .../boot/AgentPackageNotFoundException.java | 46 + .../apm/agent/core/boot/AgentPackagePath.java | 98 ++ .../apm/agent/core/boot/BootService.java | 54 + .../core/boot/DefaultNamedThreadFactory.java | 57 ++ .../apm/agent/core/boot/ServiceManager.java | 24 +- .../apm/agent/core/conf/Config.java | 26 +- .../core/conf/ConfigNotFoundException.java | 50 + .../apm/agent/core/conf/Constants.java | 43 + .../core/conf/RemoteDownstreamConfig.java | 62 ++ .../core/conf/SnifferConfigInitializer.java | 32 +- .../core/context/AbstractTracerContext.java | 28 +- .../apm/agent/core/context/CarrierItem.java | 87 ++ .../agent/core/context/CarrierItemHead.java | 46 + .../agent/core/context/ContextCarrier.java | 32 +- .../agent/core/context/ContextManager.java | 44 +- .../agent/core/context/ContextSnapshot.java | 28 +- .../context/IgnoreTracerContextListener.java | 44 + .../core/context/IgnoredTracerContext.java | 24 +- .../apm/agent/core/context/Injectable.java | 52 + .../agent/core/context/SW3CarrierItem.java | 55 + .../core/context/TraceContextCarrierItem.java | 48 + .../agent/core/context/TracingContext.java | 52 +- .../core/context/TracingContextListener.java | 43 + .../core/context/ids/DistributedTraceId.java | 101 ++ .../core/context/ids/DistributedTraceIds.java | 65 ++ .../core/context/ids/GlobalIdGenerator.java | 24 +- .../apm/agent/core/context/ids/ID.java | 22 +- .../context/ids/NewDistributedTraceId.java | 48 + .../core/context/ids/PropagatedTraceId.java | 48 + .../agent/core/context/tag/AbstractTag.java | 59 ++ .../apm/agent/core/context/tag/StringTag.java | 56 + .../apm/agent/core/context/tag/Tags.java | 82 ++ .../core/context/trace/AbstractSpan.java | 130 +++ .../context/trace/AbstractTracingSpan.java | 32 +- .../agent/core/context/trace/EntrySpan.java | 26 +- .../agent/core/context/trace/ExitSpan.java | 26 +- .../agent/core/context/trace/LocalSpan.java | 73 ++ .../core/context/trace/LogDataEntity.java | 90 ++ .../core/context/trace/NoopExitSpan.java | 66 ++ .../agent/core/context/trace/NoopSpan.java | 119 +++ .../agent/core/context/trace/SpanLayer.java | 73 ++ .../context/trace/StackBasedTracingSpan.java | 87 ++ .../core/context/trace/TraceSegment.java | 215 ++++ .../core/context/trace/TraceSegmentRef.java | 36 +- .../core/context/trace/WithPeerInfo.java | 46 + .../agent/core/context/util/KeyValuePair.java | 71 ++ .../context/util/ThrowableTransformer.java | 92 ++ .../dictionary/ApplicationDictionary.java | 85 ++ .../core/dictionary/DictionaryManager.java | 56 + .../agent/core/dictionary/DictionaryUtil.java | 50 + .../apm/agent/core/dictionary/Found.java | 46 + .../apm/agent/core/dictionary/NotFound.java | 46 + .../dictionary/OperationNameDictionary.java | 32 +- .../agent/core/dictionary/PossibleFound.java | 88 ++ .../apm/agent/core/jvm/JVMService.java | 165 +++ .../agent/core/jvm/cpu/CPUMetricAccessor.java | 68 ++ .../apm/agent/core/jvm/cpu/CPUProvider.java | 67 ++ .../core/jvm/cpu/NoSupportedCPUAccessor.java | 51 + .../agent/core/jvm/cpu/SunCpuAccessor.java | 58 ++ .../apm/agent/core/jvm/gc/CMSGCModule.java | 57 ++ .../apm/agent/core/jvm/gc/G1GCModule.java | 57 ++ .../agent/core/jvm/gc/GCMetricAccessor.java | 47 + .../apm/agent/core/jvm/gc/GCModule.java | 83 ++ .../apm/agent/core/jvm/gc/GCProvider.java | 91 ++ .../agent/core/jvm/gc/ParallelGCModule.java | 58 ++ .../apm/agent/core/jvm/gc/SerialGCModule.java | 57 ++ .../apm/agent/core/jvm/gc/UnknowGC.java | 55 + .../agent/core/jvm/memory/MemoryProvider.java | 81 ++ .../jvm/memorypool/CMSCollectorModule.java | 73 ++ .../jvm/memorypool/G1CollectorModule.java | 73 ++ .../memorypool/MemoryPoolMetricAccessor.java | 47 + .../core/jvm/memorypool/MemoryPoolModule.java | 24 +- .../jvm/memorypool/MemoryPoolProvider.java | 90 ++ .../memorypool/ParallelCollectorModule.java | 74 ++ .../jvm/memorypool/SerialCollectorModule.java | 73 ++ .../jvm/memorypool/UnknownMemoryPool.java | 59 ++ .../apm/agent/core/logging/api/ILog.java | 70 ++ .../agent/core/logging/api/LogManager.java | 62 ++ .../agent/core/logging/api/LogResolver.java | 50 + .../agent/core/logging/api/NoopLogger.java | 109 ++ .../core/logging/core/EasyLogResolver.java | 50 + .../agent/core/logging/core/EasyLogger.java | 28 +- .../agent/core/logging/core/FileWriter.java | 24 +- .../apm/agent/core/logging/core/IWriter.java | 41 + .../apm/agent/core/logging/core/LogLevel.java | 44 + .../core/logging/core/LogMessageHolder.java | 55 + .../core/logging/core/SystemOutWriter.java | 55 + .../core/logging/core/WriterFactory.java | 59 ++ .../skywalking/apm/agent/core/os/OSUtil.java | 22 +- .../apm/agent/core/os/ProcessorUtil.java | 48 + .../AbstractClassEnhancePluginDefine.java | 30 +- .../apm/agent/core/plugin/EnhanceContext.java | 72 ++ .../agent/core/plugin/PluginBootstrap.java | 102 ++ .../apm/agent/core/plugin/PluginCfg.java | 81 ++ .../apm/agent/core/plugin/PluginDefine.java | 78 ++ .../agent/core/plugin/PluginException.java | 49 + .../apm/agent/core/plugin/PluginFinder.java | 28 +- .../core/plugin/PluginResourcesResolver.java | 97 ++ .../agent/core/plugin/WitnessClassFinder.java | 78 ++ .../plugin/bytebuddy/AbstractJunction.java | 54 + .../bytebuddy/ArgumentTypeNameMatch.java | 20 +- .../IllegalPluginDefineException.java | 46 + .../ConstructorInterceptPoint.java | 64 ++ .../plugin/interceptor/EnhanceException.java | 51 + .../InstanceMethodsInterceptPoint.java | 65 ++ .../interceptor/InterceptorException.java | 49 + .../StaticMethodsInterceptPoint.java | 65 ++ .../enhance/ClassEnhancePluginDefine.java | 40 +- ...assInstanceMethodsEnhancePluginDefine.java | 59 ++ ...ClassStaticMethodsEnhancePluginDefine.java | 68 ++ .../interceptor/enhance/ConstructorInter.java | 92 ++ .../interceptor/enhance/EnhancedInstance.java | 46 + .../interceptor/enhance/InstMethodsInter.java | 28 +- .../InstMethodsInterWithOverrideArgs.java | 28 +- .../InstanceConstructorInterceptor.java | 51 + .../InstanceMethodsAroundInterceptor.java | 78 ++ .../enhance/MethodInterceptResult.java | 77 ++ .../interceptor/enhance/OverrideCallable.java | 44 + .../StaticMethodsAroundInterceptor.java | 74 ++ .../enhance/StaticMethodsInter.java | 26 +- .../StaticMethodsInterWithOverrideArgs.java | 26 +- .../core/plugin/loader/AgentClassLoader.java | 30 +- .../loader/InterceptorInstanceLoader.java | 26 +- .../plugin/match/ClassAnnotationMatch.java | 20 +- .../agent/core/plugin/match/ClassMatch.java | 43 + .../core/plugin/match/HierarchyMatch.java | 20 +- .../core/plugin/match/IndirectMatch.java | 51 + .../plugin/match/MethodAnnotationMatch.java | 20 +- .../agent/core/plugin/match/NameMatch.java | 58 ++ .../remote/AppAndServiceRegisterClient.java | 187 ++++ .../remote/CollectorDiscoveryService.java | 75 ++ .../remote/DiscoveryRestServiceClient.java | 30 +- .../core/remote/GRPCChannelListener.java | 44 + .../agent/core/remote/GRPCChannelManager.java | 32 +- .../agent/core/remote/GRPCChannelStatus.java | 45 + .../core/remote/GRPCStreamServiceStatus.java | 84 ++ .../core/remote/RESTResponseStatusError.java | 49 + .../remote/TraceSegmentServiceClient.java | 194 ++++ .../agent/core/sampling/SamplingService.java | 32 +- .../boot/AgentPackageNotFoundException.java | 28 - .../apm/agent/core/boot/AgentPackagePath.java | 80 -- .../apm/agent/core/boot/BootService.java | 36 - .../core/boot/DefaultNamedThreadFactory.java | 39 - .../core/conf/ConfigNotFoundException.java | 32 - .../apm/agent/core/conf/Constants.java | 25 - .../core/conf/RemoteDownstreamConfig.java | 44 - .../apm/agent/core/context/CarrierItem.java | 69 -- .../agent/core/context/CarrierItemHead.java | 28 - .../context/IgnoreTracerContextListener.java | 26 - .../apm/agent/core/context/Injectable.java | 34 - .../agent/core/context/SW3CarrierItem.java | 37 - .../core/context/TraceContextCarrierItem.java | 30 - .../core/context/TracingContextListener.java | 25 - .../core/context/ids/DistributedTraceId.java | 83 -- .../core/context/ids/DistributedTraceIds.java | 47 - .../context/ids/NewDistributedTraceId.java | 30 - .../core/context/ids/PropagatedTraceId.java | 30 - .../agent/core/context/ids/base64/Base64.java | 965 ------------------ .../core/context/ids/base64/Objects.java | 170 --- .../context/ids/base64/StandardCharsets.java | 63 -- .../agent/core/context/tag/AbstractTag.java | 41 - .../apm/agent/core/context/tag/StringTag.java | 38 - .../apm/agent/core/context/tag/Tags.java | 64 -- .../core/context/trace/AbstractSpan.java | 111 -- .../agent/core/context/trace/LocalSpan.java | 55 - .../core/context/trace/LogDataEntity.java | 72 -- .../core/context/trace/NoopExitSpan.java | 48 - .../agent/core/context/trace/NoopSpan.java | 101 -- .../agent/core/context/trace/SpanLayer.java | 55 - .../context/trace/StackBasedTracingSpan.java | 69 -- .../core/context/trace/TraceSegment.java | 197 ---- .../core/context/trace/WithPeerInfo.java | 28 - .../agent/core/context/util/KeyValuePair.java | 53 - .../context/util/ThrowableTransformer.java | 74 -- .../dictionary/ApplicationDictionary.java | 67 -- .../core/dictionary/DictionaryManager.java | 38 - .../agent/core/dictionary/DictionaryUtil.java | 32 - .../apm/agent/core/dictionary/Found.java | 28 - .../apm/agent/core/dictionary/NotFound.java | 28 - .../agent/core/dictionary/PossibleFound.java | 70 -- .../apm/agent/core/jvm/JVMService.java | 149 --- .../agent/core/jvm/cpu/CPUMetricAccessor.java | 50 - .../apm/agent/core/jvm/cpu/CPUProvider.java | 49 - .../core/jvm/cpu/NoSupportedCPUAccessor.java | 33 - .../agent/core/jvm/cpu/SunCpuAccessor.java | 40 - .../apm/agent/core/jvm/gc/CMSGCModule.java | 39 - .../apm/agent/core/jvm/gc/G1GCModule.java | 39 - .../agent/core/jvm/gc/GCMetricAccessor.java | 29 - .../apm/agent/core/jvm/gc/GCModule.java | 65 -- .../apm/agent/core/jvm/gc/GCProvider.java | 73 -- .../agent/core/jvm/gc/ParallelGCModule.java | 40 - .../apm/agent/core/jvm/gc/SerialGCModule.java | 39 - .../apm/agent/core/jvm/gc/UnknowGC.java | 37 - .../agent/core/jvm/memory/MemoryProvider.java | 63 -- .../jvm/memorypool/CMSCollectorModule.java | 55 - .../jvm/memorypool/G1CollectorModule.java | 55 - .../memorypool/MemoryPoolMetricAccessor.java | 29 - .../jvm/memorypool/MemoryPoolProvider.java | 72 -- .../memorypool/ParallelCollectorModule.java | 56 - .../jvm/memorypool/SerialCollectorModule.java | 55 - .../jvm/memorypool/UnknownMemoryPool.java | 41 - .../apm/agent/core/logging/api/ILog.java | 52 - .../agent/core/logging/api/LogManager.java | 44 - .../agent/core/logging/api/LogResolver.java | 32 - .../agent/core/logging/api/NoopLogger.java | 91 -- .../core/logging/core/EasyLogResolver.java | 32 - .../apm/agent/core/logging/core/IWriter.java | 23 - .../apm/agent/core/logging/core/LogLevel.java | 26 - .../core/logging/core/LogMessageHolder.java | 37 - .../core/logging/core/SystemOutWriter.java | 37 - .../core/logging/core/WriterFactory.java | 41 - .../apm/agent/core/os/ProcessorUtil.java | 30 - .../apm/agent/core/plugin/EnhanceContext.java | 52 - .../agent/core/plugin/PluginBootstrap.java | 84 -- .../apm/agent/core/plugin/PluginCfg.java | 63 -- .../apm/agent/core/plugin/PluginDefine.java | 60 -- .../agent/core/plugin/PluginException.java | 31 - .../core/plugin/PluginResourcesResolver.java | 79 -- .../agent/core/plugin/WitnessClassFinder.java | 60 -- .../plugin/bytebuddy/AbstractJunction.java | 36 - .../IllegalPluginDefineException.java | 28 - .../ConstructorInterceptPoint.java | 46 - .../plugin/interceptor/EnhanceException.java | 33 - .../InstanceMethodsInterceptPoint.java | 47 - .../interceptor/InterceptorException.java | 31 - .../StaticMethodsInterceptPoint.java | 47 - ...assInstanceMethodsEnhancePluginDefine.java | 41 - ...ClassStaticMethodsEnhancePluginDefine.java | 50 - .../interceptor/enhance/ConstructorInter.java | 74 -- .../interceptor/enhance/EnhancedInstance.java | 28 - .../InstanceConstructorInterceptor.java | 33 - .../InstanceMethodsAroundInterceptor.java | 60 -- .../enhance/MethodInterceptResult.java | 59 -- .../interceptor/enhance/OverrideCallable.java | 26 - .../StaticMethodsAroundInterceptor.java | 56 - .../agent/core/plugin/match/ClassMatch.java | 25 - .../core/plugin/match/IndirectMatch.java | 33 - .../agent/core/plugin/match/NameMatch.java | 40 - .../remote/AppAndServiceRegisterClient.java | 171 ---- .../remote/CollectorDiscoveryService.java | 57 -- .../core/remote/GRPCChannelListener.java | 26 - .../agent/core/remote/GRPCChannelStatus.java | 27 - .../core/remote/GRPCStreamServiceStatus.java | 66 -- .../core/remote/RESTResponseStatusError.java | 31 - .../remote/TraceSegmentServiceClient.java | 176 ---- ...skywalking.apm.agent.core.boot.BootService | 78 ++ ...skywalking.apm.agent.core.boot.BootService | 95 -- .../boot/DefaultNamedThreadFactoryTest.java | 60 ++ .../agent/core/boot/ServiceManagerTest.java | 144 +++ .../conf/SnifferConfigInitializerTest.java | 64 ++ .../core/context/ContextManagerTest.java | 77 +- .../context/IgnoredTracerContextTest.java | 127 +++ .../util/AbstractTracingSpanHelper.java | 62 ++ .../agent/core/context/util/FieldGetter.java | 55 + .../core/context/util/SegmentHelper.java | 53 + .../agent/core/context/util/SpanHelper.java | 62 ++ .../context/util/TraceSegmentRefHelper.java | 50 + .../logging/core/EasyLogResolverTest.java | 50 + .../core/logging/core/EasyLoggerTest.java | 24 +- .../core/logging/core/FileWriterTest.java | 89 ++ .../logging/core/SystemOutWriterTest.java | 74 ++ .../DiscoveryRestServiceClientTest.java | 31 +- .../core/remote/GRPCChannelManagerTest.java | 24 +- .../remote/TraceSegmentServiceClientTest.java | 176 ++++ .../core/test/tools/AgentServiceRule.java | 64 ++ .../agent/core/test/tools/SegmentStorage.java | 68 ++ .../core/test/tools/SegmentStoragePoint.java | 47 + .../core/test/tools/TracingSegmentRunner.java | 109 ++ .../boot/DefaultNamedThreadFactoryTest.java | 42 - .../agent/core/boot/ServiceManagerTest.java | 126 --- .../conf/SnifferConfigInitializerTest.java | 46 - .../context/IgnoredTracerContextTest.java | 109 -- .../util/AbstractTracingSpanHelper.java | 44 - .../agent/core/context/util/FieldGetter.java | 37 - .../core/context/util/SegmentHelper.java | 35 - .../agent/core/context/util/SpanHelper.java | 44 - .../context/util/TraceSegmentRefHelper.java | 32 - .../logging/core/EasyLogResolverTest.java | 32 - .../core/logging/core/FileWriterTest.java | 71 -- .../logging/core/SystemOutWriterTest.java | 56 - .../remote/TraceSegmentServiceClientTest.java | 158 --- .../core/test/tools/AgentServiceRule.java | 46 - .../agent/core/test/tools/SegmentStorage.java | 50 - .../core/test/tools/SegmentStoragePoint.java | 29 - .../core/test/tools/TracingSegmentRunner.java | 91 -- .../src/test/resources/skywalking-plugin.def | 2 +- apm-sniffer/apm-agent/pom.xml | 10 +- .../apm/agent/InstrumentDebuggingClass.java | 89 ++ .../skywalking/apm/agent/SkyWalkingAgent.java | 38 +- .../apm/agent/InstrumentDebuggingClass.java | 71 -- .../plugin/dubbo/DubboInstrumentation.java | 91 ++ .../apm/plugin/dubbo/DubboInterceptor.java | 44 +- .../plugin/dubbo/DubboInstrumentation.java | 73 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../plugin/dubbo/DubboInterceptorTest.java | 62 +- .../plugin/esjob/JobExecutorInterceptor.java | 83 ++ .../define/JobExecutorInstrumentation.java | 86 ++ .../plugin/esjob/JobExecutorInterceptor.java | 65 -- .../define/JobExecutorInstrumentation.java | 68 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../esjob/JobExecutorInterceptorTest.java | 34 +- .../http/v9/DefaultHttpClientInterceptor.java | 146 +++ .../DefaultHttpClientInstrumentation.java | 95 ++ .../http/v9/DefaultHttpClientInterceptor.java | 128 --- .../DefaultHttpClientInstrumentation.java | 77 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../v9/DefaultHttpClientInterceptorTest.java | 48 +- .../v1/ClientCallIConstructorInterceptor.java | 58 ++ .../grpc/v1/ClientCallOnNextInterceptor.java | 78 ++ .../grpc/v1/ClientCallStartInterceptor.java | 81 ++ .../grpc/v1/ClientCallsMethodInterceptor.java | 79 ++ .../grpc/v1/ManagedChannelInterceptor.java | 69 ++ .../grpc/v1/ServerCallHandlerInterceptor.java | 76 ++ .../v1/ServerCallOnCancelInterceptor.java | 74 ++ .../grpc/v1/ServerCallOnCloseInterceptor.java | 75 ++ .../v1/ServerCallOnMessageInterceptor.java | 79 ++ .../grpc/v1/ServerCallOnReadyInterceptor.java | 103 ++ .../v1/StreamClientOnCloseInterceptor.java | 94 ++ .../v1/StreamClientOnReadyInterceptor.java | 79 ++ ...yStreamToFutureConstructorInterceptor.java | 52 + .../v1/define/ClientCallInstrumentation.java | 98 ++ .../v1/define/ClientCallsInstrumentation.java | 76 ++ .../apm/plugin/grpc/v1/define/Constants.java | 54 + .../define/ManagedChannelInstrumentation.java | 85 ++ ...ObserverToCallListenerInstrumentation.java | 118 +++ ...amingServerCallHandlerInstrumentation.java | 86 ++ ...mingServerCallListenerInstrumentation.java | 134 +++ ...naryClientCallListenerInstrumentation.java | 80 ++ ...UnaryServerCallHandlerInstrumentation.java | 85 ++ ...naryServerCallListenerInstrumentation.java | 119 +++ .../plugin/grpc/v1/vo/GRPCDynamicFields.java | 106 ++ .../plugin/grpc/v1/vo/ServiceDescriptor.java | 76 ++ .../v1/ClientCallIConstructorInterceptor.java | 40 - .../grpc/v1/ClientCallOnNextInterceptor.java | 61 -- .../grpc/v1/ClientCallStartInterceptor.java | 63 -- .../grpc/v1/ClientCallsMethodInterceptor.java | 61 -- .../grpc/v1/ManagedChannelInterceptor.java | 51 - .../grpc/v1/ServerCallHandlerInterceptor.java | 57 -- .../v1/ServerCallOnCancelInterceptor.java | 57 -- .../grpc/v1/ServerCallOnCloseInterceptor.java | 57 -- .../v1/ServerCallOnMessageInterceptor.java | 61 -- .../grpc/v1/ServerCallOnReadyInterceptor.java | 85 -- .../v1/StreamClientOnCloseInterceptor.java | 78 -- .../v1/StreamClientOnReadyInterceptor.java | 62 -- ...yStreamToFutureConstructorInterceptor.java | 34 - .../v1/define/ClientCallInstrumentation.java | 80 -- .../v1/define/ClientCallsInstrumentation.java | 58 -- .../apm/plugin/grpc/v1/define/Constants.java | 36 - .../define/ManagedChannelInstrumentation.java | 67 -- ...ObserverToCallListenerInstrumentation.java | 100 -- ...amingServerCallHandlerInstrumentation.java | 68 -- ...mingServerCallListenerInstrumentation.java | 116 --- ...naryClientCallListenerInstrumentation.java | 62 -- ...UnaryServerCallHandlerInstrumentation.java | 67 -- ...naryServerCallListenerInstrumentation.java | 101 -- .../plugin/grpc/v1/vo/GRPCDynamicFields.java | 88 -- .../plugin/grpc/v1/vo/ServiceDescriptor.java | 58 -- .../src/main/resources/skywalking-plugin.def | 18 +- ...ClientCallIConstructorInterceptorTest.java | 82 ++ .../v1/ClientCallOnNextInterceptorTest.java | 102 ++ .../v1/ClientCallsMethodInterceptorTest.java | 139 +++ .../v1/ServerCallHandlerInterceptorTest.java | 89 ++ .../ServerCallOnMessageInterceptorTest.java | 103 ++ .../v1/ServerCallOnReadyInterceptorTest.java | 42 +- ...ClientCallIConstructorInterceptorTest.java | 64 -- .../v1/ClientCallOnNextInterceptorTest.java | 84 -- .../v1/ClientCallsMethodInterceptorTest.java | 121 --- .../v1/ServerCallHandlerInterceptorTest.java | 71 -- .../ServerCallOnMessageInterceptorTest.java | 85 -- ...dbcXAConnectionConstructorInterceptor.java | 55 + ...dJdbcConnectionConstructorInterceptor.java | 54 + .../AbstractConnectionInstrumentation.java | 148 +++ .../jdbc/h2/define/DriverInstrumentation.java | 56 + .../define/JdbcConnectionInstrumentation.java | 54 + .../JdbcXAConnectionInstrumentation.java | 74 ++ .../PooledJdbcConnectionInstrumentation.java | 75 ++ ...dbcXAConnectionConstructorInterceptor.java | 36 - ...dJdbcConnectionConstructorInterceptor.java | 35 - .../AbstractConnectionInstrumentation.java | 140 --- .../jdbc/h2/define/DriverInstrumentation.java | 38 - .../define/JdbcConnectionInstrumentation.java | 36 - .../JdbcXAConnectionInstrumentation.java | 56 - .../PooledJdbcConnectionInstrumentation.java | 57 -- .../src/main/resources/skywalking-plugin.def | 8 +- .../v4/HttpClientExecuteInterceptor.java | 112 ++ .../AbstractHttpClientInstrumentation.java | 92 ++ ...DefaultRequestDirectorInstrumentation.java | 85 ++ .../v4/define/HttpClientInstrumentation.java | 61 ++ .../InternalHttpClientInstrumentation.java | 84 ++ .../MinimalHttpClientInstrumentation.java | 87 ++ .../v4/HttpClientExecuteInterceptor.java | 94 -- .../AbstractHttpClientInstrumentation.java | 74 -- ...DefaultRequestDirectorInstrumentation.java | 67 -- .../v4/define/HttpClientInstrumentation.java | 43 - .../InternalHttpClientInstrumentation.java | 66 -- .../MinimalHttpClientInstrumentation.java | 69 -- .../src/main/resources/skywalking-plugin.def | 8 +- .../v4/HttpClientExecuteInterceptorTest.java | 44 +- .../ConnectionServiceMethodInterceptor.java | 86 ++ .../plugin/jdbc/JDBCDriverInterceptor.java | 72 ++ .../jdbc/JDBCPrepareCallInterceptor.java | 74 ++ .../jdbc/JDBCPrepareStatementInterceptor.java | 74 ++ .../plugin/jdbc/JDBCStatementInterceptor.java | 73 ++ .../parser/AbstractURLParser.java | 90 ++ .../parser/ConnectionURLParser.java | 48 + .../connectionurl/parser/H2URLParser.java | 24 +- .../connectionurl/parser/MysqlURLParser.java | 24 +- .../connectionurl/parser/OracleURLParser.java | 26 +- .../parser/PostgreSQLURLParser.java | 24 +- .../connectionurl/parser/URLLocation.java | 55 + .../jdbc/connectionurl/parser/URLParser.java | 67 ++ .../define/AbstractDriverInstrumentation.java | 82 ++ .../apm/plugin/jdbc/define/Constants.java | 62 ++ .../jdbc/define/StatementEnhanceInfos.java | 69 ++ .../jdbc/trace/CallableStatementTracing.java | 78 ++ .../apm/plugin/jdbc/trace/ConnectionInfo.java | 94 ++ .../jdbc/trace/PreparedStatementTracing.java | 79 ++ .../jdbc/trace/SWCallableStatement.java | 20 +- .../jdbc/trace/SWPreparedStatement.java | 20 +- .../apm/plugin/jdbc/trace/SWStatement.java | 20 +- .../plugin/jdbc/trace/StatementTracing.java | 77 ++ .../ConnectionServiceMethodInterceptor.java | 68 -- .../plugin/jdbc/JDBCDriverInterceptor.java | 54 - .../jdbc/JDBCPrepareCallInterceptor.java | 56 - .../jdbc/JDBCPrepareStatementInterceptor.java | 56 - .../plugin/jdbc/JDBCStatementInterceptor.java | 55 - .../parser/AbstractURLParser.java | 72 -- .../parser/ConnectionURLParser.java | 30 - .../connectionurl/parser/URLLocation.java | 37 - .../jdbc/connectionurl/parser/URLParser.java | 49 - .../define/AbstractDriverInstrumentation.java | 64 -- .../apm/plugin/jdbc/define/Constants.java | 44 - .../jdbc/define/StatementEnhanceInfos.java | 51 - .../jdbc/trace/CallableStatementTracing.java | 60 -- .../apm/plugin/jdbc/trace/ConnectionInfo.java | 76 -- .../jdbc/trace/PreparedStatementTracing.java | 61 -- .../plugin/jdbc/trace/StatementTracing.java | 59 -- .../plugin/jdbc/AbstractStatementTest.java | 79 ++ .../apm/plugin/jdbc/ConnectionTracing.java | 73 ++ .../plugin/jdbc/SWCallableStatementTest.java | 38 +- .../apm/plugin/jdbc/SWConnection.java | 30 +- .../apm/plugin/jdbc/SWConnectionTest.java | 36 +- .../apm/plugin/jdbc/SWStatementTest.java | 36 +- .../plugin/jdbc/SwPreparedStatementTest.java | 38 +- .../connectionurl/parser/URLParserTest.java | 22 +- .../plugin/jdbc/AbstractStatementTest.java | 61 -- .../apm/plugin/jdbc/ConnectionTracing.java | 55 - ...structorWithHostAndPortArgInterceptor.java | 50 + ...ctorWithListHostAndPortArgInterceptor.java | 56 + ...onstructorWithShardInfoArgInterceptor.java | 52 + ...isConstructorWithStringArgInterceptor.java | 54 + ...JedisConstructorWithUriArgInterceptor.java | 50 + .../jedis/v2/JedisMethodInterceptor.java | 76 ++ .../apm/plugin/jedis/v2/RedisMethodMatch.java | 20 +- .../define/JedisClusterInstrumentation.java | 125 +++ .../jedis/v2/define/JedisInstrumentation.java | 138 +++ ...structorWithHostAndPortArgInterceptor.java | 32 - ...ctorWithListHostAndPortArgInterceptor.java | 38 - ...onstructorWithShardInfoArgInterceptor.java | 34 - ...isConstructorWithStringArgInterceptor.java | 36 - ...JedisConstructorWithUriArgInterceptor.java | 32 - .../jedis/v2/JedisMethodInterceptor.java | 58 -- .../define/JedisClusterInstrumentation.java | 107 -- .../jedis/v2/define/JedisInstrumentation.java | 120 --- .../src/main/resources/skywalking-plugin.def | 4 +- ...ctorWithHostAndPortArgInterceptorTest.java | 75 ++ ...WithListHostAndPortArgInterceptorTest.java | 83 ++ ...ructorWithShardInfoArgInterceptorTest.java | 74 ++ ...nstructorWithStringArgInterceptorTest.java | 76 ++ ...sConstructorWithUriArgInterceptorTest.java | 72 ++ .../jedis/v2/JedisMethodInterceptorTest.java | 46 +- ...ctorWithHostAndPortArgInterceptorTest.java | 57 -- ...WithListHostAndPortArgInterceptorTest.java | 65 -- ...ructorWithShardInfoArgInterceptorTest.java | 56 - ...nstructorWithStringArgInterceptorTest.java | 58 -- ...sConstructorWithUriArgInterceptorTest.java | 54 - .../AsyncHttpRequestSendInterceptor.java | 88 ++ .../client/CompleteListenerInterceptor.java | 85 ++ .../SyncHttpRequestSendInterceptor.java | 85 ++ .../CompleteListenerInstrumentation.java | 89 ++ .../define/HttpRequestInstrumentation.java | 106 ++ .../AsyncHttpRequestSendInterceptor.java | 70 -- .../client/CompleteListenerInterceptor.java | 67 -- .../SyncHttpRequestSendInterceptor.java | 67 -- .../CompleteListenerInstrumentation.java | 71 -- .../define/HttpRequestInstrumentation.java | 88 -- .../src/main/resources/skywalking-plugin.def | 4 +- .../AsyncHttpRequestSendInterceptorTest.java | 158 +++ .../CompleteListenerInterceptorTest.java | 38 +- .../SyncHttpRequestSendInterceptorTest.java | 158 +++ .../AsyncHttpRequestSendInterceptorTest.java | 140 --- .../SyncHttpRequestSendInterceptorTest.java | 140 --- .../jetty/v9/server/HandleInterceptor.java | 94 ++ .../server/define/JettyInstrumentation.java | 87 ++ .../jetty/v9/server/HandleInterceptor.java | 76 -- .../server/define/JettyInstrumentation.java | 69 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../v9/server/HandleInterceptorTest.java | 169 +++ .../v9/server/HandleInterceptorTest.java | 153 --- .../MongoDBCollectionMethodInterceptor.java | 120 +++ .../mongodb/v2/define/InterceptPoint.java | 56 + .../MongoDBCollectionImplInstrumentation.java | 158 +++ .../MongoDBCollectionInstrumentation.java | 34 +- .../MongoDBCollectionMethodInterceptor.java | 102 -- .../mongodb/v2/define/InterceptPoint.java | 38 - .../MongoDBCollectionImplInstrumentation.java | 140 --- .../src/main/resources/skywalking-plugin.def | 4 +- ...ongoDBCollectionMethodInterceptorTest.java | 144 +++ ...ongoDBCollectionMethodInterceptorTest.java | 125 --- .../mongodb/v3/MongoDBMethodInterceptor.java | 42 +- .../v3/define/MongoDBInstrumentation.java | 100 ++ .../v3/define/MongoDBInstrumentation.java | 82 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../v3/MongoDBMethodInterceptorTest.java | 160 +++ .../v3/MongoDBMethodInterceptorTest.java | 141 --- .../motan/MotanConsumerInterceptor.java | 117 +++ .../motan/MotanProviderInterceptor.java | 104 ++ .../define/MotanConsumerInstrumentation.java | 92 ++ .../define/MotanProviderInstrumentation.java | 117 +++ .../motan/MotanConsumerInterceptor.java | 99 -- .../motan/MotanProviderInterceptor.java | 86 -- .../define/MotanConsumerInstrumentation.java | 74 -- .../define/MotanProviderInstrumentation.java | 99 -- .../src/main/resources/skywalking-plugin.def | 4 +- .../motan/MotanConsumerInterceptorTest.java | 158 +++ .../motan/MotanProviderInterceptorTest.java | 185 ++++ .../motan/MotanConsumerInterceptorTest.java | 142 --- .../motan/MotanProviderInterceptorTest.java | 169 --- .../CreateCallableStatementInterceptor.java | 72 ++ .../CreatePreparedStatementInterceptor.java | 72 ++ .../mysql/CreateStatementInterceptor.java | 72 ++ .../StatementExecuteMethodsInterceptor.java | 103 ++ .../mysql/define/CallableInstrumentation.java | 89 ++ .../define/ConnectionInstrumentation.java | 126 +++ .../mysql/define/DriverInstrumentation.java | 54 + .../mysql/define/MultiClassNameMatch.java | 85 ++ .../Mysql50ConnectionInstrumentation.java | 58 ++ .../Mysql5xConnectionInstrumentation.java | 57 ++ .../PreparedStatementInstrumentation.java | 97 ++ .../define/StatementInstrumentation.java | 102 ++ .../CreateCallableStatementInterceptor.java | 54 - .../CreatePreparedStatementInterceptor.java | 54 - .../mysql/CreateStatementInterceptor.java | 54 - .../StatementExecuteMethodsInterceptor.java | 85 -- .../mysql/define/CallableInstrumentation.java | 71 -- .../define/ConnectionInstrumentation.java | 115 --- .../mysql/define/DriverInstrumentation.java | 36 - .../mysql/define/MultiClassNameMatch.java | 67 -- .../Mysql50ConnectionInstrumentation.java | 40 - .../Mysql5xConnectionInstrumentation.java | 39 - .../PreparedStatementInstrumentation.java | 79 -- .../define/StatementInstrumentation.java | 84 -- .../src/main/resources/skywalking-plugin.def | 12 +- ...reateCallableStatementInterceptorTest.java | 84 ++ ...reatePreparedStatementInterceptorTest.java | 83 ++ .../mysql/CreateStatementInterceptorTest.java | 84 ++ ...tatementExecuteMethodsInterceptorTest.java | 114 +++ ...reateCallableStatementInterceptorTest.java | 66 -- ...reatePreparedStatementInterceptorTest.java | 65 -- .../mysql/CreateStatementInterceptorTest.java | 66 -- ...tatementExecuteMethodsInterceptorTest.java | 96 -- .../sync/SenderConstructorInterceptor.java | 48 + .../nutz/http/sync/SenderSendInterceptor.java | 100 ++ .../AbstractNutzHttpInstrumentation.java | 95 ++ ...NutzHttpFilePostSenderInstrumentation.java | 47 + .../NutzHttpGetSenderInstrumentation.java | 48 + .../NutzHttpPostSenderInstrumentation.java | 48 + .../sync/SenderConstructorInterceptor.java | 30 - .../nutz/http/sync/SenderSendInterceptor.java | 82 -- .../AbstractNutzHttpInstrumentation.java | 77 -- ...NutzHttpFilePostSenderInstrumentation.java | 29 - .../NutzHttpGetSenderInstrumentation.java | 30 - .../NutzHttpPostSenderInstrumentation.java | 30 - .../src/main/resources/skywalking-plugin.def | 6 +- .../nutz/http/sync/SenderInterceptorTest.java | 148 +++ .../nutz/http/sync/SenderInterceptorTest.java | 130 --- .../mvc/ActionConstructorInterceptor.java | 58 ++ .../nutz/mvc/ActionMethodInterceptor.java | 109 ++ .../apm/plugin/nutz/mvc/PathMappingCache.java | 65 ++ .../mvc/define/ActionInstrumentation.java | 102 ++ .../mvc/ActionConstructorInterceptor.java | 40 - .../nutz/mvc/ActionMethodInterceptor.java | 91 -- .../apm/plugin/nutz/mvc/PathMappingCache.java | 47 - .../mvc/define/ActionInstrumentation.java | 84 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../plugin/okhttp/v3/RealCallInterceptor.java | 147 +++ .../v3/define/RealCallInstrumentation.java | 106 ++ .../plugin/okhttp/v3/RealCallInterceptor.java | 129 --- .../v3/define/RealCallInstrumentation.java | 88 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../okhttp/v3/RealCallInterceptorTest.java | 185 ++++ .../okhttp/v3/RealCallInterceptorTest.java | 171 ---- ...CPrepareStatementWithArrayInterceptor.java | 10 +- .../define/ConnectionInstrumentation.java | 166 +++ .../oracle/define/DriverInstrumentation.java | 54 + .../define/ConnectionInstrumentation.java | 158 --- .../oracle/define/DriverInstrumentation.java | 37 - .../src/main/resources/skywalking-plugin.def | 4 +- .../CreateCallableStatementInterceptor.java | 72 ++ .../CreatePreparedStatementInterceptor.java | 72 ++ .../CreateStatementInterceptor.java | 75 ++ ...reStatementWithStringArrayInterceptor.java | 83 ++ .../StatementExecuteMethodsInterceptor.java | 93 ++ ...AbstractJdbc2StatementInstrumentation.java | 104 ++ .../define/ConnectionInstrumentation.java | 149 +++ .../jdbc/postgresql/define/Constants.java | 49 + .../define/DriverInstrumentation.java | 55 + .../Jdbc3ConnectionInstrumentation.java | 132 +++ .../Jdbc4ConnectionInstrumentation.java | 131 +++ .../CreateCallableStatementInterceptor.java | 54 - .../CreatePreparedStatementInterceptor.java | 54 - .../CreateStatementInterceptor.java | 57 -- ...reStatementWithStringArrayInterceptor.java | 65 -- .../StatementExecuteMethodsInterceptor.java | 75 -- ...AbstractJdbc2StatementInstrumentation.java | 85 -- .../define/ConnectionInstrumentation.java | 142 --- .../jdbc/postgresql/define/Constants.java | 31 - .../define/DriverInstrumentation.java | 37 - .../Jdbc3ConnectionInstrumentation.java | 125 --- .../Jdbc4ConnectionInstrumentation.java | 124 --- .../src/main/resources/skywalking-plugin.def | 10 +- .../plugin/resin/v3/ResinV3Interceptor.java | 114 +++ .../v3/define/ResinV3Instrumentation.java | 98 ++ .../plugin/resin/v3/ResinV3Interceptor.java | 96 -- .../v3/define/ResinV3Instrumentation.java | 80 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../resin/v3/ResinV3InterceptorTest.java | 171 ++++ .../resin/v3/ResinV3InterceptorTest.java | 154 --- .../plugin/resin/v4/ResinV4Interceptor.java | 111 ++ .../v4/define/ResinV4Instrumentation.java | 97 ++ .../plugin/resin/v4/ResinV4Interceptor.java | 93 -- .../v4/define/ResinV4Instrumentation.java | 79 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../resin/v4/ResinV4InterceptorTest.java | 171 ++++ .../resin/v4/ResinV4InterceptorTest.java | 155 --- .../v4/AbstractMessageConsumeInterceptor.java | 96 ++ ...MessageConcurrentlyConsumeInterceptor.java | 68 ++ .../v4/MessageOrderlyConsumeInterceptor.java | 69 ++ .../rocketMQ/v4/MessageSendInterceptor.java | 119 +++ .../rocketMQ/v4/OnExceptionInterceptor.java | 79 ++ .../rocketMQ/v4/OnSuccessInterceptor.java | 86 ++ .../v4/UpdateNameServerInterceptor.java | 61 ++ ...umeMessageConcurrentlyInstrumentation.java | 86 ++ .../ConsumeMessageOrderlyInstrumentation.java | 86 ++ .../MQClientAPIImplInstrumentation.java | 107 ++ .../v4/define/SendCallBackEnhanceInfo.java | 62 ++ .../define/SendCallbackInstrumentation.java | 105 ++ .../v4/AbstractMessageConsumeInterceptor.java | 78 -- ...MessageConcurrentlyConsumeInterceptor.java | 50 - .../v4/MessageOrderlyConsumeInterceptor.java | 51 - .../rocketMQ/v4/MessageSendInterceptor.java | 101 -- .../rocketMQ/v4/OnExceptionInterceptor.java | 61 -- .../rocketMQ/v4/OnSuccessInterceptor.java | 68 -- .../v4/UpdateNameServerInterceptor.java | 43 - ...umeMessageConcurrentlyInstrumentation.java | 68 -- .../ConsumeMessageOrderlyInstrumentation.java | 68 -- .../MQClientAPIImplInstrumentation.java | 88 -- .../v4/define/SendCallBackEnhanceInfo.java | 44 - .../define/SendCallbackInstrumentation.java | 87 -- .../src/main/resources/skywalking-plugin.def | 8 +- .../v4/MessageSendInterceptorTest.java | 155 +++ .../v4/OnExceptionInterceptorTest.java | 105 ++ .../rocketMQ/v4/OnSuccessInterceptorTest.java | 131 +++ .../v4/MessageSendInterceptorTest.java | 137 --- .../v4/OnExceptionInterceptorTest.java | 87 -- .../rocketMQ/v4/OnSuccessInterceptorTest.java | 113 -- .../plugin/sjdbc/ExecuteEventListener.java | 105 ++ .../sjdbc/define/AsyncExecuteInterceptor.java | 77 ++ .../sjdbc/define/ExecuteInterceptor.java | 75 ++ .../ExecutorEngineConstructorInterceptor.java | 54 + .../sjdbc/define/ExecutorInstrumentation.java | 124 +++ .../plugin/sjdbc/ExecuteEventListener.java | 87 -- .../sjdbc/define/AsyncExecuteInterceptor.java | 59 -- .../sjdbc/define/ExecuteInterceptor.java | 57 -- .../ExecutorEngineConstructorInterceptor.java | 36 - .../sjdbc/define/ExecutorInstrumentation.java | 106 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../apm/plugin/sjdbc/InterceptorTest.java | 60 +- .../FailureCallbackInterceptor.java | 79 ++ .../SuccessCallbackInterceptor.java | 79 ++ .../FailureCallbackInstrumentation.java | 92 ++ ...stenableFutureCallbackInstrumentation.java | 105 ++ .../SuccessCallbackInstrumentation.java | 86 ++ .../match/EitherInterfaceMatch.java | 22 +- .../concurrent/match/FailedCallbackMatch.java | 67 ++ .../match/ListenableFutureCallbackMatch.java | 24 +- .../match/SuccessCallbackMatch.java | 68 ++ .../FailureCallbackInterceptor.java | 61 -- .../SuccessCallbackInterceptor.java | 61 -- .../FailureCallbackInstrumentation.java | 74 -- ...stenableFutureCallbackInstrumentation.java | 87 -- .../SuccessCallbackInstrumentation.java | 68 -- .../concurrent/match/FailedCallbackMatch.java | 49 - .../match/SuccessCallbackMatch.java | 50 - .../src/main/resources/skywalking-plugin.def | 6 +- ...towiredAnnotationProcessorInterceptor.java | 28 +- .../patch/CreateAopProxyInterceptor.java | 74 ++ .../AopProxyFactoryInstrumentation.java | 88 ++ ...redAnnotationProcessorInstrumentation.java | 97 ++ .../patch/CreateAopProxyInterceptor.java | 56 - .../AopProxyFactoryInstrumentation.java | 70 -- ...redAnnotationProcessorInstrumentation.java | 79 -- .../src/main/resources/skywalking-plugin.def | 4 +- .../patch/CreateAopProxyInterceptorTest.java | 91 ++ .../patch/CreateAopProxyInterceptorTest.java | 73 -- .../v3/ControllerConstructorInterceptor.java | 66 ++ .../v3/HandlerMethodInvokerInterceptor.java | 72 ++ .../AbstractSpring3Instrumentation.java | 54 + .../v3/define/ControllerInstrumentation.java | 107 ++ .../define/HandlerMethodInstrumentation.java | 91 ++ .../HandlerMethodInvokerInstrumentation.java | 84 ++ .../InvocableHandlerInstrumentation.java | 88 ++ .../v3/ControllerConstructorInterceptor.java | 48 - .../v3/HandlerMethodInvokerInterceptor.java | 54 - .../AbstractSpring3Instrumentation.java | 36 - .../v3/define/ControllerInstrumentation.java | 89 -- .../define/HandlerMethodInstrumentation.java | 73 -- .../HandlerMethodInvokerInstrumentation.java | 66 -- .../InvocableHandlerInstrumentation.java | 70 -- .../src/main/resources/skywalking-plugin.def | 8 +- .../ControllerConstructorInterceptorTest.java | 121 +++ .../spring/mvc/v3/GetBeanInterceptorTest.java | 90 ++ .../v3/InvokeForRequestInterceptorTest.java | 76 ++ .../ControllerConstructorInterceptorTest.java | 103 -- .../spring/mvc/v3/GetBeanInterceptorTest.java | 72 -- .../v3/InvokeForRequestInterceptorTest.java | 58 -- .../v4/ControllerConstructorInterceptor.java | 75 ++ .../AbstractControllerInstrumentation.java | 133 +++ .../AbstractSpring4Instrumentation.java | 48 + .../v4/define/ControllerInstrumentation.java | 46 + .../define/HandlerMethodInstrumentation.java | 91 ++ .../InvocableHandlerInstrumentation.java | 91 ++ .../define/RestControllerInstrumentation.java | 46 + .../v4/ControllerConstructorInterceptor.java | 57 -- .../AbstractControllerInstrumentation.java | 116 --- .../AbstractSpring4Instrumentation.java | 30 - .../v4/define/ControllerInstrumentation.java | 28 - .../define/HandlerMethodInstrumentation.java | 73 -- .../InvocableHandlerInstrumentation.java | 73 -- .../define/RestControllerInstrumentation.java | 28 - .../src/main/resources/skywalking-plugin.def | 8 +- .../ControllerConstructorInterceptorTest.java | 146 +++ .../spring/mvc/v4/PathMappingCacheTest.java | 68 ++ .../RequestMappingMethodInterceptorTest.java | 205 ++++ .../v4/RestMappingMethodInterceptorTest.java | 74 +- .../define/ControllerInstrumentationTest.java | 94 ++ .../RestControllerInstrumentationTest.java | 81 ++ .../ControllerConstructorInterceptorTest.java | 128 --- .../spring/mvc/v4/PathMappingCacheTest.java | 50 - .../RequestMappingMethodInterceptorTest.java | 189 ---- .../define/ControllerInstrumentationTest.java | 76 -- .../RestControllerInstrumentationTest.java | 63 -- .../plugin/spring/mvc/commons/Constants.java | 52 + .../commons/EnhanceRequireObjectCache.java | 70 ++ .../spring/mvc/commons/PathMappingCache.java | 63 ++ .../interceptor/AbstractMethodInteceptor.java | 108 ++ .../interceptor/GetBeanInterceptor.java | 72 ++ .../InvokeForRequestInterceptor.java | 70 ++ .../RequestMappingMethodInterceptor.java | 60 ++ .../RestMappingMethodInterceptor.java | 20 +- .../plugin/spring/mvc/commons/Constants.java | 34 - .../commons/EnhanceRequireObjectCache.java | 52 - .../spring/mvc/commons/PathMappingCache.java | 45 - .../interceptor/AbstractMethodInteceptor.java | 90 -- .../interceptor/GetBeanInterceptor.java | 54 - .../InvokeForRequestInterceptor.java | 52 - .../RequestMappingMethodInterceptor.java | 42 - .../async/FutureGetInterceptor.java | 68 ++ .../async/ResponseCallBackInterceptor.java | 68 ++ .../async/RestExecuteInterceptor.java | 89 ++ .../async/RestRequestInterceptor.java | 75 ++ ...esponseExtractorFutureInstrumentation.java | 113 ++ .../define/RestTemplateInstrumentation.java | 111 ++ .../sync/RestExecuteInterceptor.java | 82 ++ .../sync/RestRequestInterceptor.java | 76 ++ .../sync/RestResponseInterceptor.java | 74 ++ .../define/RestTemplateInstrumentation.java | 125 +++ .../async/FutureGetInterceptor.java | 50 - .../async/ResponseCallBackInterceptor.java | 50 - .../async/RestExecuteInterceptor.java | 71 -- .../async/RestRequestInterceptor.java | 57 -- ...esponseExtractorFutureInstrumentation.java | 95 -- .../define/RestTemplateInstrumentation.java | 93 -- .../sync/RestExecuteInterceptor.java | 64 -- .../sync/RestRequestInterceptor.java | 58 -- .../sync/RestResponseInterceptor.java | 56 - .../define/RestTemplateInstrumentation.java | 107 -- .../src/main/resources/skywalking-plugin.def | 6 +- .../define/NetflixFeignInstrumentation.java | 92 ++ .../define/NetflixFeignInstrumentation.java | 73 -- .../src/main/resources/skywalking-plugin.def | 2 +- ...thInetSocketAddressListArgInterceptor.java | 61 ++ .../v2/MemcachedMethodInterceptor.java | 77 ++ .../v2/define/MemcachedInstrumentation.java | 113 ++ ...thInetSocketAddressListArgInterceptor.java | 43 - .../v2/MemcachedMethodInterceptor.java | 59 -- .../v2/define/MemcachedInstrumentation.java | 95 -- .../src/main/resources/skywalking-plugin.def | 2 +- ...etSocketAddressListArgInterceptorTest.java | 74 ++ .../v2/MemcachedMethodInterceptorTest.java | 156 +++ ...etSocketAddressListArgInterceptorTest.java | 56 - .../v2/MemcachedMethodInterceptorTest.java | 137 --- .../plugin/struts2/Struts2Interceptor.java | 92 ++ .../define/Struts2Instrumentation.java | 87 ++ .../plugin/struts2/Struts2Interceptor.java | 74 -- .../define/Struts2Instrumentation.java | 69 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../struts2/Struts2InterceptorTest.java | 185 ++++ .../struts2/Struts2InterceptorTest.java | 167 --- .../tomcat78x/TomcatExceptionInterceptor.java | 62 ++ .../tomcat78x/TomcatInvokeInterceptor.java | 110 ++ .../define/TomcatInstrumentation.java | 118 +++ .../tomcat78x/TomcatExceptionInterceptor.java | 44 - .../tomcat78x/TomcatInvokeInterceptor.java | 92 -- .../define/TomcatInstrumentation.java | 103 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../TomcatInvokeInterceptorTest.java | 185 ++++ .../TomcatInvokeInterceptorTest.java | 169 --- ...dConstructorWithComplexArgInterceptor.java | 24 +- ...ConstructorWithHostPortArgInterceptor.java | 57 ++ ...orWithInetSocketAddressArgInterceptor.java | 60 ++ ...thInetSocketAddressListArgInterceptor.java | 69 ++ .../v2/XMemcachedMethodInterceptor.java | 82 ++ .../v2/define/XMemcachedInstrumentation.java | 42 +- ...ConstructorWithHostPortArgInterceptor.java | 39 - ...orWithInetSocketAddressArgInterceptor.java | 42 - ...thInetSocketAddressListArgInterceptor.java | 51 - .../v2/XMemcachedMethodInterceptor.java | 64 -- .../src/main/resources/skywalking-plugin.def | 2 +- ...structorWithComplexArgInterceptorTest.java | 74 ++ ...tructorWithHostPortArgInterceptorTest.java | 68 ++ ...thInetSocketAddressArgInterceptorTest.java | 70 ++ ...etSocketAddressListArgInterceptorTest.java | 75 ++ .../v2/XMemcachedMethodInterceptorTest.java | 149 +++ ...structorWithComplexArgInterceptorTest.java | 56 - ...tructorWithHostPortArgInterceptorTest.java | 50 - ...thInetSocketAddressArgInterceptorTest.java | 52 - ...etSocketAddressListArgInterceptorTest.java | 57 -- .../v2/XMemcachedMethodInterceptorTest.java | 131 --- .../apm/agent/test/helper/FieldGetter.java | 62 ++ .../apm/agent/test/helper/FieldSetter.java | 60 ++ .../apm/agent/test/helper/SegmentHelper.java | 53 + .../agent/test/helper/SegmentRefHelper.java | 78 ++ .../apm/agent/test/helper/SpanHelper.java | 156 +++ .../agent/test/tools/AgentServiceRule.java | 74 ++ .../agent/test/tools/SegmentRefAssert.java | 62 ++ .../apm/agent/test/tools/SegmentStorage.java | 68 ++ .../agent/test/tools/SegmentStoragePoint.java | 47 + .../apm/agent/test/tools/SpanAssert.java | 97 ++ .../test/tools/TracingSegmentRunner.java | 109 ++ .../apm/agent/test/helper/FieldGetter.java | 44 - .../apm/agent/test/helper/FieldSetter.java | 42 - .../apm/agent/test/helper/SegmentHelper.java | 35 - .../agent/test/helper/SegmentRefHelper.java | 60 -- .../apm/agent/test/helper/SpanHelper.java | 138 --- .../agent/test/tools/AgentServiceRule.java | 56 - .../agent/test/tools/SegmentRefAssert.java | 44 - .../apm/agent/test/tools/SegmentStorage.java | 50 - .../agent/test/tools/SegmentStoragePoint.java | 29 - .../apm/agent/test/tools/SpanAssert.java | 79 -- .../test/tools/TracingSegmentRunner.java | 91 -- .../log4j/v1/x/PrintTraceIdInterceptor.java | 64 ++ .../x/TraceIdPatternConverterActivation.java | 98 ++ .../log4j/v1/x/PrintTraceIdInterceptor.java | 46 - .../x/TraceIdPatternConverterActivation.java | 80 -- .../src/main/resources/skywalking-plugin.def | 2 +- .../v2/x/Log4j2OutputAppenderActivation.java | 89 ++ .../log4j/v2/x/PrintTraceIdInterceptor.java | 73 ++ .../v2/x/Log4j2OutputAppenderActivation.java | 71 -- .../log4j/v2/x/PrintTraceIdInterceptor.java | 55 - .../src/main/resources/skywalking-plugin.def | 2 +- .../x/LogbackPatternConverterActivation.java | 99 ++ .../logback/v1/x/PrintTraceIdInterceptor.java | 64 ++ .../v1/x/mdc/MDCConverterActivation.java | 84 ++ .../v1/x/mdc/PrintMDCTraceIdInterceptor.java | 63 ++ .../x/LogbackPatternConverterActivation.java | 81 -- .../logback/v1/x/PrintTraceIdInterceptor.java | 46 - .../v1/x/mdc/MDCConverterActivation.java | 66 -- .../v1/x/mdc/PrintMDCTraceIdInterceptor.java | 45 - .../src/main/resources/skywalking-plugin.def | 4 +- .../continuation/ActivateInterceptor.java | 64 ++ .../continuation/ConstructorInterceptor.java | 48 + .../SkywalkingContinuationActivation.java | 104 ++ ...ConstructorWithSpanBuilderInterceptor.java | 76 ++ .../ConstructorWithTracerInterceptor.java | 49 + .../span/SkywalkingSpanActivation.java | 188 ++++ .../span/SpanFinishInterceptor.java | 68 ++ .../opentracing/span/SpanLogInterceptor.java | 71 ++ .../span/SpanSetOperationNameInterceptor.java | 67 ++ .../span/SpanSetTagInterceptor.java | 74 ++ .../tracer/SkywalkingTracerActivation.java | 103 ++ .../SkywalkingTracerExtractInterceptor.java | 89 ++ .../SkywalkingTracerInjectInterceptor.java | 81 ++ .../continuation/ActivateInterceptor.java | 46 - .../continuation/ConstructorInterceptor.java | 30 - .../SkywalkingContinuationActivation.java | 86 -- ...ConstructorWithSpanBuilderInterceptor.java | 58 -- .../ConstructorWithTracerInterceptor.java | 31 - .../span/SkywalkingSpanActivation.java | 170 --- .../span/SpanFinishInterceptor.java | 50 - .../opentracing/span/SpanLogInterceptor.java | 53 - .../span/SpanSetOperationNameInterceptor.java | 49 - .../span/SpanSetTagInterceptor.java | 56 - .../tracer/SkywalkingTracerActivation.java | 85 -- .../SkywalkingTracerExtractInterceptor.java | 71 -- .../SkywalkingTracerInjectInterceptor.java | 63 -- .../src/main/resources/skywalking-plugin.def | 6 +- .../SkywalkingSpanActivationTest.java | 87 +- .../trace/ActiveSpanTagActivation.java | 86 ++ .../trace/ActiveSpanTagInterceptor.java | 66 ++ .../trace/TraceAnnotationActivation.java | 86 ++ .../TraceAnnotationMethodInterceptor.java | 90 ++ .../trace/TraceContextActivation.java | 89 ++ .../trace/TraceContextInterceptor.java | 66 ++ .../trace/ActiveSpanTagActivation.java | 68 -- .../trace/ActiveSpanTagInterceptor.java | 48 - .../trace/TraceAnnotationActivation.java | 68 -- .../TraceAnnotationMethodInterceptor.java | 72 -- .../trace/TraceContextActivation.java | 71 -- .../trace/TraceContextInterceptor.java | 48 - .../src/main/resources/skywalking-plugin.def | 6 +- .../activation/trace/TraceAnnotationTest.java | 138 +++ .../activation/trace/TraceAnnotationTest.java | 121 --- apm-sniffer/pom.xml | 2 +- docs/cn/Application-toolkit-log4j-1.x-CN.md | 4 +- docs/cn/Application-toolkit-log4j-2.x-CN.md | 2 +- docs/cn/Application-toolkit-logback-1.x-CN.md | 4 +- docs/cn/Application-toolkit-trace-CN.md | 4 +- docs/cn/FAQ/Too-many-gRPC-logs-CN.md | 2 +- docs/cn/How-to-build-CN.md | 2 +- ...ow-to-communicate-with-the-collector-CN.md | 8 +- docs/cn/Plugin-Development-Guide-CN.md | 6 +- docs/cn/skywalking-opentracing-CN.md | 4 +- docs/en/Application-toolkit-log4j-1.x.md | 4 +- docs/en/Application-toolkit-log4j-2.x.md | 2 +- docs/en/Application-toolkit-logback-1.x.md | 2 +- docs/en/Application-toolkit-trace.md | 4 +- docs/en/Opentracing.md | 4 +- pom.xml | 8 +- 2260 files changed, 78285 insertions(+), 59712 deletions(-) rename java.header => CHECKSTYLE_HEAD (100%) rename ApacheCopyright => HEADER (100%) create mode 100644 apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java create mode 100644 apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java create mode 100644 apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java delete mode 100644 apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java delete mode 100644 apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java delete mode 100644 apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java create mode 100644 apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java create mode 100644 apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java delete mode 100644 apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java delete mode 100644 apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java create mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java create mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java create mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java create mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java delete mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java delete mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java delete mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java delete mode 100644 apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/ByteBufferContext.java create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java rename apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/{ => apache}/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java (79%) create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContext.java create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java rename apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/{ => apache}/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java (82%) rename apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/{ => apache}/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java (86%) create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/Tag.java create mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/TextMapContext.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/ByteBufferContext.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java delete mode 100644 apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/TextMapContext.java create mode 100644 apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java create mode 100644 apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/Trace.java create mode 100644 apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceContext.java delete mode 100644 apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/ActiveSpan.java delete mode 100644 apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/Trace.java delete mode 100644 apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/TraceContext.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java delete mode 100644 apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentJettyModule.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentJettyModule.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java rename apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java (79%) rename apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java (75%) rename apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java (84%) create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java rename apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/{ => apache}/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java (80%) create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java create mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java delete mode 100644 apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModule.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModule.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/IdAutoIncrement.java rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java (81%) rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/buffer/Offset.java (77%) rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java (82%) rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java (75%) rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java (81%) create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/GraphDefine.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SegmentParse.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java (83%) rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java (76%) create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java (83%) create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/util/FileUtils.java (76%) create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java (77%) create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java rename apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java (79%) delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/IdAutoIncrement.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/GraphDefine.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SegmentParse.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java create mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModule.java delete mode 100644 apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/skywalking/apm/collector/alerting/AlertingModule.java create mode 100644 apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModuleProvider.java create mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java create mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java delete mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/AlertingModuleProvider.java delete mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java delete mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java create mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/apache/skywalking/apm/collector/baseline/computing/ComputingModule.java delete mode 100644 apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/skywalking/apm/collector/baseline/computing/ComputingModule.java create mode 100644 apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/apache/skywalking/collector/baseline/computing/provider/ComputingProvider.java delete mode 100644 apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/skywalking/collector/baseline/computing/provider/ComputingProvider.java create mode 100644 apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/CollectorBootStartUp.java rename apm-collector/apm-collector-boot/src/main/java/org/{ => apache}/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java (81%) create mode 100644 apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java create mode 100644 apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigLoader.java delete mode 100644 apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java delete mode 100644 apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java delete mode 100644 apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigLoader.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/CacheModule.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/InstanceCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceIdCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java delete mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterException.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModule.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModuleListener.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterNodeExistException.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/DataMonitor.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ModuleRegistration.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleListenerService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleRegisterService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterException.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModule.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleListener.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterNodeExistException.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/DataMonitor.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ModuleRegistration.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleListenerService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleRegisterService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java rename apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java (80%) create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java create mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/Client.java create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/ClientException.java rename apm-collector/apm-collector-component/client-component/src/main/java/org/{ => apache}/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java (86%) create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClient.java create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClientException.java rename apm-collector/apm-collector-component/client-component/src/main/java/org/{ => apache}/skywalking/apm/collector/client/h2/H2Client.java (80%) create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2ClientException.java create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClient.java create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClientException.java rename apm-collector/apm-collector-component/client-component/src/main/java/org/{ => apache}/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java (80%) create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java create mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/util/PathUtils.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/Client.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/ClientException.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClient.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClientException.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2ClientException.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClient.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClientException.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java delete mode 100644 apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/util/PathUtils.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/Server.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerException.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerHandler.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCHandler.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServer.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServerException.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/ArgumentsParseException.java rename apm-collector/apm-collector-component/server-component/src/main/java/org/{ => apache}/skywalking/apm/collector/server/jetty/JettyHandler.java (84%) create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServer.java create mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServerException.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/Server.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerException.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerHandler.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCHandler.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServer.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServerException.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/ArgumentsParseException.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServer.java delete mode 100644 apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServerException.java create mode 100644 apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModule.java create mode 100644 apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/service/IApdexThresholdService.java delete mode 100644 apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModule.java delete mode 100644 apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/service/IApdexThresholdService.java create mode 100644 apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java create mode 100644 apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/service/ApdexThresholdService.java delete mode 100644 apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java delete mode 100644 apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/service/ApdexThresholdService.java create mode 100644 apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/CollectorException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/UnexpectedException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Collection.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Window.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessage.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Attribute.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AttributeType.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Column.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/ColumnDefine.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/CommonTable.java rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/data/Data.java (89%) create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Operation.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefineLoader.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefinitionFile.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/TableDefine.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/AddOperation.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/CoverOperation.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/NonOperation.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefineException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionFile.java rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/define/DefinitionLoader.java (80%) create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/Loader.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/framework/Executor.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/DirectWay.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Graph.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphManager.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNodeFinder.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNotFoundException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Next.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Node.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeNotFoundException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeProcessor.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/WayToNode.java rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/module/ApplicationConfiguration.java (76%) rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/module/BootstrapFlow.java (84%) create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/CycleDependencyException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/DuplicateProviderException.java rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/module/Module.java (82%) rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/module/ModuleManager.java (78%) create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/module/ModuleProvider.java (83%) create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ProviderNotFoundException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Service.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ApdexThresholdUtils.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BytesUtils.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/CollectionUtils.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtils.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/Const.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ObjectUtils.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ResourceUtils.java create mode 100644 apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/StringUtils.java rename apm-collector/apm-collector-core/src/main/java/org/{ => apache}/skywalking/apm/collector/core/util/TimeBucketUtils.java (85%) delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/CollectorException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/UnexpectedException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Collection.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Window.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AbstractHashMessage.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Attribute.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AttributeType.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Column.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/ColumnDefine.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/CommonTable.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Operation.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefineLoader.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefinitionFile.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/TableDefine.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/AddOperation.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/CoverOperation.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/NonOperation.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefineException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionFile.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/Loader.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/framework/Executor.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/DirectWay.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Graph.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphManager.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNodeFinder.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNotFoundException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Next.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Node.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeNotFoundException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeProcessor.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/WayToNode.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CycleDependencyException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/DuplicateProviderException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ProviderNotFoundException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Service.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ApdexThresholdUtils.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/BytesUtils.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/CollectionUtils.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ColumnNameUtils.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ObjectUtils.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java delete mode 100644 apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/StringUtils.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessageTest.java rename apm-collector/apm-collector-core/src/test/java/org/{ => apache}/skywalking/apm/collector/core/define/DefinitionLoaderTest.java (96%) create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceImpl.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceInterface.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/TestDefineFile.java rename apm-collector/apm-collector-core/src/test/java/org/{ => apache}/skywalking/apm/collector/core/graph/GraphManagerTest.java (85%) create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node1Processor.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node2Processor.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node3Processor.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node4Processor.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/OutputProcessor.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleA.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleB.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleAProvider.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBProvider.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleManagerTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModule.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModuleProvider.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/BytesUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/CollectionUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ObjectUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ResourceUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/StringUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node1Processor.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node2Processor.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node3Processor.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node4Processor.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/OutputProcessor.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleA.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleB.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleAProvider.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBProvider.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleManagerTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModule.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModuleProvider.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java delete mode 100644 apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java create mode 100644 apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java create mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java delete mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java delete mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java create mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java create mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java delete mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java delete mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java create mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider rename apm-collector/apm-collector-instrument/src/main/java/org/{ => apache}/skywalking/apm/collector/instrument/MetricCollector.java (88%) rename apm-collector/apm-collector-instrument/src/main/java/org/{ => apache}/skywalking/apm/collector/instrument/ServiceInstrumentation.java (77%) create mode 100644 apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java create mode 100644 apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/TracedService.java delete mode 100644 apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceMetricTracing.java delete mode 100644 apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/TracedService.java create mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerModule.java create mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java delete mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerModule.java delete mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java create mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java create mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java delete mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java delete mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java create mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/NamingModule.java create mode 100644 apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java delete mode 100644 apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/NamingModule.java delete mode 100644 apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java create mode 100644 apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java create mode 100644 apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java delete mode 100644 apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java delete mode 100644 apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java create mode 100644 apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/QueueModule.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/DaemonThreadFactory.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/MessageHolder.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueCreator.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueEventHandler.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueExecutor.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/service/QueueCreatorService.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/QueueModule.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/DaemonThreadFactory.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/MessageHolder.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueCreator.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueEventHandler.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueExecutor.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/service/QueueCreatorService.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java delete mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java create mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteException.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteModule.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RoutingRule.java rename apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/{ => apache}/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java (75%) create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClient.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClientService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDeserializeService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSenderService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSerializeService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/Selector.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteException.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteModule.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RoutingRule.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClient.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClientService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDeserializeService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSenderService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSerializeService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/Selector.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java create mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageException.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstallException.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstaller.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/AbstractDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IBatchDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/sql/SqlBuilder.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/CommonMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingList.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/table/application/ApplicationMetric.java (84%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java (85%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTrace.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/table/instance/InstanceMetric.java (83%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java (85%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetric.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetric.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Instance.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/InstanceTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceName.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceNameTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/Segment.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntry.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/table/service/ServiceMetric.java (83%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java (87%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageException.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstallException.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstaller.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageModule.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/AbstractDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IBatchDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/sql/SqlBuilder.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/CommonMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingList.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponent.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMapping.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTrace.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetric.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetric.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Application.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Instance.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceName.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/Segment.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCost.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntry.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/EsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java (81%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java (78%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java (75%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java (77%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java (75%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java (75%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java (87%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java (88%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java (85%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java (83%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java (86%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java (86%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java (83%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java (81%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java (76%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java (85%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java (84%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java (87%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java (77%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java (76%) delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/EsDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java (76%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java (85%) rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java (87%) rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java (80%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java (80%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java (82%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java (84%) rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java (83%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java (81%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java (75%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java (84%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java (78%) rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java (86%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java (76%) create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java (75%) delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/timer/PersistenceTimer.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorker.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/Provider.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerException.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerRef.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java rename apm-collector/apm-collector-stream/src/main/java/org/{ => apache}/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java (75%) create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCache.java create mode 100644 apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/timer/PersistenceTimer.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorker.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/Provider.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerException.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerRef.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCache.java delete mode 100644 apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/apache/skywalking/apm/collector/ui/UIModule.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/skywalking/apm/collector/ui/UIModule.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module delete mode 100644 apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java (79%) create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java (76%) create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/service/InstanceHealthService.java (75%) rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/service/InstanceJVMService.java (82%) create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/service/ServiceTreeService.java (80%) rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/service/SpanService.java (75%) create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java (79%) create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java rename apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/{ => apache}/skywalking/apm/collector/ui/service/TraceStackService.java (84%) delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ApplicationService.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SegmentTopService.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TimeSynchronousService.java delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagService.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider delete mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider rename apm-commons/apm-datacarrier/src/main/java/org/{ => apache}/skywalking/apm/commons/datacarrier/DataCarrier.java (75%) create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Buffer.java create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java rename apm-commons/apm-datacarrier/src/main/java/org/{ => apache}/skywalking/apm/commons/datacarrier/buffer/Channels.java (75%) create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java rename apm-commons/apm-datacarrier/src/main/java/org/{ => apache}/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java (84%) rename apm-commons/apm-datacarrier/src/main/java/org/{ => apache}/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java (78%) create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/IConsumer.java create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java create mode 100644 apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java delete mode 100644 apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java rename apm-commons/apm-datacarrier/src/test/java/org/{ => apache}/skywalking/apm/commons/datacarrier/DataCarrierTest.java (82%) create mode 100644 apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/SampleData.java create mode 100644 apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java create mode 100644 apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java rename apm-commons/apm-datacarrier/src/test/java/org/{ => apache}/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java (81%) create mode 100644 apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java create mode 100644 apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java create mode 100644 apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java delete mode 100644 apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java delete mode 100644 apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java delete mode 100644 apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java delete mode 100644 apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java delete mode 100644 apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java delete mode 100644 apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java rename apm-commons/apm-util/src/main/java/org/{ => apache}/skywalking/apm/util/ConfigInitializer.java (83%) rename apm-commons/apm-util/src/main/java/org/{ => apache}/skywalking/apm/util/MachineInfo.java (75%) create mode 100644 apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java delete mode 100644 apm-commons/apm-util/src/main/java/org/skywalking/apm/util/StringUtil.java rename apm-commons/apm-util/src/test/java/org/{ => apache}/skywalking/apm/util/ConfigInitializerTest.java (77%) create mode 100644 apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java delete mode 100644 apm-commons/apm-util/src/test/java/org/skywalking/apm/util/StringUtilTest.java create mode 100644 apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/Component.java rename apm-network/src/main/java/org/{ => apache}/skywalking/apm/network/trace/component/ComponentsDefine.java (82%) create mode 100644 apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/OfficialComponent.java delete mode 100644 apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java delete mode 100644 apm-network/src/main/java/org/skywalking/apm/network/trace/component/OfficialComponent.java create mode 100644 apm-network/src/test/java/org/apache/skywalking/apm/network/trace/proto/GRPCNoServerTest.java delete mode 100644 apm-network/src/test/java/org/skywalking/apm/network/trace/proto/GRPCNoServerTest.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/BootService.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/boot/ServiceManager.java (78%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/conf/Config.java (81%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/ConfigNotFoundException.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Constants.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java (80%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/AbstractTracerContext.java (77%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItem.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItemHead.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/ContextCarrier.java (84%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/ContextManager.java (81%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/ContextSnapshot.java (75%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/IgnoredTracerContext.java (79%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/Injectable.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/SW3CarrierItem.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TraceContextCarrierItem.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/TracingContext.java (90%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContextListener.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceId.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java (79%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/ids/ID.java (75%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/AbstractTag.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/StringTag.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java (86%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/trace/EntrySpan.java (81%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/trace/ExitSpan.java (81%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LocalSpan.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LogDataEntity.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopExitSpan.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/SpanLayer.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegment.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java (82%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/WithPeerInfo.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/KeyValuePair.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryManager.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/Found.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/NotFound.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java (78%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/PossibleFound.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/G1GCModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCProvider.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/UnknowGC.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java (75%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/ILog.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogManager.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogResolver.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/NoopLogger.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolver.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/logging/core/EasyLogger.java (80%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/logging/core/FileWriter.java (85%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/IWriter.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogLevel.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogMessageHolder.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriter.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/WriterFactory.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/os/OSUtil.java (80%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/ProcessorUtil.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java (78%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/EnhanceContext.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginBootstrap.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginException.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/PluginFinder.java (77%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessClassFinder.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java (77%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java (85%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java (78%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java (78%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java (79%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java (79%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java (85%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java (77%) rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java (77%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassMatch.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java (80%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/IndirectMatch.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java (79%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/NameMatch.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java (79%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelListener.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/remote/GRPCChannelManager.java (82%) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelStatus.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/RESTResponseStatusError.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java rename apm-sniffer/apm-agent-core/src/main/java/org/{ => apache}/skywalking/apm/agent/core/sampling/SamplingService.java (75%) delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackagePath.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/BootService.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/ConfigNotFoundException.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Constants.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItem.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItemHead.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/SW3CarrierItem.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TraceContextCarrierItem.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceId.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Base64.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Objects.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/StandardCharsets.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/AbstractTag.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopExitSpan.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/SpanLayer.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/ThrowableTransformer.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/ILog.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogManager.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogResolver.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/NoopLogger.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolver.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/IWriter.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogLevel.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogMessageHolder.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriter.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/WriterFactory.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/ProcessorUtil.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/EnhanceContext.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginDefine.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginException.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/WitnessClassFinder.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassMatch.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/IndirectMatch.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/NameMatch.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelListener.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelStatus.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/RESTResponseStatusError.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java create mode 100644 apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService delete mode 100644 apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.skywalking.apm.agent.core.boot.BootService create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/ServiceManagerTest.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java rename apm-sniffer/apm-agent-core/src/test/java/org/{ => apache}/skywalking/apm/agent/core/context/ContextManagerTest.java (81%) create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/FieldGetter.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SegmentHelper.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SpanHelper.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java rename apm-sniffer/apm-agent-core/src/test/java/org/{ => apache}/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java (79%) create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriterTest.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java rename apm-sniffer/apm-agent-core/src/test/java/org/{ => apache}/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java (79%) rename apm-sniffer/apm-agent-core/src/test/java/org/{ => apache}/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java (81%) create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/AgentServiceRule.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStorage.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java create mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/ServiceManagerTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SpanHelper.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/FileWriterTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/AgentServiceRule.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStorage.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java create mode 100644 apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java rename apm-sniffer/apm-agent/src/main/java/org/{ => apache}/skywalking/apm/agent/SkyWalkingAgent.java (77%) delete mode 100644 apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/InstrumentDebuggingClass.java create mode 100644 apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInstrumentation.java rename apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/dubbo/DubboInterceptor.java (76%) delete mode 100644 apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInstrumentation.java rename apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java (75%) create mode 100644 apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java rename apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java (77%) create mode 100644 apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java rename apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java (78%) create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/Constants.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/Constants.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java rename apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java (79%) delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java rename apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java (80%) create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java (83%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java (76%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java (83%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java (76%) create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java (97%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java (95%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/jdbc/trace/SWStatement.java (92%) create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/StatementTracing.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/Constants.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/AbstractStatementTest.java create mode 100755 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionTracing.java rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/{ => apache}/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java (96%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/{ => apache}/skywalking/apm/plugin/jdbc/SWConnection.java (90%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/{ => apache}/skywalking/apm/plugin/jdbc/SWConnectionTest.java (90%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/{ => apache}/skywalking/apm/plugin/jdbc/SWStatementTest.java (89%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/{ => apache}/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java (95%) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/{ => apache}/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java (87%) delete mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/AbstractStatementTest.java delete mode 100755 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java rename apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java (87%) create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java rename apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java (75%) delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java rename apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java (75%) create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java create mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java rename apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java (78%) delete mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java rename apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java (84%) create mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java create mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java delete mode 100644 apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java delete mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java rename apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/sjdbc/InterceptorTest.java (78%) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java rename apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java (78%) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java rename apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java (75%) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java rename apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/{ => apache}/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java (80%) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java rename apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/{ => apache}/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java (82%) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java rename apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/{ => apache}/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java (79%) delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/Constants.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/Struts2Interceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java rename apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java (76%) create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java rename apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/{ => apache}/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java (75%) delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldGetter.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldSetter.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentHelper.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentRefHelper.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SpanHelper.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/AgentServiceRule.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentRefAssert.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStorage.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStoragePoint.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SpanAssert.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/TracingSegmentRunner.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldGetter.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldSetter.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentHelper.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentRefHelper.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SpanHelper.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/AgentServiceRule.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentRefAssert.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStorage.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStoragePoint.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SpanAssert.java delete mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/TracingSegmentRunner.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java rename apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/{ => apache}/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java (79%) create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java diff --git a/java.header b/CHECKSTYLE_HEAD similarity index 100% rename from java.header rename to CHECKSTYLE_HEAD diff --git a/ApacheCopyright b/HEADER similarity index 100% rename from ApacheCopyright rename to HEADER diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/pom.xml b/apm-application-toolkit/apm-toolkit-log4j-1.x/pom.xml index 2a1ef20c65a6..6721f256891f 100644 --- a/apm-application-toolkit/apm-toolkit-log4j-1.x/pom.xml +++ b/apm-application-toolkit/apm-toolkit-log4j-1.x/pom.xml @@ -64,7 +64,7 @@ bintray-wu-sheng-sky-walking-repository wu-sheng-sky-walking-repository - https://api.bintray.com/maven/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-1.x/;publish=1 + https://api.bintray.com/maven/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-1.x/;publish=1 diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java new file mode 100644 index 000000000000..4b01641c198c --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.log4j.v1.x; + +import org.apache.log4j.helpers.PatternConverter; +import org.apache.log4j.spi.LoggingEvent; + +/** + * Default implementation outputs "TID: N/A". + * But, if in sky-walking agent active mode, output will become the real ids. + *

+ * Created by wusheng on 2016/12/7. + */ + +public class TraceIdPatternConverter extends PatternConverter { + @Override + protected String convert(LoggingEvent loggingEvent) { + return "TID: N/A"; + } +} diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java new file mode 100644 index 000000000000..b2307dd3fd8c --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.log4j.v1.x; + +import org.apache.log4j.PatternLayout; +import org.apache.log4j.helpers.PatternParser; + +/** + * The log4j extend pattern. By using this pattern, if sky-walking agent is also active, {@link + * PatternParser#finalizeConverter(char)} method will be override dynamic.

+ * + * @author wusheng + */ +public class TraceIdPatternLayout extends PatternLayout { + @Override + protected PatternParser createPatternParser(String pattern) { + return new TraceIdPatternParser(pattern); + } +} diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java new file mode 100644 index 000000000000..6308adde76ef --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.log4j.v1.x; + +import org.apache.log4j.helpers.PatternParser; + +/** + * Base on '%T', use {@link TraceIdPatternConverter} to convert the '%t' to traceId. + *

+ * Created by wusheng on 2016/12/7. + */ +public class TraceIdPatternParser extends PatternParser { + public TraceIdPatternParser(String pattern) { + super(pattern); + } + + @Override + protected void finalizeConverter(char c) { + if ('T' == c) { + addConverter(new TraceIdPatternConverter()); + } else { + super.finalizeConverter(c); + } + } +} diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java deleted file mode 100644 index bc78843c4c13..000000000000 --- a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.log4j.v1.x; - -import org.apache.log4j.helpers.PatternConverter; -import org.apache.log4j.spi.LoggingEvent; - -/** - * Default implementation outputs "TID: N/A". - * But, if in sky-walking agent active mode, output will become the real ids. - *

- * Created by wusheng on 2016/12/7. - */ - -public class TraceIdPatternConverter extends PatternConverter { - @Override - protected String convert(LoggingEvent loggingEvent) { - return "TID: N/A"; - } -} diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java deleted file mode 100644 index 118637a492f4..000000000000 --- a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternLayout.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.log4j.v1.x; - -import org.apache.log4j.PatternLayout; -import org.apache.log4j.helpers.PatternParser; - -/** - * The log4j extend pattern. By using this pattern, if sky-walking agent is also active, {@link - * PatternParser#finalizeConverter(char)} method will be override dynamic.

- * - * @author wusheng - */ -public class TraceIdPatternLayout extends PatternLayout { - @Override - protected PatternParser createPatternParser(String pattern) { - return new TraceIdPatternParser(pattern); - } -} diff --git a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java b/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java deleted file mode 100644 index 5a53fb94b9b3..000000000000 --- a/apm-application-toolkit/apm-toolkit-log4j-1.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v1/x/TraceIdPatternParser.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.log4j.v1.x; - -import org.apache.log4j.helpers.PatternParser; - -/** - * Base on '%T', use {@link TraceIdPatternConverter} to convert the '%t' to traceId. - *

- * Created by wusheng on 2016/12/7. - */ -public class TraceIdPatternParser extends PatternParser { - public TraceIdPatternParser(String pattern) { - super(pattern); - } - - @Override - protected void finalizeConverter(char c) { - if ('T' == c) { - addConverter(new TraceIdPatternConverter()); - } else { - super.finalizeConverter(c); - } - } -} diff --git a/apm-application-toolkit/apm-toolkit-log4j-2.x/pom.xml b/apm-application-toolkit/apm-toolkit-log4j-2.x/pom.xml index dd621f0628fe..cc3bc9099bb7 100644 --- a/apm-application-toolkit/apm-toolkit-log4j-2.x/pom.xml +++ b/apm-application-toolkit/apm-toolkit-log4j-2.x/pom.xml @@ -64,7 +64,7 @@ bintray-wu-sheng-sky-walking-repository wu-sheng-sky-walking-repository - https://api.bintray.com/maven/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/;publish=1 + https://api.bintray.com/maven/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/;publish=1 diff --git a/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java b/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java new file mode 100644 index 000000000000..c5e7670bcaae --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.log4j.v2.x; + +/** + * Created by wusheng on 2016/12/11. + */ +public class Log4j2OutputAppender { + /** + * As default, append "TID: N/A" to the output message, + * if sky-walking agent in active mode, append the real traceId in the recent Context, if existed, or empty String. + * + * @param toAppendTo origin output message. + */ + public static void append(StringBuilder toAppendTo) { + toAppendTo.append("TID: N/A"); + } +} diff --git a/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java b/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java new file mode 100644 index 000000000000..4527deb85181 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.log4j.v2.x; + +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.pattern.ConverterKeys; +import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; + +/** + * {@link TraceIdConverter} is a log4j2 plugin, by annotation as {@link Plugin}. + * It convert the pattern key: traceId. + * Use '%traceId' in log4j2's config: , + * '%traceId' will output as TID:xxxx + *

+ * Created by wusheng on 2016/12/7. + */ +@Plugin(name = "TraceIdConverter", category = "Converter") +@ConverterKeys({"traceId"}) +public class TraceIdConverter extends LogEventPatternConverter { + + /** + * Constructs an instance of LoggingEventPatternConverter. + * + * @param name name of converter. + * @param style CSS style for output. + */ + protected TraceIdConverter(String name, String style) { + super(name, style); + } + + public static TraceIdConverter newInstance(String[] options) { + return new TraceIdConverter("traceId", "traceId"); + } + + @Override + public void format(LogEvent event, StringBuilder toAppendTo) { + Log4j2OutputAppender.append(toAppendTo); + } +} diff --git a/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java b/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java deleted file mode 100644 index 82298767193c..000000000000 --- a/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.log4j.v2.x; - -/** - * Created by wusheng on 2016/12/11. - */ -public class Log4j2OutputAppender { - /** - * As default, append "TID: N/A" to the output message, - * if sky-walking agent in active mode, append the real traceId in the recent Context, if existed, or empty String. - * - * @param toAppendTo origin output message. - */ - public static void append(StringBuilder toAppendTo) { - toAppendTo.append("TID: N/A"); - } -} diff --git a/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java b/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java deleted file mode 100644 index 2d5638c52992..000000000000 --- a/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.log4j.v2.x; - -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.pattern.ConverterKeys; -import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; - -/** - * {@link TraceIdConverter} is a log4j2 plugin, by annotation as {@link Plugin}. - * It convert the pattern key: traceId. - * Use '%traceId' in log4j2's config: , - * '%traceId' will output as TID:xxxx - *

- * Created by wusheng on 2016/12/7. - */ -@Plugin(name = "TraceIdConverter", category = "Converter") -@ConverterKeys({"traceId"}) -public class TraceIdConverter extends LogEventPatternConverter { - - /** - * Constructs an instance of LoggingEventPatternConverter. - * - * @param name name of converter. - * @param style CSS style for output. - */ - protected TraceIdConverter(String name, String style) { - super(name, style); - } - - public static TraceIdConverter newInstance(String[] options) { - return new TraceIdConverter("traceId", "traceId"); - } - - @Override - public void format(LogEvent event, StringBuilder toAppendTo) { - Log4j2OutputAppender.append(toAppendTo); - } -} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/pom.xml b/apm-application-toolkit/apm-toolkit-logback-1.x/pom.xml index 03db7fc664e1..f57673d33854 100644 --- a/apm-application-toolkit/apm-toolkit-logback-1.x/pom.xml +++ b/apm-application-toolkit/apm-toolkit-logback-1.x/pom.xml @@ -64,7 +64,7 @@ bintray-wu-sheng-sky-walking-repository wu-sheng-sky-walking-repository - https://api.bintray.com/maven/wu-sheng/skywalking/org.skywalking.apm-toolkit-logback-1.x/;publish=1 + https://api.bintray.com/maven/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-logback-1.x/;publish=1 diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java new file mode 100644 index 000000000000..cc2e242eda6e --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.logback.v1.x; + +import ch.qos.logback.classic.pattern.ClassicConverter; +import ch.qos.logback.classic.spi.ILoggingEvent; + +/** + * Created by wusheng on 2016/12/7. + */ +public class LogbackPatternConverter extends ClassicConverter { + /** + * As default, return "TID: N/A" to the output message, + * if sky-walking agent in active mode, return the real traceId in the recent Context, if existed. + * + * @param iLoggingEvent + * @return the traceId: N/A, empty String, or the real traceId. + */ + @Override + public String convert(ILoggingEvent iLoggingEvent) { + return "TID: N/A"; + } +} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java new file mode 100644 index 000000000000..419a390e2db7 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.logback.v1.x; + +import ch.qos.logback.classic.PatternLayout; + +/** + * Based on the logback-compoenent convert register mechanism, + * register {@link LogbackPatternConverter} as a new convert, match to "tid". + * You can use "%tid" in logback config file, "Pattern" section. + *

+ * Created by wusheng on 2016/12/7. + */ +public class TraceIdPatternLogbackLayout extends PatternLayout { + static { + defaultConverterMap.put("tid", LogbackPatternConverter.class.getName()); + } +} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java new file mode 100644 index 000000000000..e8680658c21d --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc; + +import ch.qos.logback.classic.pattern.MDCConverter; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.util.OptionHelper; + +/** + * @author zhangkewei + */ +public class LogbackMDCPatternConverter extends MDCConverter { + private static final String CONVERT_KEY = "tid"; + + private boolean convert4TID = false; + @Override + public void start() { + super.start(); + String[] key = OptionHelper.extractDefaultReplacement(getFirstOption()); + if (null != key && key.length > 0 && CONVERT_KEY.equals(key[0])) { + convert4TID = true; + } + } + @Override + public String convert(ILoggingEvent iLoggingEvent) { + return convert4TID ? convertTID() : super.convert(iLoggingEvent); + } + + public String convertTID() { + return "TID: N/A"; + } +} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java new file mode 100644 index 000000000000..d511c02e3f45 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/apache/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc; + +import ch.qos.logback.classic.PatternLayout; + +/** + * Override "X",SuperClass run before Subclass. + * @author zhangkewei + */ +public class TraceIdMDCPatternLogbackLayout extends PatternLayout { + static { + defaultConverterMap.put("X", LogbackMDCPatternConverter.class.getName()); + } +} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java deleted file mode 100644 index aaa493cf70f7..000000000000 --- a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/LogbackPatternConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.logback.v1.x; - -import ch.qos.logback.classic.pattern.ClassicConverter; -import ch.qos.logback.classic.spi.ILoggingEvent; - -/** - * Created by wusheng on 2016/12/7. - */ -public class LogbackPatternConverter extends ClassicConverter { - /** - * As default, return "TID: N/A" to the output message, - * if sky-walking agent in active mode, return the real traceId in the recent Context, if existed. - * - * @param iLoggingEvent - * @return the traceId: N/A, empty String, or the real traceId. - */ - @Override - public String convert(ILoggingEvent iLoggingEvent) { - return "TID: N/A"; - } -} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java deleted file mode 100644 index d7f9f93d8b47..000000000000 --- a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.logback.v1.x; - -import ch.qos.logback.classic.PatternLayout; - -/** - * Based on the logback-compoenent convert register mechanism, - * register {@link LogbackPatternConverter} as a new convert, match to "tid". - * You can use "%tid" in logback config file, "Pattern" section. - *

- * Created by wusheng on 2016/12/7. - */ -public class TraceIdPatternLogbackLayout extends PatternLayout { - static { - defaultConverterMap.put("tid", LogbackPatternConverter.class.getName()); - } -} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java deleted file mode 100644 index 0509d88c4e83..000000000000 --- a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/LogbackMDCPatternConverter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.logback.v1.x.mdc; - -import ch.qos.logback.classic.pattern.MDCConverter; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.util.OptionHelper; - -/** - * @author zhangkewei - */ -public class LogbackMDCPatternConverter extends MDCConverter { - private static final String CONVERT_KEY = "tid"; - - private boolean convert4TID = false; - @Override - public void start() { - super.start(); - String[] key = OptionHelper.extractDefaultReplacement(getFirstOption()); - if (null != key && key.length > 0 && CONVERT_KEY.equals(key[0])) { - convert4TID = true; - } - } - @Override - public String convert(ILoggingEvent iLoggingEvent) { - return convert4TID ? convertTID() : super.convert(iLoggingEvent); - } - - public String convertTID() { - return "TID: N/A"; - } -} diff --git a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java b/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java deleted file mode 100644 index 24df2484debf..000000000000 --- a/apm-application-toolkit/apm-toolkit-logback-1.x/src/main/java/org/skywalking/apm/toolkit/log/logback/v1/x/mdc/TraceIdMDCPatternLogbackLayout.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.log.logback.v1.x.mdc; - -import ch.qos.logback.classic.PatternLayout; - -/** - * Override "X",SuperClass run before Subclass. - * @author zhangkewei - */ -public class TraceIdMDCPatternLogbackLayout extends PatternLayout { - static { - defaultConverterMap.put("X", LogbackMDCPatternConverter.class.getName()); - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/pom.xml b/apm-application-toolkit/apm-toolkit-opentracing/pom.xml index 80304410dcaa..6c0756eb45ee 100644 --- a/apm-application-toolkit/apm-toolkit-opentracing/pom.xml +++ b/apm-application-toolkit/apm-toolkit-opentracing/pom.xml @@ -46,7 +46,7 @@ bintray-wu-sheng-sky-walking-repository wu-sheng-sky-walking-repository - https://api.bintray.com/maven/wu-sheng/skywalking/org.skywalking.apm-toolkit-opentracing/;publish=1 + https://api.bintray.com/maven/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-opentracing/;publish=1 diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/ByteBufferContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/ByteBufferContext.java new file mode 100644 index 000000000000..3c683de448d5 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/ByteBufferContext.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +import io.opentracing.SpanContext; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by wusheng on 2016/12/21. + */ +public class ByteBufferContext implements SpanContext { + static final Charset CHARSET = Charset.forName("UTF-8"); + + static final byte NO_ENTRY = 0; + static final byte ENTRY = 1; + + private final ByteBuffer byteBuffer; + + ByteBufferContext(ByteBuffer byteBuffer) { + this.byteBuffer = byteBuffer; + } + + @Override + public Iterable> baggageItems() { + return new HashMap().entrySet(); + } +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java new file mode 100644 index 000000000000..ace574e375bf --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The NeedSnifferActivation annotation is flag for reader and maintainers, + * which represents this method should be activated/intercepted in sniffer. + * + * @author wusheng + */ +@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) +@Retention(RetentionPolicy.SOURCE) +public @interface NeedSnifferActivation { + String value() default "What should interceptor do?"; +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java similarity index 79% rename from apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java rename to apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java index 18487bff5cb0..d44e33186e45 100644 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.toolkit.opentracing; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; import io.opentracing.ActiveSpan; import io.opentracing.SpanContext; diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContext.java new file mode 100644 index 000000000000..56ce3e919620 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContext.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +import io.opentracing.SpanContext; +import java.util.Map; + +/** + * Skywalking tracer context based on {@link ThreadLocal} auto mechanism. + * + * @author wusheng + */ +public class SkywalkingContext implements SpanContext { + public static final SkywalkingContext INSTANCE = new SkywalkingContext(); + + private SkywalkingContext() { + } + + @Override + public Iterable> baggageItems() { + return null; + } +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java new file mode 100644 index 000000000000..504f21532d8d --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +import io.opentracing.ActiveSpan; + +/** + * @author wusheng + */ +public class SkywalkingContinuation implements ActiveSpan.Continuation { + @NeedSnifferActivation("1. ContextManager#capture" + + "2. set ContextSnapshot to the dynamic field") + public SkywalkingContinuation() { + } + + @NeedSnifferActivation("1. get ContextSnapshot from the dynamic field" + + "2. ContextManager#continued") + @Override + public ActiveSpan activate() { + SkywalkingSpanBuilder builder = new SkywalkingSpanBuilder("Thread/" + Thread.currentThread().getName()); + return builder.startActive(); + } +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java similarity index 82% rename from apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java rename to apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java index 5e1b674af331..8114694994b9 100644 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.toolkit.opentracing; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; import io.opentracing.Span; import io.opentracing.SpanContext; diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java similarity index 86% rename from apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java rename to apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java index f5ad45da6df0..80dd0453cc43 100644 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.toolkit.opentracing; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; import io.opentracing.ActiveSpan; import io.opentracing.BaseSpan; diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java new file mode 100644 index 000000000000..a9a2cf059af7 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +import io.opentracing.ActiveSpan; +import io.opentracing.Span; +import io.opentracing.SpanContext; +import io.opentracing.Tracer; +import io.opentracing.propagation.Format; + +/** + * @author wusheng + */ +public class SkywalkingTracer implements Tracer { + + public SpanBuilder buildSpan(String operationName) { + return new SkywalkingSpanBuilder(operationName); + } + + @NeedSnifferActivation + @Override + public void inject(SpanContext spanContext, Format format, C carrier) { + + } + + @NeedSnifferActivation + @Override + public SpanContext extract(Format format, C carrier) { + return new TextMapContext(); + } + + @Override + public ActiveSpan activeSpan() { + return new SkywalkingActiveSpan(new SkywalkingSpan(this)); + } + + @Override + public ActiveSpan makeActive(Span span) { + if (span instanceof SkywalkingSpan) { + return new SkywalkingActiveSpan((SkywalkingSpan)span); + } else { + throw new IllegalArgumentException("span must be a type of SkywalkingSpan"); + } + } +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/Tag.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/Tag.java new file mode 100644 index 000000000000..b20c9dc5cbbb --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/Tag.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +/** + * @author wusheng + */ +public class Tag { + private String key; + private String value; + + public Tag(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/TextMapContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/TextMapContext.java new file mode 100644 index 000000000000..d6aed917ab17 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/apache/skywalking/apm/toolkit/opentracing/TextMapContext.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.opentracing; + +import io.opentracing.SpanContext; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by wusheng on 2016/12/21. + */ +public class TextMapContext implements SpanContext { + public TextMapContext() { + } + + @Override + public Iterable> baggageItems() { + return new HashMap(0).entrySet(); + } +} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/ByteBufferContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/ByteBufferContext.java deleted file mode 100644 index 120d0bfb3173..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/ByteBufferContext.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -import io.opentracing.SpanContext; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by wusheng on 2016/12/21. - */ -public class ByteBufferContext implements SpanContext { - static final Charset CHARSET = Charset.forName("UTF-8"); - - static final byte NO_ENTRY = 0; - static final byte ENTRY = 1; - - private final ByteBuffer byteBuffer; - - ByteBufferContext(ByteBuffer byteBuffer) { - this.byteBuffer = byteBuffer; - } - - @Override - public Iterable> baggageItems() { - return new HashMap().entrySet(); - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java deleted file mode 100644 index 28b73451e6fd..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/NeedSnifferActivation.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The NeedSnifferActivation annotation is flag for reader and maintainers, - * which represents this method should be activated/intercepted in sniffer. - * - * @author wusheng - */ -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@Retention(RetentionPolicy.SOURCE) -public @interface NeedSnifferActivation { - String value() default "What should interceptor do?"; -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java deleted file mode 100644 index a17d2a4d4278..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -import io.opentracing.SpanContext; -import java.util.Map; - -/** - * Skywalking tracer context based on {@link ThreadLocal} auto mechanism. - * - * @author wusheng - */ -public class SkywalkingContext implements SpanContext { - public static final SkywalkingContext INSTANCE = new SkywalkingContext(); - - private SkywalkingContext() { - } - - @Override - public Iterable> baggageItems() { - return null; - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java deleted file mode 100644 index 6fa24c253194..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -import io.opentracing.ActiveSpan; - -/** - * @author wusheng - */ -public class SkywalkingContinuation implements ActiveSpan.Continuation { - @NeedSnifferActivation("1. ContextManager#capture" + - "2. set ContextSnapshot to the dynamic field") - public SkywalkingContinuation() { - } - - @NeedSnifferActivation("1. get ContextSnapshot from the dynamic field" + - "2. ContextManager#continued") - @Override - public ActiveSpan activate() { - SkywalkingSpanBuilder builder = new SkywalkingSpanBuilder("Thread/" + Thread.currentThread().getName()); - return builder.startActive(); - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java deleted file mode 100644 index e50b646eaba5..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -import io.opentracing.ActiveSpan; -import io.opentracing.Span; -import io.opentracing.SpanContext; -import io.opentracing.Tracer; -import io.opentracing.propagation.Format; - -/** - * @author wusheng - */ -public class SkywalkingTracer implements Tracer { - - public SpanBuilder buildSpan(String operationName) { - return new SkywalkingSpanBuilder(operationName); - } - - @NeedSnifferActivation - @Override - public void inject(SpanContext spanContext, Format format, C carrier) { - - } - - @NeedSnifferActivation - @Override - public SpanContext extract(Format format, C carrier) { - return new TextMapContext(); - } - - @Override - public ActiveSpan activeSpan() { - return new SkywalkingActiveSpan(new SkywalkingSpan(this)); - } - - @Override - public ActiveSpan makeActive(Span span) { - if (span instanceof SkywalkingSpan) { - return new SkywalkingActiveSpan((SkywalkingSpan)span); - } else { - throw new IllegalArgumentException("span must be a type of SkywalkingSpan"); - } - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java deleted file mode 100644 index 4223f67461e4..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -/** - * @author wusheng - */ -public class Tag { - private String key; - private String value; - - public Tag(String key, String value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public String getValue() { - return value; - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/TextMapContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/TextMapContext.java deleted file mode 100644 index 2d5017a41422..000000000000 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/TextMapContext.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.opentracing; - -import io.opentracing.SpanContext; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by wusheng on 2016/12/21. - */ -public class TextMapContext implements SpanContext { - public TextMapContext() { - } - - @Override - public Iterable> baggageItems() { - return new HashMap(0).entrySet(); - } -} diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer b/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer index 980fb4a6c329..6184cc8bdb51 100644 --- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer +++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer @@ -1 +1 @@ -org.skywalking.apm.toolkit.opentracing.SkyWalkingTracer +org.apache.skywalking.apm.toolkit.opentracing.SkyWalkingTracer diff --git a/apm-application-toolkit/apm-toolkit-trace/pom.xml b/apm-application-toolkit/apm-toolkit-trace/pom.xml index d6a0073cbc2c..ee3301606a54 100644 --- a/apm-application-toolkit/apm-toolkit-trace/pom.xml +++ b/apm-application-toolkit/apm-toolkit-trace/pom.xml @@ -57,7 +57,7 @@ bintray-wu-sheng-sky-walking-repository wu-sheng-sky-walking-repository - https://api.bintray.com/maven/wu-sheng/skywalking/org.skywalking.apm-toolkit-trace/;publish=1 + https://api.bintray.com/maven/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-trace/;publish=1 diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java new file mode 100644 index 000000000000..6e60531eb9b5 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; + +/** + * provide custom api that set tag for current active span. + * + * @author zhangxin + */ +public class ActiveSpan { + /** + * @param key tag key + * @param value tag value + */ + public static void tag(String key, String value) { + + } +} diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/Trace.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/Trace.java new file mode 100644 index 000000000000..05026e07df30 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/Trace.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The agent create local span if the method that annotation with {@link Trace}. The value of span operation name will + * fetch by {@link #operationName()}. if the value of {@link #operationName()} is blank string. the operation name will + * be set the class name + method name. + * + * @author zhangxin + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Trace { + /** + * @return operation name, the default value is blank string. + */ + String operationName() default ""; +} diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceContext.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceContext.java new file mode 100644 index 000000000000..acea9205d9c0 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceContext.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; + +/** + * Try to access the sky-walking tracer context. + * The context is not existed, always. + * only the middleware, component, or rpc-framework are supported in the current invoke stack, in the same thread, + * the context will be available. + *

+ * Created by xin on 2016/12/15. + */ +public class TraceContext { + + /** + * Try to get the traceId of current trace context. + * + * @return traceId, if it exists, or empty {@link String}. + */ + public static String traceId() { + return ""; + } +} diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/ActiveSpan.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/ActiveSpan.java deleted file mode 100644 index 90649320d665..000000000000 --- a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/ActiveSpan.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.trace; - -/** - * provide custom api that set tag for current active span. - * - * @author zhangxin - */ -public class ActiveSpan { - /** - * @param key tag key - * @param value tag value - */ - public static void tag(String key, String value) { - - } -} diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/Trace.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/Trace.java deleted file mode 100644 index 7d13a05a1b62..000000000000 --- a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/Trace.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.trace; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The agent create local span if the method that annotation with {@link Trace}. The value of span operation name will - * fetch by {@link #operationName()}. if the value of {@link #operationName()} is blank string. the operation name will - * be set the class name + method name. - * - * @author zhangxin - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Trace { - /** - * @return operation name, the default value is blank string. - */ - String operationName() default ""; -} diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/TraceContext.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/TraceContext.java deleted file mode 100644 index 83d326c7f16e..000000000000 --- a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/skywalking/apm/toolkit/trace/TraceContext.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.trace; - -/** - * Try to access the sky-walking tracer context. - * The context is not existed, always. - * only the middleware, component, or rpc-framework are supported in the current invoke stack, in the same thread, - * the context will be available. - *

- * Created by xin on 2016/12/15. - */ -public class TraceContext { - - /** - * Try to get the traceId of current trace context. - * - * @return traceId, if it exists, or empty {@link String}. - */ - public static String traceId() { - return ""; - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java new file mode 100644 index 000000000000..6c7d4cd8bbe7 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc; + +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class AgentGRPCModule extends Module { + + public static final String NAME = "agent_gRPC"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[0]; + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java deleted file mode 100644 index 89f99eeadeff..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentGRPCModule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc; - -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class AgentGRPCModule extends Module { - - public static final String NAME = "agent_gRPC"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[0]; - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..ec8255a67218 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.agent.grpc.AgentGRPCModule diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 437a0a72a1f6..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.agent.grpc.AgentGRPCModule diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java new file mode 100644 index 000000000000..2ee7da4685d9 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.agent.grpc.handler.naming.AgentGRPCNamingListener; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.naming.NamingModule; +import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; +import org.apache.skywalking.apm.collector.agent.grpc.handler.ApplicationRegisterServiceHandler; +import org.apache.skywalking.apm.collector.agent.grpc.handler.InstanceDiscoveryServiceHandler; +import org.apache.skywalking.apm.collector.agent.grpc.handler.JVMMetricsServiceHandler; +import org.apache.skywalking.apm.collector.agent.grpc.handler.ServiceNameDiscoveryServiceHandler; +import org.apache.skywalking.apm.collector.agent.grpc.handler.TraceSegmentServiceHandler; +import org.apache.skywalking.apm.collector.agent.grpc.handler.naming.AgentGRPCNamingHandler; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.grpc.manager.GRPCManagerModule; +import org.apache.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; +import org.apache.skywalking.apm.collector.server.Server; + +/** + * @author peng-yongsheng + */ +public class AgentModuleGRPCProvider extends ModuleProvider { + + public static final String NAME = "gRPC"; + private static final String HOST = "host"; + private static final String PORT = "port"; + + @Override public String name() { + return NAME; + } + + @Override public Class module() { + return AgentGRPCModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + String host = config.getProperty(HOST); + Integer port = (Integer)config.get(PORT); + + ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); + moduleRegisterService.register(AgentGRPCModule.NAME, this.name(), new AgentModuleGRPCRegistration(host, port)); + + AgentGRPCNamingListener namingListener = new AgentGRPCNamingListener(); + ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); + moduleListenerService.addListener(namingListener); + + NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class); + namingHandlerRegisterService.register(new AgentGRPCNamingHandler(namingListener)); + + GRPCManagerService managerService = getManager().find(GRPCManagerModule.NAME).getService(GRPCManagerService.class); + Server gRPCServer = managerService.createIfAbsent(host, port); + + addHandlers(gRPCServer); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {ClusterModule.NAME, NamingModule.NAME, GRPCManagerModule.NAME, AgentStreamModule.NAME}; + } + + private void addHandlers(Server gRPCServer) { + gRPCServer.addHandler(new ApplicationRegisterServiceHandler(getManager())); + gRPCServer.addHandler(new InstanceDiscoveryServiceHandler(getManager())); + gRPCServer.addHandler(new ServiceNameDiscoveryServiceHandler(getManager())); + gRPCServer.addHandler(new JVMMetricsServiceHandler(getManager())); + gRPCServer.addHandler(new TraceSegmentServiceHandler(getManager())); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java new file mode 100644 index 000000000000..557e11728830 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc; + +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; +import org.apache.skywalking.apm.collector.core.util.Const; + +/** + * @author peng-yongsheng + */ +public class AgentModuleGRPCRegistration extends ModuleRegistration { + + private final String host; + private final int port; + + public AgentModuleGRPCRegistration(String host, int port) { + this.host = host; + this.port = port; + } + + @Override public Value buildValue() { + return new Value(host, port, Const.EMPTY_STRING); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java new file mode 100644 index 000000000000..56ebf4e94267 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler; + +import com.google.protobuf.ProtocolStringList; +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; +import org.apache.skywalking.apm.network.proto.Application; +import org.apache.skywalking.apm.network.proto.ApplicationMapping; +import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; +import org.apache.skywalking.apm.network.proto.KeyWithIntegerValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationRegisterServiceHandler extends ApplicationRegisterServiceGrpc.ApplicationRegisterServiceImplBase implements GRPCHandler { + + private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServiceHandler.class); + + private final IApplicationIDService applicationIDService; + + public ApplicationRegisterServiceHandler(ModuleManager moduleManager) { + applicationIDService = moduleManager.find(AgentStreamModule.NAME).getService(IApplicationIDService.class); + } + + @Override public void register(Application request, StreamObserver responseObserver) { + logger.debug("register application"); + ProtocolStringList applicationCodes = request.getApplicationCodeList(); + + ApplicationMapping.Builder builder = ApplicationMapping.newBuilder(); + for (int i = 0; i < applicationCodes.size(); i++) { + String applicationCode = applicationCodes.get(i); + int applicationId = applicationIDService.getOrCreate(applicationCode); + + if (applicationId != 0) { + KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId).build(); + builder.addApplication(value); + } + } + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java new file mode 100644 index 000000000000..98c68b5b2e60 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; +import org.apache.skywalking.apm.network.proto.ApplicationInstance; +import org.apache.skywalking.apm.network.proto.ApplicationInstanceMapping; +import org.apache.skywalking.apm.network.proto.ApplicationInstanceRecover; +import org.apache.skywalking.apm.network.proto.Downstream; +import org.apache.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc; +import org.apache.skywalking.apm.network.proto.OSInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceImplBase implements GRPCHandler { + + private final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServiceHandler.class); + + private final IInstanceIDService instanceIDService; + + public InstanceDiscoveryServiceHandler(ModuleManager moduleManager) { + this.instanceIDService = moduleManager.find(AgentStreamModule.NAME).getService(IInstanceIDService.class); + } + + @Override + public void register(ApplicationInstance request, StreamObserver responseObserver) { + long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(request.getRegisterTime()); + int instanceId = instanceIDService.getOrCreate(request.getApplicationId(), request.getAgentUUID(), timeBucket, buildOsInfo(request.getOsinfo())); + ApplicationInstanceMapping.Builder builder = ApplicationInstanceMapping.newBuilder(); + builder.setApplicationId(request.getApplicationId()); + builder.setApplicationInstanceId(instanceId); + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } + + @Override + public void registerRecover(ApplicationInstanceRecover request, StreamObserver responseObserver) { + long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(request.getRegisterTime()); + instanceIDService.recover(request.getApplicationInstanceId(), request.getApplicationId(), timeBucket, buildOsInfo(request.getOsinfo())); + responseObserver.onNext(Downstream.newBuilder().build()); + responseObserver.onCompleted(); + } + + private String buildOsInfo(OSInfo osinfo) { + JsonObject osInfoJson = new JsonObject(); + osInfoJson.addProperty("osName", osinfo.getOsName()); + osInfoJson.addProperty("hostName", osinfo.getHostname()); + osInfoJson.addProperty("processId", osinfo.getProcessNo()); + + JsonArray ipv4Array = new JsonArray(); + for (String ipv4 : osinfo.getIpv4SList()) { + ipv4Array.add(ipv4); + } + osInfoJson.add("ipv4s", ipv4Array); + return osInfoJson.toString(); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java new file mode 100644 index 000000000000..a557f39e7bc9 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler; + +import io.grpc.stub.StreamObserver; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; +import org.apache.skywalking.apm.network.proto.CPU; +import org.apache.skywalking.apm.network.proto.Downstream; +import org.apache.skywalking.apm.network.proto.GC; +import org.apache.skywalking.apm.network.proto.JVMMetrics; +import org.apache.skywalking.apm.network.proto.JVMMetricsServiceGrpc; +import org.apache.skywalking.apm.network.proto.Memory; +import org.apache.skywalking.apm.network.proto.MemoryPool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsServiceImplBase implements GRPCHandler { + + private final Logger logger = LoggerFactory.getLogger(JVMMetricsServiceHandler.class); + + private final ICpuMetricService cpuMetricService; + private final IGCMetricService gcMetricService; + private final IMemoryMetricService memoryMetricService; + private final IMemoryPoolMetricService memoryPoolMetricService; + private final IInstanceHeartBeatService instanceHeartBeatService; + + public JVMMetricsServiceHandler(ModuleManager moduleManager) { + this.cpuMetricService = moduleManager.find(AgentStreamModule.NAME).getService(ICpuMetricService.class); + this.gcMetricService = moduleManager.find(AgentStreamModule.NAME).getService(IGCMetricService.class); + this.memoryMetricService = moduleManager.find(AgentStreamModule.NAME).getService(IMemoryMetricService.class); + this.memoryPoolMetricService = moduleManager.find(AgentStreamModule.NAME).getService(IMemoryPoolMetricService.class); + this.instanceHeartBeatService = moduleManager.find(AgentStreamModule.NAME).getService(IInstanceHeartBeatService.class); + } + + @Override public void collect(JVMMetrics request, StreamObserver responseObserver) { + int instanceId = request.getApplicationInstanceId(); + logger.debug("receive the jvm metric from application instance, id: {}", instanceId); + + request.getMetricsList().forEach(metric -> { + long time = TimeBucketUtils.INSTANCE.getSecondTimeBucket(metric.getTime()); + sendToInstanceHeartBeatService(instanceId, metric.getTime()); + sendToCpuMetricService(instanceId, time, metric.getCpu()); + sendToMemoryMetricService(instanceId, time, metric.getMemoryList()); + sendToMemoryPoolMetricService(instanceId, time, metric.getMemoryPoolList()); + sendToGCMetricService(instanceId, time, metric.getGcList()); + }); + + responseObserver.onNext(Downstream.newBuilder().build()); + responseObserver.onCompleted(); + } + + private void sendToInstanceHeartBeatService(int instanceId, long heartBeatTime) { + instanceHeartBeatService.send(instanceId, heartBeatTime); + } + + private void sendToMemoryMetricService(int instanceId, long timeBucket, List memories) { + memories.forEach(memory -> memoryMetricService.send(instanceId, timeBucket, memory.getIsHeap(), memory.getInit(), memory.getMax(), memory.getUsed(), memory.getCommitted())); + } + + private void sendToMemoryPoolMetricService(int instanceId, long timeBucket, + List memoryPools) { + + memoryPools.forEach(memoryPool -> memoryPoolMetricService.send(instanceId, timeBucket, memoryPool.getType().getNumber(), memoryPool.getInit(), memoryPool.getMax(), memoryPool.getUsed(), memoryPool.getCommited())); + } + + private void sendToCpuMetricService(int instanceId, long timeBucket, CPU cpu) { + cpuMetricService.send(instanceId, timeBucket, cpu.getUsagePercent()); + } + + private void sendToGCMetricService(int instanceId, long timeBucket, List gcs) { + gcs.forEach(gc -> gcMetricService.send(instanceId, timeBucket, gc.getPhraseValue(), gc.getCount(), gc.getTime())); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java new file mode 100644 index 000000000000..ea10e8eb9e75 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler; + +import io.grpc.stub.StreamObserver; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; +import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; +import org.apache.skywalking.apm.network.proto.ServiceNameCollection; +import org.apache.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; +import org.apache.skywalking.apm.network.proto.ServiceNameElement; +import org.apache.skywalking.apm.network.proto.ServiceNameMappingCollection; +import org.apache.skywalking.apm.network.proto.ServiceNameMappingElement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameDiscoveryServiceHandler extends ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceImplBase implements GRPCHandler { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameDiscoveryServiceHandler.class); + + private final IServiceNameService serviceNameService; + + public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) { + this.serviceNameService = moduleManager.find(AgentStreamModule.NAME).getService(IServiceNameService.class); + } + + @Override public void discovery(ServiceNameCollection request, + StreamObserver responseObserver) { + List serviceNameElementList = request.getElementsList(); + + ServiceNameMappingCollection.Builder builder = ServiceNameMappingCollection.newBuilder(); + for (ServiceNameElement serviceNameElement : serviceNameElementList) { + int applicationId = serviceNameElement.getApplicationId(); + String serviceName = serviceNameElement.getServiceName(); + int serviceId = serviceNameService.getOrCreate(applicationId, serviceName); + + if (serviceId != 0) { + ServiceNameMappingElement.Builder mappingElement = ServiceNameMappingElement.newBuilder(); + mappingElement.setServiceId(serviceId); + mappingElement.setElement(serviceNameElement); + builder.addElements(mappingElement); + } + } + + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java new file mode 100644 index 000000000000..cde136e2554f --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; +import org.apache.skywalking.apm.network.proto.Downstream; +import org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TraceSegmentServiceHandler extends TraceSegmentServiceGrpc.TraceSegmentServiceImplBase implements GRPCHandler { + + private final Logger logger = LoggerFactory.getLogger(TraceSegmentServiceHandler.class); + + private final ITraceSegmentService traceSegmentService; + + public TraceSegmentServiceHandler(ModuleManager moduleManager) { + this.traceSegmentService = moduleManager.find(AgentStreamModule.NAME).getService(ITraceSegmentService.class); + } + + @Override public StreamObserver collect(StreamObserver responseObserver) { + return new StreamObserver() { + @Override public void onNext(UpstreamSegment segment) { + logger.debug("receive segment"); + traceSegmentService.send(segment); + } + + @Override public void onError(Throwable throwable) { + logger.error(throwable.getMessage(), throwable); + } + + @Override public void onCompleted() { + responseObserver.onNext(Downstream.newBuilder().build()); + responseObserver.onCompleted(); + } + }; + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java new file mode 100644 index 000000000000..387589ca0fee --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler.naming; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import java.util.Set; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; + +/** + * @author peng-yongsheng + */ +public class AgentGRPCNamingHandler extends JettyHandler { + + private final AgentGRPCNamingListener namingListener; + + public AgentGRPCNamingHandler(AgentGRPCNamingListener namingListener) { + this.namingListener = namingListener; + } + + @Override public String pathSpec() { + return "/agent/gRPC"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + Set servers = namingListener.getAddresses(); + JsonArray serverArray = new JsonArray(); + servers.forEach(serverArray::add); + return serverArray; + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java new file mode 100644 index 000000000000..707f1ee99a3f --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler.naming; + +import org.apache.skywalking.apm.collector.agent.grpc.AgentGRPCModule; +import org.apache.skywalking.apm.collector.agent.grpc.AgentModuleGRPCProvider; +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; + +/** + * @author peng-yongsheng + */ +public class AgentGRPCNamingListener extends ClusterModuleListener { + + public static final String PATH = "/" + AgentGRPCModule.NAME + "/" + AgentModuleGRPCProvider.NAME; + + @Override public String path() { + return PATH; + } + + @Override public void serverJoinNotify(String serverAddress) { + + } + + @Override public void serverQuitNotify(String serverAddress) { + + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java deleted file mode 100644 index 56fd97935250..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc; - -import java.util.Properties; -import org.skywalking.apm.collector.agent.grpc.handler.ApplicationRegisterServiceHandler; -import org.skywalking.apm.collector.agent.grpc.handler.InstanceDiscoveryServiceHandler; -import org.skywalking.apm.collector.agent.grpc.handler.JVMMetricsServiceHandler; -import org.skywalking.apm.collector.agent.grpc.handler.ServiceNameDiscoveryServiceHandler; -import org.skywalking.apm.collector.agent.grpc.handler.TraceSegmentServiceHandler; -import org.skywalking.apm.collector.agent.grpc.handler.naming.AgentGRPCNamingHandler; -import org.skywalking.apm.collector.agent.grpc.handler.naming.AgentGRPCNamingListener; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.grpc.manager.GRPCManagerModule; -import org.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; -import org.skywalking.apm.collector.naming.NamingModule; -import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; -import org.skywalking.apm.collector.server.Server; - -/** - * @author peng-yongsheng - */ -public class AgentModuleGRPCProvider extends ModuleProvider { - - public static final String NAME = "gRPC"; - private static final String HOST = "host"; - private static final String PORT = "port"; - - @Override public String name() { - return NAME; - } - - @Override public Class module() { - return AgentGRPCModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - String host = config.getProperty(HOST); - Integer port = (Integer)config.get(PORT); - - ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); - moduleRegisterService.register(AgentGRPCModule.NAME, this.name(), new AgentModuleGRPCRegistration(host, port)); - - AgentGRPCNamingListener namingListener = new AgentGRPCNamingListener(); - ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); - moduleListenerService.addListener(namingListener); - - NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class); - namingHandlerRegisterService.register(new AgentGRPCNamingHandler(namingListener)); - - GRPCManagerService managerService = getManager().find(GRPCManagerModule.NAME).getService(GRPCManagerService.class); - Server gRPCServer = managerService.createIfAbsent(host, port); - - addHandlers(gRPCServer); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {ClusterModule.NAME, NamingModule.NAME, GRPCManagerModule.NAME, AgentStreamModule.NAME}; - } - - private void addHandlers(Server gRPCServer) { - gRPCServer.addHandler(new ApplicationRegisterServiceHandler(getManager())); - gRPCServer.addHandler(new InstanceDiscoveryServiceHandler(getManager())); - gRPCServer.addHandler(new ServiceNameDiscoveryServiceHandler(getManager())); - gRPCServer.addHandler(new JVMMetricsServiceHandler(getManager())); - gRPCServer.addHandler(new TraceSegmentServiceHandler(getManager())); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java deleted file mode 100644 index 3f1d7bd473e7..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/AgentModuleGRPCRegistration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.core.util.Const; - -/** - * @author peng-yongsheng - */ -public class AgentModuleGRPCRegistration extends ModuleRegistration { - - private final String host; - private final int port; - - public AgentModuleGRPCRegistration(String host, int port) { - this.host = host; - this.port = port; - } - - @Override public Value buildValue() { - return new Value(host, port, Const.EMPTY_STRING); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java deleted file mode 100644 index ef33835ab516..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler; - -import com.google.protobuf.ProtocolStringList; -import io.grpc.stub.StreamObserver; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.grpc.GRPCHandler; -import org.skywalking.apm.network.proto.Application; -import org.skywalking.apm.network.proto.ApplicationMapping; -import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.skywalking.apm.network.proto.KeyWithIntegerValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationRegisterServiceHandler extends ApplicationRegisterServiceGrpc.ApplicationRegisterServiceImplBase implements GRPCHandler { - - private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServiceHandler.class); - - private final IApplicationIDService applicationIDService; - - public ApplicationRegisterServiceHandler(ModuleManager moduleManager) { - applicationIDService = moduleManager.find(AgentStreamModule.NAME).getService(IApplicationIDService.class); - } - - @Override public void register(Application request, StreamObserver responseObserver) { - logger.debug("register application"); - ProtocolStringList applicationCodes = request.getApplicationCodeList(); - - ApplicationMapping.Builder builder = ApplicationMapping.newBuilder(); - for (int i = 0; i < applicationCodes.size(); i++) { - String applicationCode = applicationCodes.get(i); - int applicationId = applicationIDService.getOrCreate(applicationCode); - - if (applicationId != 0) { - KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId).build(); - builder.addApplication(value); - } - } - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java deleted file mode 100644 index 6aab67ac53cd..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/InstanceDiscoveryServiceHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import io.grpc.stub.StreamObserver; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.server.grpc.GRPCHandler; -import org.skywalking.apm.network.proto.ApplicationInstance; -import org.skywalking.apm.network.proto.ApplicationInstanceMapping; -import org.skywalking.apm.network.proto.ApplicationInstanceRecover; -import org.skywalking.apm.network.proto.Downstream; -import org.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc; -import org.skywalking.apm.network.proto.OSInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceImplBase implements GRPCHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServiceHandler.class); - - private final IInstanceIDService instanceIDService; - - public InstanceDiscoveryServiceHandler(ModuleManager moduleManager) { - this.instanceIDService = moduleManager.find(AgentStreamModule.NAME).getService(IInstanceIDService.class); - } - - @Override - public void register(ApplicationInstance request, StreamObserver responseObserver) { - long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(request.getRegisterTime()); - int instanceId = instanceIDService.getOrCreate(request.getApplicationId(), request.getAgentUUID(), timeBucket, buildOsInfo(request.getOsinfo())); - ApplicationInstanceMapping.Builder builder = ApplicationInstanceMapping.newBuilder(); - builder.setApplicationId(request.getApplicationId()); - builder.setApplicationInstanceId(instanceId); - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } - - @Override - public void registerRecover(ApplicationInstanceRecover request, StreamObserver responseObserver) { - long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(request.getRegisterTime()); - instanceIDService.recover(request.getApplicationInstanceId(), request.getApplicationId(), timeBucket, buildOsInfo(request.getOsinfo())); - responseObserver.onNext(Downstream.newBuilder().build()); - responseObserver.onCompleted(); - } - - private String buildOsInfo(OSInfo osinfo) { - JsonObject osInfoJson = new JsonObject(); - osInfoJson.addProperty("osName", osinfo.getOsName()); - osInfoJson.addProperty("hostName", osinfo.getHostname()); - osInfoJson.addProperty("processId", osinfo.getProcessNo()); - - JsonArray ipv4Array = new JsonArray(); - for (String ipv4 : osinfo.getIpv4SList()) { - ipv4Array.add(ipv4); - } - osInfoJson.add("ipv4s", ipv4Array); - return osInfoJson.toString(); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java deleted file mode 100644 index c5b84d09c485..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/JVMMetricsServiceHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler; - -import io.grpc.stub.StreamObserver; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.server.grpc.GRPCHandler; -import org.skywalking.apm.network.proto.CPU; -import org.skywalking.apm.network.proto.Downstream; -import org.skywalking.apm.network.proto.GC; -import org.skywalking.apm.network.proto.JVMMetrics; -import org.skywalking.apm.network.proto.JVMMetricsServiceGrpc; -import org.skywalking.apm.network.proto.Memory; -import org.skywalking.apm.network.proto.MemoryPool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsServiceImplBase implements GRPCHandler { - - private final Logger logger = LoggerFactory.getLogger(JVMMetricsServiceHandler.class); - - private final ICpuMetricService cpuMetricService; - private final IGCMetricService gcMetricService; - private final IMemoryMetricService memoryMetricService; - private final IMemoryPoolMetricService memoryPoolMetricService; - private final IInstanceHeartBeatService instanceHeartBeatService; - - public JVMMetricsServiceHandler(ModuleManager moduleManager) { - this.cpuMetricService = moduleManager.find(AgentStreamModule.NAME).getService(ICpuMetricService.class); - this.gcMetricService = moduleManager.find(AgentStreamModule.NAME).getService(IGCMetricService.class); - this.memoryMetricService = moduleManager.find(AgentStreamModule.NAME).getService(IMemoryMetricService.class); - this.memoryPoolMetricService = moduleManager.find(AgentStreamModule.NAME).getService(IMemoryPoolMetricService.class); - this.instanceHeartBeatService = moduleManager.find(AgentStreamModule.NAME).getService(IInstanceHeartBeatService.class); - } - - @Override public void collect(JVMMetrics request, StreamObserver responseObserver) { - int instanceId = request.getApplicationInstanceId(); - logger.debug("receive the jvm metric from application instance, id: {}", instanceId); - - request.getMetricsList().forEach(metric -> { - long time = TimeBucketUtils.INSTANCE.getSecondTimeBucket(metric.getTime()); - sendToInstanceHeartBeatService(instanceId, metric.getTime()); - sendToCpuMetricService(instanceId, time, metric.getCpu()); - sendToMemoryMetricService(instanceId, time, metric.getMemoryList()); - sendToMemoryPoolMetricService(instanceId, time, metric.getMemoryPoolList()); - sendToGCMetricService(instanceId, time, metric.getGcList()); - }); - - responseObserver.onNext(Downstream.newBuilder().build()); - responseObserver.onCompleted(); - } - - private void sendToInstanceHeartBeatService(int instanceId, long heartBeatTime) { - instanceHeartBeatService.send(instanceId, heartBeatTime); - } - - private void sendToMemoryMetricService(int instanceId, long timeBucket, List memories) { - memories.forEach(memory -> memoryMetricService.send(instanceId, timeBucket, memory.getIsHeap(), memory.getInit(), memory.getMax(), memory.getUsed(), memory.getCommitted())); - } - - private void sendToMemoryPoolMetricService(int instanceId, long timeBucket, - List memoryPools) { - - memoryPools.forEach(memoryPool -> memoryPoolMetricService.send(instanceId, timeBucket, memoryPool.getType().getNumber(), memoryPool.getInit(), memoryPool.getMax(), memoryPool.getUsed(), memoryPool.getCommited())); - } - - private void sendToCpuMetricService(int instanceId, long timeBucket, CPU cpu) { - cpuMetricService.send(instanceId, timeBucket, cpu.getUsagePercent()); - } - - private void sendToGCMetricService(int instanceId, long timeBucket, List gcs) { - gcs.forEach(gc -> gcMetricService.send(instanceId, timeBucket, gc.getPhraseValue(), gc.getCount(), gc.getTime())); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java deleted file mode 100644 index c77bab9ccb63..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/ServiceNameDiscoveryServiceHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler; - -import io.grpc.stub.StreamObserver; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.grpc.GRPCHandler; -import org.skywalking.apm.network.proto.ServiceNameCollection; -import org.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; -import org.skywalking.apm.network.proto.ServiceNameElement; -import org.skywalking.apm.network.proto.ServiceNameMappingCollection; -import org.skywalking.apm.network.proto.ServiceNameMappingElement; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameDiscoveryServiceHandler extends ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceImplBase implements GRPCHandler { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameDiscoveryServiceHandler.class); - - private final IServiceNameService serviceNameService; - - public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) { - this.serviceNameService = moduleManager.find(AgentStreamModule.NAME).getService(IServiceNameService.class); - } - - @Override public void discovery(ServiceNameCollection request, - StreamObserver responseObserver) { - List serviceNameElementList = request.getElementsList(); - - ServiceNameMappingCollection.Builder builder = ServiceNameMappingCollection.newBuilder(); - for (ServiceNameElement serviceNameElement : serviceNameElementList) { - int applicationId = serviceNameElement.getApplicationId(); - String serviceName = serviceNameElement.getServiceName(); - int serviceId = serviceNameService.getOrCreate(applicationId, serviceName); - - if (serviceId != 0) { - ServiceNameMappingElement.Builder mappingElement = ServiceNameMappingElement.newBuilder(); - mappingElement.setServiceId(serviceId); - mappingElement.setElement(serviceNameElement); - builder.addElements(mappingElement); - } - } - - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java deleted file mode 100644 index a52500e58359..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/TraceSegmentServiceHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler; - -import io.grpc.stub.StreamObserver; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.grpc.GRPCHandler; -import org.skywalking.apm.network.proto.Downstream; -import org.skywalking.apm.network.proto.TraceSegmentServiceGrpc; -import org.skywalking.apm.network.proto.UpstreamSegment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceSegmentServiceHandler extends TraceSegmentServiceGrpc.TraceSegmentServiceImplBase implements GRPCHandler { - - private final Logger logger = LoggerFactory.getLogger(TraceSegmentServiceHandler.class); - - private final ITraceSegmentService traceSegmentService; - - public TraceSegmentServiceHandler(ModuleManager moduleManager) { - this.traceSegmentService = moduleManager.find(AgentStreamModule.NAME).getService(ITraceSegmentService.class); - } - - @Override public StreamObserver collect(StreamObserver responseObserver) { - return new StreamObserver() { - @Override public void onNext(UpstreamSegment segment) { - logger.debug("receive segment"); - traceSegmentService.send(segment); - } - - @Override public void onError(Throwable throwable) { - logger.error(throwable.getMessage(), throwable); - } - - @Override public void onCompleted() { - responseObserver.onNext(Downstream.newBuilder().build()); - responseObserver.onCompleted(); - } - }; - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java deleted file mode 100644 index f908383d1389..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler.naming; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; - -/** - * @author peng-yongsheng - */ -public class AgentGRPCNamingHandler extends JettyHandler { - - private final AgentGRPCNamingListener namingListener; - - public AgentGRPCNamingHandler(AgentGRPCNamingListener namingListener) { - this.namingListener = namingListener; - } - - @Override public String pathSpec() { - return "/agent/gRPC"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - Set servers = namingListener.getAddresses(); - JsonArray serverArray = new JsonArray(); - servers.forEach(serverArray::add); - return serverArray; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java deleted file mode 100644 index ab81473856ec..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/java/org/skywalking/apm/collector/agent/grpc/handler/naming/AgentGRPCNamingListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler.naming; - -import org.skywalking.apm.collector.agent.grpc.AgentGRPCModule; -import org.skywalking.apm.collector.agent.grpc.AgentModuleGRPCProvider; -import org.skywalking.apm.collector.cluster.ClusterModuleListener; - -/** - * @author peng-yongsheng - */ -public class AgentGRPCNamingListener extends ClusterModuleListener { - - public static final String PATH = "/" + AgentGRPCModule.NAME + "/" + AgentModuleGRPCProvider.NAME; - - @Override public String path() { - return PATH; - } - - @Override public void serverJoinNotify(String serverAddress) { - - } - - @Override public void serverQuitNotify(String serverAddress) { - - } -} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..4eb9a529c054 --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.agent.grpc.AgentModuleGRPCProvider diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 74fd6fb06262..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.agent.grpc.AgentModuleGRPCProvider diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java new file mode 100644 index 000000000000..e56e174d3b6d --- /dev/null +++ b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.grpc.handler; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import org.apache.skywalking.apm.network.proto.Application; +import org.apache.skywalking.apm.network.proto.ApplicationMapping; +import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationRegisterServiceHandlerTestCase { + + private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServiceHandlerTestCase.class); + + private ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub stub; + + public void testRegister() { + ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build(); + stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel); + + Application application = Application.newBuilder().addApplicationCode("test141").build(); + ApplicationMapping mapping = stub.register(application); + logger.debug(mapping.getApplication(0).getKey() + ", " + mapping.getApplication(0).getValue()); + } +} diff --git a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java b/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java deleted file mode 100644 index 1f19b59cb1b6..000000000000 --- a/apm-collector/apm-collector-agent-grpc/collector-agent-grpc-provider/src/test/java/org/skywalking/apm/collector/agent/grpc/handler/ApplicationRegisterServiceHandlerTestCase.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.grpc.handler; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import org.skywalking.apm.network.proto.Application; -import org.skywalking.apm.network.proto.ApplicationMapping; -import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationRegisterServiceHandlerTestCase { - - private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServiceHandlerTestCase.class); - - private ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub stub; - - public void testRegister() { - ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build(); - stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel); - - Application application = Application.newBuilder().addApplicationCode("test141").build(); - ApplicationMapping mapping = stub.register(application); - logger.debug(mapping.getApplication(0).getKey() + ", " + mapping.getApplication(0).getValue()); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentJettyModule.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentJettyModule.java new file mode 100644 index 000000000000..87f0e730d9cc --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentJettyModule.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty; + +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class AgentJettyModule extends Module { + + public static final String NAME = "agent_jetty"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[0]; + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentJettyModule.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentJettyModule.java deleted file mode 100644 index e93293c868a9..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentJettyModule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty; - -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class AgentJettyModule extends Module { - - public static final String NAME = "agent_jetty"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[0]; - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..1234d192e374 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.agent.jetty.AgentJettyModule diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 75e781a4b462..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.agent.jetty.AgentJettyModule diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java new file mode 100644 index 000000000000..930ffcb4c32f --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.agent.jetty.handler.TraceSegmentServletHandler; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.naming.NamingModule; +import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.agent.jetty.handler.ApplicationRegisterServletHandler; +import org.apache.skywalking.apm.collector.agent.jetty.handler.InstanceDiscoveryServletHandler; +import org.apache.skywalking.apm.collector.agent.jetty.handler.ServiceNameDiscoveryServiceHandler; +import org.apache.skywalking.apm.collector.agent.jetty.handler.naming.AgentJettyNamingHandler; +import org.apache.skywalking.apm.collector.agent.jetty.handler.naming.AgentJettyNamingListener; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.jetty.manager.JettyManagerModule; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerService; + +/** + * @author peng-yongsheng + */ +public class AgentModuleJettyProvider extends ModuleProvider { + + public static final String NAME = "jetty"; + private static final String HOST = "host"; + private static final String PORT = "port"; + private static final String CONTEXT_PATH = "context_path"; + + @Override public String name() { + return NAME; + } + + @Override public Class module() { + return AgentJettyModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + String host = config.getProperty(HOST); + Integer port = (Integer)config.get(PORT); + String contextPath = config.getProperty(CONTEXT_PATH); + + ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); + moduleRegisterService.register(AgentJettyModule.NAME, this.name(), new AgentModuleJettyRegistration(host, port, contextPath)); + + AgentJettyNamingListener namingListener = new AgentJettyNamingListener(); + ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); + moduleListenerService.addListener(namingListener); + + NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class); + namingHandlerRegisterService.register(new AgentJettyNamingHandler(namingListener)); + + JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class); + Server jettyServer = managerService.createIfAbsent(host, port, contextPath); + addHandlers(jettyServer); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {ClusterModule.NAME, NamingModule.NAME, JettyManagerModule.NAME, AgentStreamModule.NAME}; + } + + private void addHandlers(Server jettyServer) { + jettyServer.addHandler(new TraceSegmentServletHandler(getManager())); + jettyServer.addHandler(new ApplicationRegisterServletHandler(getManager())); + jettyServer.addHandler(new InstanceDiscoveryServletHandler(getManager())); + jettyServer.addHandler(new ServiceNameDiscoveryServiceHandler(getManager())); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java new file mode 100644 index 000000000000..fbb0e1536455 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty; + +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; + +/** + * @author peng-yongsheng + */ +public class AgentModuleJettyRegistration extends ModuleRegistration { + + private final String host; + private final int port; + private final String contextPath; + + public AgentModuleJettyRegistration(String host, int port, String contextPath) { + this.host = host; + this.port = port; + this.contextPath = contextPath; + } + + @Override public Value buildValue() { + return new Value(host, port, contextPath); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java new file mode 100644 index 000000000000..d30a7b1cd48e --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationRegisterServletHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServletHandler.class); + + private final IApplicationIDService applicationIDService; + private Gson gson = new Gson(); + private static final String APPLICATION_CODE = "c"; + private static final String APPLICATION_ID = "i"; + + public ApplicationRegisterServletHandler(ModuleManager moduleManager) { + this.applicationIDService = moduleManager.find(AgentStreamModule.NAME).getService(IApplicationIDService.class); + } + + @Override public String pathSpec() { + return "/application/register"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + JsonArray responseArray = new JsonArray(); + try { + JsonArray applicationCodes = gson.fromJson(req.getReader(), JsonArray.class); + for (int i = 0; i < applicationCodes.size(); i++) { + String applicationCode = applicationCodes.get(i).getAsString(); + int applicationId = applicationIDService.getOrCreate(applicationCode); + JsonObject mapping = new JsonObject(); + mapping.addProperty(APPLICATION_CODE, applicationCode); + mapping.addProperty(APPLICATION_ID, applicationId); + responseArray.add(mapping); + } + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + return responseArray; + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java new file mode 100644 index 000000000000..a481e03b3f7e --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceDiscoveryServletHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServletHandler.class); + + private final IInstanceIDService instanceIDService; + private final Gson gson = new Gson(); + + private static final String APPLICATION_ID = "ai"; + private static final String AGENT_UUID = "au"; + private static final String REGISTER_TIME = "rt"; + private static final String INSTANCE_ID = "ii"; + private static final String OS_INFO = "oi"; + + public InstanceDiscoveryServletHandler(ModuleManager moduleManager) { + this.instanceIDService = moduleManager.find(AgentStreamModule.NAME).getService(IInstanceIDService.class); + } + + @Override public String pathSpec() { + return "/instance/register"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + JsonObject responseJson = new JsonObject(); + try { + JsonObject instance = gson.fromJson(req.getReader(), JsonObject.class); + int applicationId = instance.get(APPLICATION_ID).getAsInt(); + String agentUUID = instance.get(AGENT_UUID).getAsString(); + long registerTime = instance.get(REGISTER_TIME).getAsLong(); + JsonObject osInfo = instance.get(OS_INFO).getAsJsonObject(); + + int instanceId = instanceIDService.getOrCreate(applicationId, agentUUID, registerTime, osInfo.toString()); + responseJson.addProperty(APPLICATION_ID, applicationId); + responseJson.addProperty(INSTANCE_ID, instanceId); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + return responseJson; + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java new file mode 100644 index 000000000000..ee2d09cac653 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameDiscoveryServiceHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameDiscoveryServiceHandler.class); + + private final IServiceNameService serviceNameService; + private final Gson gson = new Gson(); + + private static final String APPLICATION_ID = "ai"; + private static final String SERVICE_NAME = "sn"; + private static final String SERVICE_ID = "si"; + private static final String ELEMENT = "el"; + + public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) { + this.serviceNameService = moduleManager.find(AgentStreamModule.NAME).getService(IServiceNameService.class); + } + + @Override public String pathSpec() { + return "/servicename/discovery"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + JsonArray responseArray = new JsonArray(); + try { + JsonArray services = gson.fromJson(req.getReader(), JsonArray.class); + for (JsonElement service : services) { + int applicationId = service.getAsJsonObject().get(APPLICATION_ID).getAsInt(); + String serviceName = service.getAsJsonObject().get(SERVICE_NAME).getAsString(); + + int serviceId = serviceNameService.getOrCreate(applicationId, serviceName); + if (serviceId != 0) { + JsonObject responseJson = new JsonObject(); + responseJson.addProperty(SERVICE_ID, serviceId); + responseJson.add(ELEMENT, service); + responseArray.add(responseJson); + } + } + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + return responseArray; + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java new file mode 100644 index 000000000000..ddcbff82408a --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.JsonElement; +import com.google.gson.stream.JsonReader; +import java.io.BufferedReader; +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.agent.jetty.handler.reader.TraceSegment; +import org.apache.skywalking.apm.collector.agent.jetty.handler.reader.TraceSegmentJsonReader; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TraceSegmentServletHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(TraceSegmentServletHandler.class); + + private final ITraceSegmentService traceSegmentService; + + public TraceSegmentServletHandler(ModuleManager moduleManager) { + this.traceSegmentService = moduleManager.find(AgentStreamModule.NAME).getService(ITraceSegmentService.class); + } + + @Override public String pathSpec() { + return "/segments"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + logger.debug("receive stream segment"); + try { + BufferedReader bufferedReader = req.getReader(); + read(bufferedReader); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + private TraceSegmentJsonReader jsonReader = new TraceSegmentJsonReader(); + + private void read(BufferedReader bufferedReader) throws IOException { + JsonReader reader = new JsonReader(bufferedReader); + + reader.beginArray(); + while (reader.hasNext()) { + TraceSegment traceSegment = jsonReader.read(reader); + traceSegmentService.send(traceSegment.getUpstreamSegment()); + } + reader.endArray(); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java new file mode 100644 index 000000000000..fa4ad3962c76 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.naming; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import java.util.Set; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; + +/** + * @author peng-yongsheng + */ +public class AgentJettyNamingHandler extends JettyHandler { + + private final AgentJettyNamingListener namingListener; + + public AgentJettyNamingHandler(AgentJettyNamingListener namingListener) { + this.namingListener = namingListener; + } + + @Override public String pathSpec() { + return "/agent/jetty"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + Set servers = namingListener.getAddresses(); + JsonArray serverArray = new JsonArray(); + servers.forEach(serverArray::add); + return serverArray; + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java new file mode 100644 index 000000000000..ed445d851eee --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.naming; + +import org.apache.skywalking.apm.collector.agent.jetty.AgentJettyModule; +import org.apache.skywalking.apm.collector.agent.jetty.AgentModuleJettyProvider; +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; + +/** + * @author peng-yongsheng + */ +public class AgentJettyNamingListener extends ClusterModuleListener { + + public static final String PATH = "/" + AgentJettyModule.NAME + "/" + AgentModuleJettyProvider.NAME; + + @Override public String path() { + return PATH; + } + + @Override public void serverJoinNotify(String serverAddress) { + + } + + @Override public void serverQuitNotify(String serverAddress) { + + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java new file mode 100644 index 000000000000..fae435319bac --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; + +import com.google.gson.stream.JsonReader; +import java.io.IOException; +import org.apache.skywalking.apm.network.proto.KeyWithStringValue; + +/** + * @author peng-yongsheng + */ +public class KeyWithStringValueJsonReader implements StreamJsonReader { + + private static final String KEY = "k"; + private static final String VALUE = "v"; + + @Override public KeyWithStringValue read(JsonReader reader) throws IOException { + KeyWithStringValue.Builder builder = KeyWithStringValue.newBuilder(); + + reader.beginObject(); + while (reader.hasNext()) { + switch (reader.nextName()) { + case KEY: + builder.setKey(reader.nextString()); + break; + case VALUE: + builder.setValue(reader.nextString()); + break; + default: + reader.skipValue(); + break; + } + } + reader.endObject(); + + return builder.build(); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java new file mode 100644 index 000000000000..8037f4bbc2c9 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; + +import com.google.gson.stream.JsonReader; +import java.io.IOException; +import org.apache.skywalking.apm.network.proto.LogMessage; + +/** + * @author peng-yongsheng + */ +public class LogJsonReader implements StreamJsonReader { + + private KeyWithStringValueJsonReader keyWithStringValueJsonReader = new KeyWithStringValueJsonReader(); + + private static final String TIME = "ti"; + private static final String LOG_DATA = "ld"; + + @Override public LogMessage read(JsonReader reader) throws IOException { + LogMessage.Builder builder = LogMessage.newBuilder(); + + while (reader.hasNext()) { + switch (reader.nextName()) { + case TIME: + builder.setTime(reader.nextLong()); + case LOG_DATA: + reader.beginArray(); + while (reader.hasNext()) { + builder.addData(keyWithStringValueJsonReader.read(reader)); + } + reader.endArray(); + default: + reader.skipValue(); + } + } + + return builder.build(); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java similarity index 79% rename from apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java rename to apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java index b5ed54147ab6..2b8d4a14932b 100644 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/ReferenceJsonReader.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.agent.jetty.handler.reader; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; import com.google.gson.stream.JsonReader; import java.io.IOException; -import org.skywalking.apm.network.proto.TraceSegmentReference; +import org.apache.skywalking.apm.network.proto.TraceSegmentReference; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java similarity index 75% rename from apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java rename to apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java index 5778ee32c3f2..bb41a746f15e 100644 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/SegmentJsonReader.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.agent.jetty.handler.reader; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; import com.google.gson.stream.JsonReader; import java.io.IOException; -import org.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java similarity index 84% rename from apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java rename to apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java index cd0163be268f..7aafff328d0b 100644 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/SpanJsonReader.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.agent.jetty.handler.reader; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; import com.google.gson.stream.JsonReader; import java.io.IOException; -import org.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.SpanObject; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java new file mode 100644 index 000000000000..143b9d0c9321 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; + +import com.google.gson.stream.JsonReader; +import java.io.IOException; + +/** + * @author peng-yongsheng + */ +public interface StreamJsonReader { + T read(JsonReader reader) throws IOException; +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java new file mode 100644 index 000000000000..1bc7c025f488 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; + +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.UniqueId; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +/** + * @author peng-yongsheng + */ +public class TraceSegment { + + private UpstreamSegment.Builder builder; + + public TraceSegment() { + builder = UpstreamSegment.newBuilder(); + } + + public void addGlobalTraceId(UniqueId.Builder globalTraceId) { + builder.addGlobalTraceIds(globalTraceId); + } + + public void setTraceSegmentBuilder(TraceSegmentObject.Builder traceSegmentBuilder) { + builder.setSegment(traceSegmentBuilder.build().toByteString()); + } + + public UpstreamSegment getUpstreamSegment() { + return builder.build(); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java new file mode 100644 index 000000000000..7b5bf75bdcc3 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; + +import com.google.gson.stream.JsonReader; +import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TraceSegmentJsonReader implements StreamJsonReader { + + private final Logger logger = LoggerFactory.getLogger(TraceSegmentJsonReader.class); + + private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader(); + private SegmentJsonReader segmentJsonReader = new SegmentJsonReader(); + + private static final String GLOBAL_TRACE_IDS = "gt"; + private static final String SEGMENT = "sg"; + + @Override public TraceSegment read(JsonReader reader) throws IOException { + TraceSegment traceSegment = new TraceSegment(); + + reader.beginObject(); + while (reader.hasNext()) { + switch (reader.nextName()) { + case GLOBAL_TRACE_IDS: + reader.beginArray(); + while (reader.hasNext()) { + traceSegment.addGlobalTraceId(uniqueIdJsonReader.read(reader)); + } + reader.endArray(); + + break; + case SEGMENT: + traceSegment.setTraceSegmentBuilder(segmentJsonReader.read(reader)); + break; + default: + reader.skipValue(); + break; + } + } + reader.endObject(); + + return traceSegment; + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java new file mode 100644 index 000000000000..8af787b41352 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler.reader; + +import com.google.gson.stream.JsonReader; +import java.io.IOException; +import org.apache.skywalking.apm.network.proto.UniqueId; + +/** + * @author peng-yongsheng + */ +public class UniqueIdJsonReader implements StreamJsonReader { + + @Override public UniqueId.Builder read(JsonReader reader) throws IOException { + UniqueId.Builder builder = UniqueId.newBuilder(); + + reader.beginArray(); + while (reader.hasNext()) { + builder.addIdParts(reader.nextLong()); + } + reader.endArray(); + return builder; + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java deleted file mode 100644 index 069083c02086..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyProvider.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty; - -import java.util.Properties; -import org.skywalking.apm.collector.agent.jetty.handler.ApplicationRegisterServletHandler; -import org.skywalking.apm.collector.agent.jetty.handler.InstanceDiscoveryServletHandler; -import org.skywalking.apm.collector.agent.jetty.handler.ServiceNameDiscoveryServiceHandler; -import org.skywalking.apm.collector.agent.jetty.handler.TraceSegmentServletHandler; -import org.skywalking.apm.collector.agent.jetty.handler.naming.AgentJettyNamingHandler; -import org.skywalking.apm.collector.agent.jetty.handler.naming.AgentJettyNamingListener; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.jetty.manager.JettyManagerModule; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService; -import org.skywalking.apm.collector.naming.NamingModule; -import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; -import org.skywalking.apm.collector.server.Server; - -/** - * @author peng-yongsheng - */ -public class AgentModuleJettyProvider extends ModuleProvider { - - public static final String NAME = "jetty"; - private static final String HOST = "host"; - private static final String PORT = "port"; - private static final String CONTEXT_PATH = "context_path"; - - @Override public String name() { - return NAME; - } - - @Override public Class module() { - return AgentJettyModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - String host = config.getProperty(HOST); - Integer port = (Integer)config.get(PORT); - String contextPath = config.getProperty(CONTEXT_PATH); - - ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); - moduleRegisterService.register(AgentJettyModule.NAME, this.name(), new AgentModuleJettyRegistration(host, port, contextPath)); - - AgentJettyNamingListener namingListener = new AgentJettyNamingListener(); - ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); - moduleListenerService.addListener(namingListener); - - NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class); - namingHandlerRegisterService.register(new AgentJettyNamingHandler(namingListener)); - - JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class); - Server jettyServer = managerService.createIfAbsent(host, port, contextPath); - addHandlers(jettyServer); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {ClusterModule.NAME, NamingModule.NAME, JettyManagerModule.NAME, AgentStreamModule.NAME}; - } - - private void addHandlers(Server jettyServer) { - jettyServer.addHandler(new TraceSegmentServletHandler(getManager())); - jettyServer.addHandler(new ApplicationRegisterServletHandler(getManager())); - jettyServer.addHandler(new InstanceDiscoveryServletHandler(getManager())); - jettyServer.addHandler(new ServiceNameDiscoveryServiceHandler(getManager())); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java deleted file mode 100644 index a8004e00b07a..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/AgentModuleJettyRegistration.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; - -/** - * @author peng-yongsheng - */ -public class AgentModuleJettyRegistration extends ModuleRegistration { - - private final String host; - private final int port; - private final String contextPath; - - public AgentModuleJettyRegistration(String host, int port, String contextPath) { - this.host = host; - this.port = port; - this.contextPath = contextPath; - } - - @Override public Value buildValue() { - return new Value(host, port, contextPath); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java deleted file mode 100644 index 2addd6277896..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterServletHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationRegisterServletHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServletHandler.class); - - private final IApplicationIDService applicationIDService; - private Gson gson = new Gson(); - private static final String APPLICATION_CODE = "c"; - private static final String APPLICATION_ID = "i"; - - public ApplicationRegisterServletHandler(ModuleManager moduleManager) { - this.applicationIDService = moduleManager.find(AgentStreamModule.NAME).getService(IApplicationIDService.class); - } - - @Override public String pathSpec() { - return "/application/register"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - JsonArray responseArray = new JsonArray(); - try { - JsonArray applicationCodes = gson.fromJson(req.getReader(), JsonArray.class); - for (int i = 0; i < applicationCodes.size(); i++) { - String applicationCode = applicationCodes.get(i).getAsString(); - int applicationId = applicationIDService.getOrCreate(applicationCode); - JsonObject mapping = new JsonObject(); - mapping.addProperty(APPLICATION_CODE, applicationCode); - mapping.addProperty(APPLICATION_ID, applicationId); - responseArray.add(mapping); - } - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - return responseArray; - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java deleted file mode 100644 index 400a1b1dc786..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceDiscoveryServletHandler.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceDiscoveryServletHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServletHandler.class); - - private final IInstanceIDService instanceIDService; - private final Gson gson = new Gson(); - - private static final String APPLICATION_ID = "ai"; - private static final String AGENT_UUID = "au"; - private static final String REGISTER_TIME = "rt"; - private static final String INSTANCE_ID = "ii"; - private static final String OS_INFO = "oi"; - - public InstanceDiscoveryServletHandler(ModuleManager moduleManager) { - this.instanceIDService = moduleManager.find(AgentStreamModule.NAME).getService(IInstanceIDService.class); - } - - @Override public String pathSpec() { - return "/instance/register"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - JsonObject responseJson = new JsonObject(); - try { - JsonObject instance = gson.fromJson(req.getReader(), JsonObject.class); - int applicationId = instance.get(APPLICATION_ID).getAsInt(); - String agentUUID = instance.get(AGENT_UUID).getAsString(); - long registerTime = instance.get(REGISTER_TIME).getAsLong(); - JsonObject osInfo = instance.get(OS_INFO).getAsJsonObject(); - - int instanceId = instanceIDService.getOrCreate(applicationId, agentUUID, registerTime, osInfo.toString()); - responseJson.addProperty(APPLICATION_ID, applicationId); - responseJson.addProperty(INSTANCE_ID, instanceId); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - return responseJson; - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java deleted file mode 100644 index 0e9a548b0f44..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameDiscoveryServiceHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameDiscoveryServiceHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameDiscoveryServiceHandler.class); - - private final IServiceNameService serviceNameService; - private final Gson gson = new Gson(); - - private static final String APPLICATION_ID = "ai"; - private static final String SERVICE_NAME = "sn"; - private static final String SERVICE_ID = "si"; - private static final String ELEMENT = "el"; - - public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) { - this.serviceNameService = moduleManager.find(AgentStreamModule.NAME).getService(IServiceNameService.class); - } - - @Override public String pathSpec() { - return "/servicename/discovery"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - JsonArray responseArray = new JsonArray(); - try { - JsonArray services = gson.fromJson(req.getReader(), JsonArray.class); - for (JsonElement service : services) { - int applicationId = service.getAsJsonObject().get(APPLICATION_ID).getAsInt(); - String serviceName = service.getAsJsonObject().get(SERVICE_NAME).getAsString(); - - int serviceId = serviceNameService.getOrCreate(applicationId, serviceName); - if (serviceId != 0) { - JsonObject responseJson = new JsonObject(); - responseJson.addProperty(SERVICE_ID, serviceId); - responseJson.add(ELEMENT, service); - responseArray.add(responseJson); - } - } - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - return responseArray; - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java deleted file mode 100644 index ae0d1d711b52..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/TraceSegmentServletHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.JsonElement; -import com.google.gson.stream.JsonReader; -import java.io.BufferedReader; -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.agent.jetty.handler.reader.TraceSegment; -import org.skywalking.apm.collector.agent.jetty.handler.reader.TraceSegmentJsonReader; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceSegmentServletHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(TraceSegmentServletHandler.class); - - private final ITraceSegmentService traceSegmentService; - - public TraceSegmentServletHandler(ModuleManager moduleManager) { - this.traceSegmentService = moduleManager.find(AgentStreamModule.NAME).getService(ITraceSegmentService.class); - } - - @Override public String pathSpec() { - return "/segments"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - logger.debug("receive stream segment"); - try { - BufferedReader bufferedReader = req.getReader(); - read(bufferedReader); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - return null; - } - - private TraceSegmentJsonReader jsonReader = new TraceSegmentJsonReader(); - - private void read(BufferedReader bufferedReader) throws IOException { - JsonReader reader = new JsonReader(bufferedReader); - - reader.beginArray(); - while (reader.hasNext()) { - TraceSegment traceSegment = jsonReader.read(reader); - traceSegmentService.send(traceSegment.getUpstreamSegment()); - } - reader.endArray(); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java deleted file mode 100644 index 3941a5433eae..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.naming; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; - -/** - * @author peng-yongsheng - */ -public class AgentJettyNamingHandler extends JettyHandler { - - private final AgentJettyNamingListener namingListener; - - public AgentJettyNamingHandler(AgentJettyNamingListener namingListener) { - this.namingListener = namingListener; - } - - @Override public String pathSpec() { - return "/agent/jetty"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - Set servers = namingListener.getAddresses(); - JsonArray serverArray = new JsonArray(); - servers.forEach(serverArray::add); - return serverArray; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java deleted file mode 100644 index 0e103c4d1a09..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/naming/AgentJettyNamingListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.naming; - -import org.skywalking.apm.collector.agent.jetty.AgentJettyModule; -import org.skywalking.apm.collector.agent.jetty.AgentModuleJettyProvider; -import org.skywalking.apm.collector.cluster.ClusterModuleListener; - -/** - * @author peng-yongsheng - */ -public class AgentJettyNamingListener extends ClusterModuleListener { - - public static final String PATH = "/" + AgentJettyModule.NAME + "/" + AgentModuleJettyProvider.NAME; - - @Override public String path() { - return PATH; - } - - @Override public void serverJoinNotify(String serverAddress) { - - } - - @Override public void serverQuitNotify(String serverAddress) { - - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java deleted file mode 100644 index c639298548a2..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/KeyWithStringValueJsonReader.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.reader; - -import com.google.gson.stream.JsonReader; -import java.io.IOException; -import org.skywalking.apm.network.proto.KeyWithStringValue; - -/** - * @author peng-yongsheng - */ -public class KeyWithStringValueJsonReader implements StreamJsonReader { - - private static final String KEY = "k"; - private static final String VALUE = "v"; - - @Override public KeyWithStringValue read(JsonReader reader) throws IOException { - KeyWithStringValue.Builder builder = KeyWithStringValue.newBuilder(); - - reader.beginObject(); - while (reader.hasNext()) { - switch (reader.nextName()) { - case KEY: - builder.setKey(reader.nextString()); - break; - case VALUE: - builder.setValue(reader.nextString()); - break; - default: - reader.skipValue(); - break; - } - } - reader.endObject(); - - return builder.build(); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java deleted file mode 100644 index 74a753e7958b..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/LogJsonReader.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.reader; - -import com.google.gson.stream.JsonReader; -import java.io.IOException; -import org.skywalking.apm.network.proto.LogMessage; - -/** - * @author peng-yongsheng - */ -public class LogJsonReader implements StreamJsonReader { - - private KeyWithStringValueJsonReader keyWithStringValueJsonReader = new KeyWithStringValueJsonReader(); - - private static final String TIME = "ti"; - private static final String LOG_DATA = "ld"; - - @Override public LogMessage read(JsonReader reader) throws IOException { - LogMessage.Builder builder = LogMessage.newBuilder(); - - while (reader.hasNext()) { - switch (reader.nextName()) { - case TIME: - builder.setTime(reader.nextLong()); - case LOG_DATA: - reader.beginArray(); - while (reader.hasNext()) { - builder.addData(keyWithStringValueJsonReader.read(reader)); - } - reader.endArray(); - default: - reader.skipValue(); - } - } - - return builder.build(); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java deleted file mode 100644 index 347b55d58c59..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/StreamJsonReader.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.reader; - -import com.google.gson.stream.JsonReader; -import java.io.IOException; - -/** - * @author peng-yongsheng - */ -public interface StreamJsonReader { - T read(JsonReader reader) throws IOException; -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java deleted file mode 100644 index e10a7594e463..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegment.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.reader; - -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.proto.UniqueId; -import org.skywalking.apm.network.proto.UpstreamSegment; - -/** - * @author peng-yongsheng - */ -public class TraceSegment { - - private UpstreamSegment.Builder builder; - - public TraceSegment() { - builder = UpstreamSegment.newBuilder(); - } - - public void addGlobalTraceId(UniqueId.Builder globalTraceId) { - builder.addGlobalTraceIds(globalTraceId); - } - - public void setTraceSegmentBuilder(TraceSegmentObject.Builder traceSegmentBuilder) { - builder.setSegment(traceSegmentBuilder.build().toByteString()); - } - - public UpstreamSegment getUpstreamSegment() { - return builder.build(); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java deleted file mode 100644 index 58c05d897a0f..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/TraceSegmentJsonReader.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.reader; - -import com.google.gson.stream.JsonReader; -import java.io.IOException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceSegmentJsonReader implements StreamJsonReader { - - private final Logger logger = LoggerFactory.getLogger(TraceSegmentJsonReader.class); - - private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader(); - private SegmentJsonReader segmentJsonReader = new SegmentJsonReader(); - - private static final String GLOBAL_TRACE_IDS = "gt"; - private static final String SEGMENT = "sg"; - - @Override public TraceSegment read(JsonReader reader) throws IOException { - TraceSegment traceSegment = new TraceSegment(); - - reader.beginObject(); - while (reader.hasNext()) { - switch (reader.nextName()) { - case GLOBAL_TRACE_IDS: - reader.beginArray(); - while (reader.hasNext()) { - traceSegment.addGlobalTraceId(uniqueIdJsonReader.read(reader)); - } - reader.endArray(); - - break; - case SEGMENT: - traceSegment.setTraceSegmentBuilder(segmentJsonReader.read(reader)); - break; - default: - reader.skipValue(); - break; - } - } - reader.endObject(); - - return traceSegment; - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java deleted file mode 100644 index a1d44419bee0..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/java/org/skywalking/apm/collector/agent/jetty/handler/reader/UniqueIdJsonReader.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler.reader; - -import com.google.gson.stream.JsonReader; -import java.io.IOException; -import org.skywalking.apm.network.proto.UniqueId; - -/** - * @author peng-yongsheng - */ -public class UniqueIdJsonReader implements StreamJsonReader { - - @Override public UniqueId.Builder read(JsonReader reader) throws IOException { - UniqueId.Builder builder = UniqueId.newBuilder(); - - reader.beginArray(); - while (reader.hasNext()) { - builder.addIdParts(reader.nextLong()); - } - reader.endArray(); - return builder; - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..b353e54334ee --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.agent.jetty.AgentModuleJettyProvider diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 93047114bcf5..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.agent.jetty.AgentModuleJettyProvider diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java new file mode 100644 index 000000000000..d67e617ba1fb --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.JsonElement; +import java.io.IOException; + +/** + * @author peng-yongsheng + */ +public class ApplicationRegisterPost { + + public void send(String jsonFile) throws IOException { + JsonElement application = JsonFileReader.INSTANCE.read(jsonFile); + HttpClientTools.INSTANCE.post("http://localhost:12800/application/register", application.toString()); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java similarity index 80% rename from apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java rename to apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java index 831e0a3156ff..fc45de06e4d1 100644 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/HttpClientTools.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.agent.jetty.handler; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; import java.io.IOException; import java.net.URI; diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java new file mode 100644 index 000000000000..f257f8391f8b --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.JsonElement; +import java.io.IOException; + +/** + * @author peng-yongsheng + */ +public class InstanceRegisterPost { + + public void send(String jsonFile) throws IOException { + JsonElement instance = JsonFileReader.INSTANCE.read(jsonFile); + HttpClientTools.INSTANCE.post("http://localhost:12800/instance/register", instance.toString()); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java new file mode 100644 index 000000000000..8b6e43018e95 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import java.io.FileNotFoundException; +import java.io.FileReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public enum JsonFileReader { + INSTANCE; + + private final Logger logger = LoggerFactory.getLogger(JsonFileReader.class); + + public JsonElement read(String fileName) throws FileNotFoundException { + String path = this.getClass().getClassLoader().getResource(fileName).getFile(); + logger.debug("path: {}", path); + JsonParser jsonParser = new JsonParser(); + return jsonParser.parse(new FileReader(path)); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java new file mode 100644 index 000000000000..d420c78a8753 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.JsonElement; +import java.io.IOException; + +/** + * @author peng-yongsheng + */ +public class SegmentPost { + + public static void main(String[] args) throws IOException { + ApplicationRegisterPost applicationRegisterPost = new ApplicationRegisterPost(); + applicationRegisterPost.send("json/application-register-consumer.json"); + applicationRegisterPost.send("json/application-register-provider.json"); + + InstanceRegisterPost instanceRegisterPost = new InstanceRegisterPost(); + instanceRegisterPost.send("json/instance-register-consumer.json"); + instanceRegisterPost.send("json/instance-register-provider.json"); + + ServiceNameRegisterPost serviceNameRegisterPost = new ServiceNameRegisterPost(); + serviceNameRegisterPost.send("json/servicename-register-consumer.json"); + serviceNameRegisterPost.send("json/servicename-register-provider.json"); + + JsonElement provider = JsonFileReader.INSTANCE.read("json/dubbox-provider.json"); + JsonElement consumer = JsonFileReader.INSTANCE.read("json/dubbox-consumer.json"); + + for (int i = 0; i < 1; i++) { + HttpClientTools.INSTANCE.post("http://localhost:12800/segments", provider.toString()); + HttpClientTools.INSTANCE.post("http://localhost:12800/segments", consumer.toString()); + } + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java new file mode 100644 index 000000000000..b96782914890 --- /dev/null +++ b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.jetty.handler; + +import com.google.gson.JsonElement; +import java.io.IOException; + +/** + * @author peng-yongsheng + */ +public class ServiceNameRegisterPost { + + public void send(String jsonFile) throws IOException { + JsonElement instance = JsonFileReader.INSTANCE.read(jsonFile); + HttpClientTools.INSTANCE.post("http://localhost:12800/servicename/discovery", instance.toString()); + } +} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java deleted file mode 100644 index a8d6cb153e86..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ApplicationRegisterPost.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.JsonElement; -import java.io.IOException; - -/** - * @author peng-yongsheng - */ -public class ApplicationRegisterPost { - - public void send(String jsonFile) throws IOException { - JsonElement application = JsonFileReader.INSTANCE.read(jsonFile); - HttpClientTools.INSTANCE.post("http://localhost:12800/application/register", application.toString()); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java deleted file mode 100644 index 49ce1d13d7b8..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/InstanceRegisterPost.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.JsonElement; -import java.io.IOException; - -/** - * @author peng-yongsheng - */ -public class InstanceRegisterPost { - - public void send(String jsonFile) throws IOException { - JsonElement instance = JsonFileReader.INSTANCE.read(jsonFile); - HttpClientTools.INSTANCE.post("http://localhost:12800/instance/register", instance.toString()); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java deleted file mode 100644 index e1254be7eec6..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/JsonFileReader.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import java.io.FileNotFoundException; -import java.io.FileReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public enum JsonFileReader { - INSTANCE; - - private final Logger logger = LoggerFactory.getLogger(JsonFileReader.class); - - public JsonElement read(String fileName) throws FileNotFoundException { - String path = this.getClass().getClassLoader().getResource(fileName).getFile(); - logger.debug("path: {}", path); - JsonParser jsonParser = new JsonParser(); - return jsonParser.parse(new FileReader(path)); - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java deleted file mode 100644 index 89a9d05ecce8..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/SegmentPost.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.JsonElement; -import java.io.IOException; - -/** - * @author peng-yongsheng - */ -public class SegmentPost { - - public static void main(String[] args) throws IOException { - ApplicationRegisterPost applicationRegisterPost = new ApplicationRegisterPost(); - applicationRegisterPost.send("json/application-register-consumer.json"); - applicationRegisterPost.send("json/application-register-provider.json"); - - InstanceRegisterPost instanceRegisterPost = new InstanceRegisterPost(); - instanceRegisterPost.send("json/instance-register-consumer.json"); - instanceRegisterPost.send("json/instance-register-provider.json"); - - ServiceNameRegisterPost serviceNameRegisterPost = new ServiceNameRegisterPost(); - serviceNameRegisterPost.send("json/servicename-register-consumer.json"); - serviceNameRegisterPost.send("json/servicename-register-provider.json"); - - JsonElement provider = JsonFileReader.INSTANCE.read("json/dubbox-provider.json"); - JsonElement consumer = JsonFileReader.INSTANCE.read("json/dubbox-consumer.json"); - - for (int i = 0; i < 1; i++) { - HttpClientTools.INSTANCE.post("http://localhost:12800/segments", provider.toString()); - HttpClientTools.INSTANCE.post("http://localhost:12800/segments", consumer.toString()); - } - } -} diff --git a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java b/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java deleted file mode 100644 index 6056250863d8..000000000000 --- a/apm-collector/apm-collector-agent-jetty/collector-agent-jetty-provider/src/test/java/org/skywalking/apm/collector/agent/jetty/handler/ServiceNameRegisterPost.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.jetty.handler; - -import com.google.gson.JsonElement; -import java.io.IOException; - -/** - * @author peng-yongsheng - */ -public class ServiceNameRegisterPost { - - public void send(String jsonFile) throws IOException { - JsonElement instance = JsonFileReader.INSTANCE.read(jsonFile); - HttpClientTools.INSTANCE.post("http://localhost:12800/servicename/discovery", instance.toString()); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModule.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModule.java new file mode 100644 index 000000000000..91a53b7b9759 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModule.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; +import org.apache.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class AgentStreamModule extends Module { + + public static final String NAME = "agent_stream"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + List classes = new ArrayList<>(); + + addRegisterService(classes); + addJVMService(classes); + classes.add(ITraceSegmentService.class); + + return classes.toArray(new Class[] {}); + } + + private void addRegisterService(List classes) { + classes.add(IApplicationIDService.class); + classes.add(IInstanceIDService.class); + classes.add(IServiceNameService.class); + } + + private void addJVMService(List classes) { + classes.add(ICpuMetricService.class); + classes.add(IGCMetricService.class); + classes.add(IMemoryMetricService.class); + classes.add(IMemoryPoolMetricService.class); + classes.add(IInstanceHeartBeatService.class); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java new file mode 100644 index 000000000000..1798bfdb73c4 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.graph; + +/** + * @author peng-yongsheng + */ +public class ApplicationGraphNodeIdDefine { + public static final int APPLICATION_REFERENCE_METRIC_AGGREGATION_NODE_ID = 1001; + public static final int APPLICATION_REFERENCE_METRIC_REMOTE_NODE_ID = 1002; + public static final int APPLICATION_REFERENCE_METRIC_PERSISTENCE_NODE_ID = 1003; +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java new file mode 100644 index 000000000000..d1df2026abb7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.graph; + +/** + * @author peng-yongsheng + */ +public class InstanceGraphNodeIdDefine { + public static final int INSTANCE_REFERENCE_METRIC_AGGREGATION_NODE_ID = 2001; + public static final int INSTANCE_REFERENCE_METRIC_REMOTE_NODE_ID = 2002; + public static final int INSTANCE_REFERENCE_METRIC_PERSISTENCE_NODE_ID = 2003; +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java new file mode 100644 index 000000000000..fad384a0f4e1 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.graph; + +/** + * @author peng-yongsheng + */ +public class JvmMetricStreamGraphDefine { + public static final int GC_METRIC_GRAPH_ID = 100; + public static final int MEMORY_METRIC_GRAPH_ID = 101; + public static final int MEMORY_POOL_METRIC_GRAPH_ID = 102; + public static final int CPU_METRIC_GRAPH_ID = 103; + public static final int INST_HEART_BEAT_GRAPH_ID = 104; +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java new file mode 100644 index 000000000000..4a520ea5982c --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.graph; + +/** + * @author peng-yongsheng + */ +public class RegisterStreamGraphDefine { + public static final int APPLICATION_REGISTER_GRAPH_ID = 200; + public static final int INSTANCE_REGISTER_GRAPH_ID = 201; + public static final int SERVICE_NAME_REGISTER_GRAPH_ID = 202; +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java new file mode 100644 index 000000000000..9d804815f308 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.graph; + +/** + * @author peng-yongsheng + */ +public class ServiceGraphNodeIdDefine { + public static final int SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID = 3001; + public static final int SERVICE_REFERENCE_METRIC_REMOTE_NODE_ID = 3002; + public static final int SERVICE_REFERENCE_METRIC_PERSISTENCE_NODE_ID = 3003; +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java new file mode 100644 index 000000000000..0671d5f775be --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.jvm; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface ICpuMetricService extends Service { + void send(int instanceId, long timeBucket, double usagePercent); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java new file mode 100644 index 000000000000..4812a236a6d7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.jvm; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IGCMetricService extends Service { + void send(int instanceId, long timeBucket, int phraseValue, long count, long time); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java new file mode 100644 index 000000000000..c5108d0a2f3e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.jvm; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IInstanceHeartBeatService extends Service { + void send(int instanceId, long heartBeatTime); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java new file mode 100644 index 000000000000..3aac3fc900c9 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.jvm; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IMemoryMetricService extends Service { + void send(int instanceId, long timeBucket, boolean isHeap, long init, long max, long used, long commited); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java new file mode 100644 index 000000000000..42b4c08d9471 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.jvm; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IMemoryPoolMetricService extends Service { + void send(int instanceId, long timeBucket, int poolType, long init, long max, long used, long commited); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java new file mode 100644 index 000000000000..0388efdbc1a7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.register; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IApplicationIDService extends Service { + int getOrCreate(String applicationCode); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java new file mode 100644 index 000000000000..fe2f8114bf61 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.register; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IInstanceIDService extends Service { + int getOrCreate(int applicationId, String agentUUID, long registerTime, String osInfo); + + void recover(int instanceId, int applicationId, long registerTime, String osInfo); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java new file mode 100644 index 000000000000..02890c1f1703 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.register; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IServiceNameService extends Service { + int getOrCreate(int applicationId, String serviceName); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java new file mode 100644 index 000000000000..7630b6f41b73 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.trace; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +/** + * @author peng-yongsheng + */ +public interface ITraceSegmentService extends Service { + void send(UpstreamSegment segment); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java new file mode 100644 index 000000000000..d02eeafae588 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/apache/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.service.trace; + +/** + * @author peng-yongsheng + */ +public enum MetricSource { + Exit, Entry +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModule.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModule.java deleted file mode 100644 index 7d782de339e7..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModule.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream; - -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; -import org.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; -import org.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; -import org.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; -import org.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class AgentStreamModule extends Module { - - public static final String NAME = "agent_stream"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - List classes = new ArrayList<>(); - - addRegisterService(classes); - addJVMService(classes); - classes.add(ITraceSegmentService.class); - - return classes.toArray(new Class[] {}); - } - - private void addRegisterService(List classes) { - classes.add(IApplicationIDService.class); - classes.add(IInstanceIDService.class); - classes.add(IServiceNameService.class); - } - - private void addJVMService(List classes) { - classes.add(ICpuMetricService.class); - classes.add(IGCMetricService.class); - classes.add(IMemoryMetricService.class); - classes.add(IMemoryPoolMetricService.class); - classes.add(IInstanceHeartBeatService.class); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java deleted file mode 100644 index cf7b786092a1..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ApplicationGraphNodeIdDefine.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.graph; - -/** - * @author peng-yongsheng - */ -public class ApplicationGraphNodeIdDefine { - public static final int APPLICATION_REFERENCE_METRIC_AGGREGATION_NODE_ID = 1001; - public static final int APPLICATION_REFERENCE_METRIC_REMOTE_NODE_ID = 1002; - public static final int APPLICATION_REFERENCE_METRIC_PERSISTENCE_NODE_ID = 1003; -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java deleted file mode 100644 index 75593f28d059..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/InstanceGraphNodeIdDefine.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.graph; - -/** - * @author peng-yongsheng - */ -public class InstanceGraphNodeIdDefine { - public static final int INSTANCE_REFERENCE_METRIC_AGGREGATION_NODE_ID = 2001; - public static final int INSTANCE_REFERENCE_METRIC_REMOTE_NODE_ID = 2002; - public static final int INSTANCE_REFERENCE_METRIC_PERSISTENCE_NODE_ID = 2003; -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java deleted file mode 100644 index ae55132ce977..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/JvmMetricStreamGraphDefine.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.graph; - -/** - * @author peng-yongsheng - */ -public class JvmMetricStreamGraphDefine { - public static final int GC_METRIC_GRAPH_ID = 100; - public static final int MEMORY_METRIC_GRAPH_ID = 101; - public static final int MEMORY_POOL_METRIC_GRAPH_ID = 102; - public static final int CPU_METRIC_GRAPH_ID = 103; - public static final int INST_HEART_BEAT_GRAPH_ID = 104; -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java deleted file mode 100644 index 92fbf759e015..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/RegisterStreamGraphDefine.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.graph; - -/** - * @author peng-yongsheng - */ -public class RegisterStreamGraphDefine { - public static final int APPLICATION_REGISTER_GRAPH_ID = 200; - public static final int INSTANCE_REGISTER_GRAPH_ID = 201; - public static final int SERVICE_NAME_REGISTER_GRAPH_ID = 202; -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java deleted file mode 100644 index 3ff42dfcdc20..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/graph/ServiceGraphNodeIdDefine.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.graph; - -/** - * @author peng-yongsheng - */ -public class ServiceGraphNodeIdDefine { - public static final int SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID = 3001; - public static final int SERVICE_REFERENCE_METRIC_REMOTE_NODE_ID = 3002; - public static final int SERVICE_REFERENCE_METRIC_PERSISTENCE_NODE_ID = 3003; -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java deleted file mode 100644 index 3127e20db8f6..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/ICpuMetricService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.jvm; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface ICpuMetricService extends Service { - void send(int instanceId, long timeBucket, double usagePercent); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java deleted file mode 100644 index 3fde5ee9224e..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IGCMetricService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.jvm; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IGCMetricService extends Service { - void send(int instanceId, long timeBucket, int phraseValue, long count, long time); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java deleted file mode 100644 index 4203eaf95eef..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IInstanceHeartBeatService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.jvm; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IInstanceHeartBeatService extends Service { - void send(int instanceId, long heartBeatTime); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java deleted file mode 100644 index 9bd0db915904..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryMetricService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.jvm; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IMemoryMetricService extends Service { - void send(int instanceId, long timeBucket, boolean isHeap, long init, long max, long used, long commited); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java deleted file mode 100644 index 2dead89ae199..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/jvm/IMemoryPoolMetricService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.jvm; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IMemoryPoolMetricService extends Service { - void send(int instanceId, long timeBucket, int poolType, long init, long max, long used, long commited); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java deleted file mode 100644 index fd34d7e0f878..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IApplicationIDService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.register; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IApplicationIDService extends Service { - int getOrCreate(String applicationCode); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java deleted file mode 100644 index 3f8a57138cef..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IInstanceIDService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.register; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IInstanceIDService extends Service { - int getOrCreate(int applicationId, String agentUUID, long registerTime, String osInfo); - - void recover(int instanceId, int applicationId, long registerTime, String osInfo); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java deleted file mode 100644 index 875a5157deaa..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/register/IServiceNameService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.register; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IServiceNameService extends Service { - int getOrCreate(int applicationId, String serviceName); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java deleted file mode 100644 index 9b81a846f230..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/ITraceSegmentService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.trace; - -import org.skywalking.apm.collector.core.module.Service; -import org.skywalking.apm.network.proto.UpstreamSegment; - -/** - * @author peng-yongsheng - */ -public interface ITraceSegmentService extends Service { - void send(UpstreamSegment segment); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java deleted file mode 100644 index 3261863ef38a..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/java/org/skywalking/apm/collector/agent/stream/service/trace/MetricSource.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.service.trace; - -/** - * @author peng-yongsheng - */ -public enum MetricSource { - Exit, Entry -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..af4001408438 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 20dd2c6a7f68..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.agent.stream.AgentStreamModule diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java new file mode 100644 index 000000000000..4156dd4acd0b --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream; + +import org.apache.skywalking.apm.collector.agent.stream.graph.JvmMetricStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.graph.RegisterStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; +import org.apache.skywalking.apm.collector.stream.timer.PersistenceTimer; + +/** + * @author peng-yongsheng + */ +public class AgentStreamBootStartup { + + private final ModuleManager moduleManager; + private final WorkerCreateListener workerCreateListener; + + public AgentStreamBootStartup(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.workerCreateListener = new WorkerCreateListener(); + } + + public void start() { + createJVMGraph(); + createRegisterGraph(); + createTraceGraph(); + + PersistenceTimer timer = new PersistenceTimer(); + timer.start(moduleManager, workerCreateListener.getPersistenceWorkers()); + } + + private void createJVMGraph() { + JvmMetricStreamGraph jvmMetricStreamGraph = new JvmMetricStreamGraph(moduleManager, workerCreateListener); + jvmMetricStreamGraph.createCpuMetricGraph(); + jvmMetricStreamGraph.createGcMetricGraph(); + jvmMetricStreamGraph.createMemoryMetricGraph(); + jvmMetricStreamGraph.createMemoryPoolMetricGraph(); + jvmMetricStreamGraph.createHeartBeatGraph(); + } + + private void createRegisterGraph() { + RegisterStreamGraph registerStreamGraph = new RegisterStreamGraph(moduleManager, workerCreateListener); + registerStreamGraph.createApplicationRegisterGraph(); + registerStreamGraph.createInstanceRegisterGraph(); + registerStreamGraph.createServiceNameRegisterGraph(); + } + + private void createTraceGraph() { + TraceStreamGraph traceStreamGraph = new TraceStreamGraph(moduleManager, workerCreateListener); + traceStreamGraph.createSegmentStandardizationGraph(); + traceStreamGraph.createGlobalTraceGraph(); + traceStreamGraph.createInstanceMetricGraph(); + traceStreamGraph.createApplicationComponentGraph(); + traceStreamGraph.createApplicationMappingGraph(); +// traceStreamGraph.createApplicationReferenceMetricGraph(); + traceStreamGraph.createServiceEntryGraph(); + traceStreamGraph.createSegmentGraph(); + traceStreamGraph.createSegmentCostGraph(); + + traceStreamGraph.createServiceReferenceGraph(); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java new file mode 100644 index 000000000000..d6b622a5ef32 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.agent.stream.buffer.BufferFileConfig; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; +import org.apache.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; +import org.apache.skywalking.apm.collector.agent.stream.worker.AgentStreamRemoteDataRegister; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.CpuMetricService; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.GCMetricService; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.InstanceHeartBeatService; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.MemoryMetricService; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.MemoryPoolMetricService; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ApplicationIDService; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.InstanceIDService; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.TraceSegmentService; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.remote.RemoteModule; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataRegisterService; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ServiceNameService; +import org.apache.skywalking.apm.collector.configuration.ConfigurationModule; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.storage.StorageModule; + +/** + * @author peng-yongsheng + */ +public class AgentStreamModuleProvider extends ModuleProvider { + + @Override public String name() { + return "default"; + } + + @Override public Class module() { + return AgentStreamModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(IApplicationIDService.class, new ApplicationIDService(getManager())); + this.registerServiceImplementation(IInstanceIDService.class, new InstanceIDService(getManager())); + this.registerServiceImplementation(IServiceNameService.class, new ServiceNameService(getManager())); + + this.registerServiceImplementation(ICpuMetricService.class, new CpuMetricService()); + this.registerServiceImplementation(IGCMetricService.class, new GCMetricService()); + this.registerServiceImplementation(IMemoryMetricService.class, new MemoryMetricService()); + this.registerServiceImplementation(IMemoryPoolMetricService.class, new MemoryPoolMetricService()); + this.registerServiceImplementation(IInstanceHeartBeatService.class, new InstanceHeartBeatService()); + + this.registerServiceImplementation(ITraceSegmentService.class, new TraceSegmentService(getManager())); + + BufferFileConfig.Parser parser = new BufferFileConfig.Parser(); + parser.parse(config); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + RemoteDataRegisterService remoteDataRegisterService = getManager().find(RemoteModule.NAME).getService(RemoteDataRegisterService.class); + AgentStreamRemoteDataRegister agentStreamRemoteDataRegister = new AgentStreamRemoteDataRegister(remoteDataRegisterService); + agentStreamRemoteDataRegister.register(); + + AgentStreamBootStartup bootStartup = new AgentStreamBootStartup(getManager()); + bootStartup.start(); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {StorageModule.NAME, CacheModule.NAME, ConfigurationModule.NAME}; + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/IdAutoIncrement.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/IdAutoIncrement.java new file mode 100644 index 000000000000..9d9307b48f14 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/IdAutoIncrement.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream; + +/** + * @author peng-yongsheng + */ +public enum IdAutoIncrement { + INSTANCE; + + public int increment(int min, int max) { + int instanceId; + if (min == max) { + instanceId = -1; + } else if (min + max == 0) { + instanceId = max + 1; + } else if (min + max > 0) { + instanceId = min - 1; + } else if (max < 0) { + instanceId = 1; + } else { + instanceId = max + 1; + } + return instanceId; + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java similarity index 81% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java index a798ec311a41..d20590f1e820 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/BufferFileConfig.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.agent.stream.buffer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.buffer; import java.util.Properties; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/Offset.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/Offset.java similarity index 77% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/Offset.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/Offset.java index b3f54ec692f2..d8922134f5f0 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/Offset.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/Offset.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.agent.stream.buffer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.buffer; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java similarity index 82% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java index f7aef3d8d882..a9714b9891bf 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/OffsetManager.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.agent.stream.buffer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.buffer; import java.io.File; import java.io.FilenameFilter; @@ -24,10 +42,10 @@ import java.io.RandomAccessFile; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.skywalking.apm.collector.agent.stream.util.FileUtils; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.agent.stream.util.FileUtils; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java similarity index 75% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java index 44139c147cd3..056e14207b02 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/SegmentBufferManager.java @@ -16,16 +16,34 @@ * */ -package org.skywalking.apm.collector.agent.stream.buffer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.buffer; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.network.proto.UpstreamSegment; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java similarity index 81% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java index 201825ea1779..8160e33f464c 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/buffer/SegmentBufferReader.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.agent.stream.buffer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.buffer; import com.google.protobuf.CodedOutputStream; import java.io.File; @@ -26,12 +44,12 @@ import java.io.InputStream; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.skywalking.apm.collector.agent.stream.parser.SegmentParse; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.network.proto.UpstreamSegment; +import org.apache.skywalking.apm.collector.agent.stream.parser.SegmentParse; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/GraphDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/GraphDefine.java new file mode 100644 index 000000000000..5a27d82e6937 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/GraphDefine.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.graph; + +/** + * @author peng-yongsheng + */ +public interface GraphDefine { + + +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java new file mode 100644 index 000000000000..e252d6b712b7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.graph; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.CpuMetricPersistenceWorker; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.queue.QueueModule; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.GCMetricPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.InstHeartBeatPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.MemoryMetricPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.jvm.MemoryPoolMetricPersistenceWorker; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; + +/** + * @author peng-yongsheng + */ +public class JvmMetricStreamGraph { + + private final ModuleManager moduleManager; + private final WorkerCreateListener workerCreateListener; + + public JvmMetricStreamGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { + this.moduleManager = moduleManager; + this.workerCreateListener = workerCreateListener; + } + + @SuppressWarnings("unchecked") + public void createGcMetricGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.GC_METRIC_GRAPH_ID, GCMetric.class); + graph.addNode(new GCMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createCpuMetricGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.CPU_METRIC_GRAPH_ID, CpuMetric.class); + graph.addNode(new CpuMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createMemoryMetricGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_METRIC_GRAPH_ID, MemoryMetric.class); + graph.addNode(new MemoryMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createMemoryPoolMetricGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_POOL_METRIC_GRAPH_ID, MemoryPoolMetric.class); + graph.addNode(new MemoryPoolMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createHeartBeatGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.INST_HEART_BEAT_GRAPH_ID, Instance.class); + graph.addNode(new InstHeartBeatPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java new file mode 100644 index 000000000000..02ee710a5aa3 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.graph; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ApplicationRegisterRemoteWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ApplicationRegisterSerialWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.InstanceRegisterRemoteWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.InstanceRegisterSerialWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ServiceNameRegisterRemoteWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ServiceNameRegisterSerialWorker; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.QueueModule; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.remote.RemoteModule; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; + +/** + * @author peng-yongsheng + */ +public class RegisterStreamGraph { + + private final ModuleManager moduleManager; + private final WorkerCreateListener workerCreateListener; + + public RegisterStreamGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { + this.moduleManager = moduleManager; + this.workerCreateListener = workerCreateListener; + } + + @SuppressWarnings("unchecked") + public void createApplicationRegisterGraph() { + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.APPLICATION_REGISTER_GRAPH_ID, Application.class); + graph.addNode(new ApplicationRegisterRemoteWorker.Factory(moduleManager, remoteSenderService, RegisterStreamGraphDefine.APPLICATION_REGISTER_GRAPH_ID).create(workerCreateListener)) + .addNext(new ApplicationRegisterSerialWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createInstanceRegisterGraph() { + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.INSTANCE_REGISTER_GRAPH_ID, Instance.class); + graph.addNode(new InstanceRegisterRemoteWorker.Factory(moduleManager, remoteSenderService, RegisterStreamGraphDefine.INSTANCE_REGISTER_GRAPH_ID).create(workerCreateListener)) + .addNext(new InstanceRegisterSerialWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createServiceNameRegisterGraph() { + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.SERVICE_NAME_REGISTER_GRAPH_ID, ServiceName.class); + graph.addNode(new ServiceNameRegisterRemoteWorker.Factory(moduleManager, remoteSenderService, RegisterStreamGraphDefine.SERVICE_NAME_REGISTER_GRAPH_ID).create(workerCreateListener)) + .addNext(new ServiceNameRegisterSerialWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java new file mode 100644 index 000000000000..d65925f992fa --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.graph; + +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SegmentStandardizationWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentRemoteWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingAggregationWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.segment.SegmentPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntryRemoteWorker; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.queue.QueueModule; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SegmentStandardization; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentAggregationWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingRemoteWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.global.GlobalTracePersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance.InstanceMetricPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.segment.SegmentCostPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntryAggregationWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntryPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricAggregationWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricPersistenceWorker; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricRemoteWorker; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.remote.RemoteModule; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTrace; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.segment.Segment; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; + +/** + * @author peng-yongsheng + */ +public class TraceStreamGraph { + public static final int GLOBAL_TRACE_GRAPH_ID = 300; + public static final int INSTANCE_METRIC_GRAPH_ID = 301; + public static final int APPLICATION_COMPONENT_GRAPH_ID = 302; + public static final int APPLICATION_MAPPING_GRAPH_ID = 303; + public static final int SERVICE_ENTRY_GRAPH_ID = 305; + public static final int SERVICE_REFERENCE_GRAPH_ID = 306; + public static final int SEGMENT_GRAPH_ID = 307; + public static final int SEGMENT_COST_GRAPH_ID = 308; + public static final int SEGMENT_STANDARDIZATION_GRAPH_ID = 309; + + private final ModuleManager moduleManager; + private final WorkerCreateListener workerCreateListener; + + public TraceStreamGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { + this.moduleManager = moduleManager; + this.workerCreateListener = workerCreateListener; + } + + @SuppressWarnings("unchecked") + public void createSegmentStandardizationGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(SEGMENT_STANDARDIZATION_GRAPH_ID, SegmentStandardization.class); + graph.addNode(new SegmentStandardizationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createGlobalTraceGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(GLOBAL_TRACE_GRAPH_ID, GlobalTrace.class); + graph.addNode(new GlobalTracePersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createInstanceMetricGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(INSTANCE_METRIC_GRAPH_ID, InstanceMetric.class); + graph.addNode(new InstanceMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createApplicationComponentGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(APPLICATION_COMPONENT_GRAPH_ID, ApplicationComponent.class); + graph.addNode(new ApplicationComponentAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) + .addNext(new ApplicationComponentRemoteWorker.Factory(moduleManager, remoteSenderService, APPLICATION_COMPONENT_GRAPH_ID).create(workerCreateListener)) + .addNext(new ApplicationComponentPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createApplicationMappingGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(APPLICATION_MAPPING_GRAPH_ID, ApplicationMapping.class); + graph.addNode(new ApplicationMappingAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) + .addNext(new ApplicationMappingRemoteWorker.Factory(moduleManager, remoteSenderService, APPLICATION_MAPPING_GRAPH_ID).create(workerCreateListener)) + .addNext(new ApplicationMappingPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createServiceEntryGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(SERVICE_ENTRY_GRAPH_ID, ServiceEntry.class); + graph.addNode(new ServiceEntryAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) + .addNext(new ServiceEntryRemoteWorker.Factory(moduleManager, remoteSenderService, SERVICE_ENTRY_GRAPH_ID).create(workerCreateListener)) + .addNext(new ServiceEntryPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createServiceReferenceGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(SERVICE_REFERENCE_GRAPH_ID, ServiceReferenceMetric.class); + graph.addNode(new ServiceReferenceMetricAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) + .addNext(new ServiceReferenceMetricRemoteWorker.Factory(moduleManager, remoteSenderService, SERVICE_REFERENCE_GRAPH_ID).create(workerCreateListener)) + .addNext(new ServiceReferenceMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + + createInstanceReferenceGraph(graph); + } + + @SuppressWarnings("unchecked") + private void createInstanceReferenceGraph(Graph graph) { + QueueCreatorService aggregationQueueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + QueueCreatorService persistenceQueueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + +// Node serviceReferenceMetricNode = graph.toFinder().findNode(ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID, ServiceReferenceMetric.class); +// serviceReferenceMetricNode.addNext(new InstanceReferenceMetricAggregationWorker.Factory(moduleManager, aggregationQueueCreatorService).create(workerCreateListener)) +// .addNext(new InstanceReferenceMetricRemoteWorker.Factory(moduleManager, remoteSenderService, SERVICE_REFERENCE_GRAPH_ID).create(workerCreateListener)) +// .addNext(new InstanceReferencePersistenceWorker.Factory(moduleManager, persistenceQueueCreatorService).create(workerCreateListener)); + + createApplicationReferenceMetricGraph(graph); + } + + @SuppressWarnings("unchecked") + private void createApplicationReferenceMetricGraph(Graph graph) { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); + +// Node serviceReferenceMetricNode = graph.toFinder().findNode(ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID, ServiceReferenceMetric.class); +// graph.addNode(new ApplicationReferenceMetricAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) +// .addNext(new ApplicationReferenceMetricRemoteWorker.Factory(moduleManager, remoteSenderService, APPLICATION_REFERENCE_METRIC_GRAPH_ID).create(workerCreateListener)) +// .addNext(new ApplicationReferenceMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createSegmentGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(SEGMENT_GRAPH_ID, Segment.class); + graph.addNode(new SegmentPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } + + @SuppressWarnings("unchecked") + public void createSegmentCostGraph() { + QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(SEGMENT_COST_GRAPH_ID, SegmentCost.class); + graph.addNode(new SegmentCostPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java new file mode 100644 index 000000000000..97aa2a2917a7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; + +/** + * @author peng-yongsheng + */ +public interface EntrySpanListener extends SpanListener { + void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java new file mode 100644 index 000000000000..c88e142a37e0 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; + +/** + * @author peng-yongsheng + */ +public interface ExitSpanListener extends SpanListener { + void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java new file mode 100644 index 000000000000..babccdd706e4 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; + +/** + * @author peng-yongsheng + */ +public interface FirstSpanListener extends SpanListener { + void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java new file mode 100644 index 000000000000..afaa7b04aa66 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +import org.apache.skywalking.apm.network.proto.UniqueId; + +/** + * @author peng-yongsheng + */ +public interface GlobalTraceIdsListener extends SpanListener { + void parseGlobalTraceId(UniqueId uniqueId); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java new file mode 100644 index 000000000000..ffdfd47e337d --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; + +/** + * @author peng-yongsheng + */ +public interface LocalSpanListener extends SpanListener { + void parseLocal(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SegmentParse.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SegmentParse.java new file mode 100644 index 000000000000..248b1ef2dda4 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SegmentParse.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +import com.google.protobuf.InvalidProtocolBufferException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.ReferenceIdExchanger; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SegmentDecorator; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntrySpanListener; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.ReferenceDecorator; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SegmentStandardization; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanIdExchanger; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationReferenceMetricSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.global.GlobalTraceSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance.InstanceMetricSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.segment.SegmentCostSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricSpanListener; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.segment.Segment; +import org.apache.skywalking.apm.network.proto.SpanType; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.UniqueId; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentParse { + + private final Logger logger = LoggerFactory.getLogger(SegmentParse.class); + + private final List spanListeners; + private final ModuleManager moduleManager; + private String segmentId; + private long timeBucket = 0; + + public SegmentParse(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.spanListeners = new ArrayList<>(); + this.spanListeners.add(new ApplicationComponentSpanListener()); + this.spanListeners.add(new ApplicationMappingSpanListener()); + this.spanListeners.add(new ApplicationReferenceMetricSpanListener(moduleManager)); + this.spanListeners.add(new SegmentCostSpanListener(moduleManager)); + this.spanListeners.add(new GlobalTraceSpanListener()); + this.spanListeners.add(new ServiceEntrySpanListener(moduleManager)); + this.spanListeners.add(new ServiceReferenceMetricSpanListener()); + this.spanListeners.add(new InstanceMetricSpanListener()); + } + + public boolean parse(UpstreamSegment segment, Source source) { + try { + List traceIds = segment.getGlobalTraceIdsList(); + TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getSegment()); + + SegmentDecorator segmentDecorator = new SegmentDecorator(segmentObject); + + if (!preBuild(traceIds, segmentDecorator)) { + logger.debug("This segment id exchange not success, write to buffer file, id: {}", segmentId); + + if (source.equals(Source.Agent)) { + writeToBufferFile(segmentId, segment); + } + return false; + } else { + logger.debug("This segment id exchange success, id: {}", segmentId); + notifyListenerToBuild(); + buildSegment(segmentId, segmentDecorator.toByteArray()); + return true; + } + } catch (InvalidProtocolBufferException e) { + logger.error(e.getMessage(), e); + } + return false; + } + + private boolean preBuild(List traceIds, SegmentDecorator segmentDecorator) { + StringBuilder segmentIdBuilder = new StringBuilder(); + + for (int i = 0; i < segmentDecorator.getTraceSegmentId().getIdPartsList().size(); i++) { + if (i == 0) { + segmentIdBuilder.append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i)); + } else { + segmentIdBuilder.append(".").append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i)); + } + } + + segmentId = segmentIdBuilder.toString(); + + for (UniqueId uniqueId : traceIds) { + notifyGlobalsListener(uniqueId); + } + + int applicationId = segmentDecorator.getApplicationId(); + int applicationInstanceId = segmentDecorator.getApplicationInstanceId(); + + int entrySpanCount = 0; + for (int i = 0; i < segmentDecorator.getSpansCount(); i++) { + SpanDecorator spanDecorator = segmentDecorator.getSpans(i); + + if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, applicationId)) { + return false; + } else { + for (int j = 0; j < spanDecorator.getRefsCount(); j++) { + ReferenceDecorator referenceDecorator = spanDecorator.getRefs(j); + if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, applicationId)) { + return false; + } + } + } + + if (SpanType.Entry.equals(spanDecorator.getSpanType())) { + entrySpanCount++; + } + + if (entrySpanCount > 1) { + throw new UnexpectedException("This segment contains multiple entry span."); + } + } + + for (int i = 0; i < segmentDecorator.getSpansCount(); i++) { + SpanDecorator spanDecorator = segmentDecorator.getSpans(i); + + if (spanDecorator.getSpanId() == 0) { + notifyFirstListener(spanDecorator, applicationId, applicationInstanceId, segmentId); + timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + } + + if (SpanType.Exit.equals(spanDecorator.getSpanType())) { + notifyExitListener(spanDecorator, applicationId, applicationInstanceId, segmentId); + } else if (SpanType.Entry.equals(spanDecorator.getSpanType())) { + notifyEntryListener(spanDecorator, applicationId, applicationInstanceId, segmentId); + } else if (SpanType.Local.equals(spanDecorator.getSpanType())) { + notifyLocalListener(spanDecorator, applicationId, applicationInstanceId, segmentId); + } else { + logger.error("span type value was unexpected, span type name: {}", spanDecorator.getSpanType().name()); + } + } + + return true; + } + + private void buildSegment(String id, byte[] dataBinary) { + Segment segment = new Segment(id); + segment.setDataBinary(dataBinary); + segment.setTimeBucket(timeBucket); + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SEGMENT_GRAPH_ID, Segment.class); + graph.start(segment); + } + + private void writeToBufferFile(String id, UpstreamSegment upstreamSegment) { + logger.debug("push to segment buffer write worker, id: {}", id); + SegmentStandardization standardization = new SegmentStandardization(id); + standardization.setUpstreamSegment(upstreamSegment); + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SEGMENT_STANDARDIZATION_GRAPH_ID, SegmentStandardization.class); + graph.start(standardization); + } + + private void notifyListenerToBuild() { + spanListeners.forEach(SpanListener::build); + } + + private void notifyExitListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, + String segmentId) { + for (SpanListener listener : spanListeners) { + if (listener instanceof ExitSpanListener) { + ((ExitSpanListener)listener).parseExit(spanDecorator, applicationId, applicationInstanceId, segmentId); + } + } + } + + private void notifyEntryListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, + String segmentId) { + for (SpanListener listener : spanListeners) { + if (listener instanceof EntrySpanListener) { + ((EntrySpanListener)listener).parseEntry(spanDecorator, applicationId, applicationInstanceId, segmentId); + } + } + } + + private void notifyLocalListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, + String segmentId) { + for (SpanListener listener : spanListeners) { + if (listener instanceof LocalSpanListener) { + ((LocalSpanListener)listener).parseLocal(spanDecorator, applicationId, applicationInstanceId, segmentId); + } + } + } + + private void notifyFirstListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, + String segmentId) { + for (SpanListener listener : spanListeners) { + if (listener instanceof FirstSpanListener) { + ((FirstSpanListener)listener).parseFirst(spanDecorator, applicationId, applicationInstanceId, segmentId); + } + } + } + + private void notifyGlobalsListener(UniqueId uniqueId) { + for (SpanListener listener : spanListeners) { + if (listener instanceof GlobalTraceIdsListener) { + ((GlobalTraceIdsListener)listener).parseGlobalTraceId(uniqueId); + } + } + } + + public enum Source { + Agent, Buffer + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SpanListener.java new file mode 100644 index 000000000000..7fffcd754abc --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/SpanListener.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser; + +/** + * @author peng-yongsheng + */ +public interface SpanListener { + void build(); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java new file mode 100644 index 000000000000..31cb32bb2201 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; + +/** + * @author peng-yongsheng + */ +public interface IdExchanger { + boolean exchange(T standardBuilder, int applicationId); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java similarity index 83% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java index b47569fce147..4ec4a68bcf0a 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceDecorator.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.agent.stream.parser.standardization; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; -import org.skywalking.apm.network.proto.RefType; -import org.skywalking.apm.network.proto.TraceSegmentReference; -import org.skywalking.apm.network.proto.UniqueId; +import org.apache.skywalking.apm.network.proto.RefType; +import org.apache.skywalking.apm.network.proto.TraceSegmentReference; +import org.apache.skywalking.apm.network.proto.UniqueId; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java similarity index 76% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java index 8d0b452ab68b..0e976c069f74 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/ReferenceIdExchanger.java @@ -16,15 +16,33 @@ * */ -package org.skywalking.apm.collector.agent.stream.parser.standardization; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; -import org.skywalking.apm.collector.agent.stream.worker.register.ApplicationIDService; -import org.skywalking.apm.collector.agent.stream.worker.register.ServiceNameService; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ApplicationIDService; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ServiceNameService; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java new file mode 100644 index 000000000000..bd8a6f84f6d1 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; + +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.UniqueId; + +/** + * @author peng-yongsheng + */ +public class SegmentDecorator implements StandardBuilder { + private boolean isOrigin = true; + private final TraceSegmentObject segmentObject; + private TraceSegmentObject.Builder segmentBuilder; + + public SegmentDecorator(TraceSegmentObject segmentObject) { + this.segmentObject = segmentObject; + } + + public int getApplicationId() { + return segmentObject.getApplicationId(); + } + + public int getApplicationInstanceId() { + return segmentObject.getApplicationInstanceId(); + } + + public UniqueId getTraceSegmentId() { + return segmentObject.getTraceSegmentId(); + } + + public int getSpansCount() { + return segmentObject.getSpansCount(); + } + + public SpanDecorator getSpans(int index) { + if (isOrigin) { + return new SpanDecorator(segmentObject.getSpans(index), this); + } else { + return new SpanDecorator(segmentBuilder.getSpansBuilder(index), this); + } + } + + public byte[] toByteArray() { + if (isOrigin) { + return segmentObject.toByteArray(); + } else { + return segmentBuilder.build().toByteArray(); + } + } + + @Override public void toBuilder() { + if (isOrigin) { + this.isOrigin = false; + this.segmentBuilder = segmentObject.toBuilder(); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java new file mode 100644 index 000000000000..c578fa9449b7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; + +import org.apache.skywalking.apm.collector.core.data.EndOfBatchQueueMessage; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +/** + * @author peng-yongsheng + */ +public class SegmentStandardization extends EndOfBatchQueueMessage { + + public SegmentStandardization(String key) { + super(key); + } + + private UpstreamSegment upstreamSegment; + + public UpstreamSegment getUpstreamSegment() { + return upstreamSegment; + } + + public void setUpstreamSegment(UpstreamSegment upstreamSegment) { + this.upstreamSegment = upstreamSegment; + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java new file mode 100644 index 000000000000..b354499be548 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; + +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.agent.stream.buffer.SegmentBufferManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentStandardizationWorker extends AbstractLocalAsyncWorker { + + private final Logger logger = LoggerFactory.getLogger(SegmentStandardizationWorker.class); + + public SegmentStandardizationWorker(ModuleManager moduleManager) { + super(moduleManager); + SegmentBufferManager.INSTANCE.initialize(moduleManager); + } + + @Override public int id() { + return 108; + } + + @Override protected void onWork(SegmentStandardization segmentStandardization) throws WorkerException { + SegmentBufferManager.INSTANCE.writeBuffer(segmentStandardization.getUpstreamSegment()); + } + + public final void flushAndSwitch() { + SegmentBufferManager.INSTANCE.flush(); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public SegmentStandardizationWorker workerInstance(ModuleManager moduleManager) { + SegmentStandardizationWorker standardizationWorker = new SegmentStandardizationWorker(moduleManager); + startTimer(standardizationWorker); + return standardizationWorker; + } + + @Override public int queueSize() { + return 1024; + } + + private void startTimer(SegmentStandardizationWorker standardizationWorker) { + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(standardizationWorker::flushAndSwitch, 10, 3, TimeUnit.SECONDS); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java similarity index 83% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java index de883f15909d..6aa1b527a5d3 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanDecorator.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.agent.stream.parser.standardization; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; -import org.skywalking.apm.network.proto.SpanLayer; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.proto.SpanType; +import org.apache.skywalking.apm.network.proto.SpanLayer; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.SpanType; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java new file mode 100644 index 000000000000..1cb12500f64b --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; + +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ApplicationIDService; +import org.apache.skywalking.apm.collector.agent.stream.worker.register.ServiceNameService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SpanIdExchanger implements IdExchanger { + + private final Logger logger = LoggerFactory.getLogger(SpanIdExchanger.class); + + private static SpanIdExchanger EXCHANGER; + private final ApplicationIDService applicationIDService; + private final ServiceNameService serviceNameService; + + public static SpanIdExchanger getInstance(ModuleManager moduleManager) { + if (EXCHANGER == null) { + EXCHANGER = new SpanIdExchanger(moduleManager); + } + return EXCHANGER; + } + + private SpanIdExchanger(ModuleManager moduleManager) { + this.applicationIDService = new ApplicationIDService(moduleManager); + this.serviceNameService = new ServiceNameService(moduleManager); + } + + @Override public boolean exchange(SpanDecorator standardBuilder, int applicationId) { + if (standardBuilder.getPeerId() == 0 && StringUtils.isNotEmpty(standardBuilder.getPeer())) { + int peerId = applicationIDService.getOrCreate(standardBuilder.getPeer()); + if (peerId == 0) { + logger.debug("peer: {} in application: {} exchange failed", standardBuilder.getPeer(), applicationId); + return false; + } else { + standardBuilder.toBuilder(); + standardBuilder.setPeerId(peerId); + standardBuilder.setPeer(Const.EMPTY_STRING); + } + } + + if (standardBuilder.getOperationNameId() == 0 && StringUtils.isNotEmpty(standardBuilder.getOperationName())) { + int operationNameId = serviceNameService.getOrCreate(applicationId, standardBuilder.getOperationName()); + + if (operationNameId == 0) { + logger.debug("service name: {} from application id: {} exchange failed", standardBuilder.getOperationName(), applicationId); + return false; + } else { + standardBuilder.toBuilder(); + standardBuilder.setOperationNameId(operationNameId); + standardBuilder.setOperationName(Const.EMPTY_STRING); + } + } + return true; + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java new file mode 100644 index 000000000000..201b0b453b1b --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.parser.standardization; + +/** + * @author peng-yongsheng + */ +public interface StandardBuilder { + void toBuilder(); +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/util/FileUtils.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/util/FileUtils.java similarity index 76% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/util/FileUtils.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/util/FileUtils.java index d9a82d8fe48a..61930ac1e3ad 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/util/FileUtils.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/util/FileUtils.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.collector.agent.stream.util; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.util; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; -import org.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.Const; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java new file mode 100644 index 000000000000..e918d0c5076e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker; + +import org.apache.skywalking.apm.collector.remote.service.RemoteDataRegisterService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; + +/** + * @author peng-yongsheng + */ +public class AgentStreamRemoteDataRegister { + + private final RemoteDataRegisterService remoteDataRegisterService; + + public AgentStreamRemoteDataRegister(RemoteDataRegisterService remoteDataRegisterService) { + this.remoteDataRegisterService = remoteDataRegisterService; + } + + public void register() { + remoteDataRegisterService.register(Application.class, Application::new); + remoteDataRegisterService.register(Instance.class, Instance::new); + remoteDataRegisterService.register(ServiceName.class, ServiceName::new); + + remoteDataRegisterService.register(ApplicationComponent.class, ApplicationComponent::new); + remoteDataRegisterService.register(ApplicationMapping.class, ApplicationMapping::new); + remoteDataRegisterService.register(ApplicationReferenceMetric.class, ApplicationReferenceMetric::new); + remoteDataRegisterService.register(ServiceEntry.class, ServiceEntry::new); + remoteDataRegisterService.register(ServiceReferenceMetric.class, ServiceReferenceMetric::new); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java new file mode 100644 index 000000000000..8ed0ae96d96a --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class CpuMetricPersistenceWorker extends PersistenceWorker { + + public CpuMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 115; + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(ICpuMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public CpuMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new CpuMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java new file mode 100644 index 000000000000..7a1f5e46f3de --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class CpuMetricService implements ICpuMetricService { + + private final Logger logger = LoggerFactory.getLogger(CpuMetricService.class); + + private Graph cpuMetricGraph; + + private Graph getCpuMetricGraph() { + if (ObjectUtils.isEmpty(cpuMetricGraph)) { + cpuMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.CPU_METRIC_GRAPH_ID, CpuMetric.class); + } + return cpuMetricGraph; + } + + @Override public void send(int instanceId, long timeBucket, double usagePercent) { + CpuMetric cpuMetric = new CpuMetric(timeBucket + Const.ID_SPLIT + instanceId); + cpuMetric.setInstanceId(instanceId); + cpuMetric.setUsagePercent(usagePercent); + cpuMetric.setTimeBucket(timeBucket); + + logger.debug("push to cpu metric graph, id: {}", cpuMetric.getId()); + getCpuMetricGraph().start(cpuMetric); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java new file mode 100644 index 000000000000..9a579c44cfe1 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class GCMetricPersistenceWorker extends PersistenceWorker { + + public GCMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 112; + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IGCMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public GCMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new GCMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java new file mode 100644 index 000000000000..21c24236ae90 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GCMetricService implements IGCMetricService { + + private final Logger logger = LoggerFactory.getLogger(GCMetricService.class); + + private Graph gcMetricGraph; + + private Graph getGcMetricGraph() { + if (ObjectUtils.isEmpty(gcMetricGraph)) { + gcMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.GC_METRIC_GRAPH_ID, GCMetric.class); + } + return gcMetricGraph; + } + + @Override public void send(int instanceId, long timeBucket, int phraseValue, long count, long time) { + GCMetric gcMetric = new GCMetric(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(phraseValue)); + gcMetric.setInstanceId(instanceId); + gcMetric.setPhrase(phraseValue); + gcMetric.setCount(count); + gcMetric.setTime(time); + gcMetric.setTimeBucket(timeBucket); + + logger.debug("push to gc metric graph, id: {}", gcMetric.getId()); + getGcMetricGraph().start(gcMetric); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java new file mode 100644 index 000000000000..afda90e2825a --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class InstHeartBeatPersistenceWorker extends PersistenceWorker { + + public InstHeartBeatPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 113; + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IInstanceHeartBeatPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public InstHeartBeatPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new InstHeartBeatPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java new file mode 100644 index 000000000000..7891f1655f5f --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceHeartBeatService implements IInstanceHeartBeatService { + + private final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatService.class); + + private Graph heartBeatGraph; + + private Graph getHeartBeatGraph() { + if (ObjectUtils.isEmpty(heartBeatGraph)) { + this.heartBeatGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.INST_HEART_BEAT_GRAPH_ID, Instance.class); + } + return heartBeatGraph; + } + + @Override public void send(int instanceId, long heartBeatTime) { + Instance instance = new Instance(String.valueOf(instanceId)); + instance.setHeartBeatTime(TimeBucketUtils.INSTANCE.getSecondTimeBucket(heartBeatTime)); + instance.setInstanceId(instanceId); + + logger.debug("push to instance heart beat persistence worker, id: {}", instance.getId()); + getHeartBeatGraph().start(instance); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java new file mode 100644 index 000000000000..9295d3ef7c3d --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetric; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricPersistenceWorker extends PersistenceWorker { + + public MemoryMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 119; + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IMemoryMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public MemoryMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new MemoryMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java new file mode 100644 index 000000000000..c64d919c530c --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricService implements IMemoryMetricService { + + private final Logger logger = LoggerFactory.getLogger(MemoryMetricService.class); + + private Graph memoryMetricGraph; + + private Graph getMemoryMetricGraph() { + if (ObjectUtils.isEmpty(memoryMetricGraph)) { + this.memoryMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_METRIC_GRAPH_ID, MemoryMetric.class); + } + return memoryMetricGraph; + } + + @Override + public void send(int instanceId, long timeBucket, boolean isHeap, long init, long max, long used, long commited) { + MemoryMetric memoryMetric = new MemoryMetric(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(isHeap)); + memoryMetric.setInstanceId(instanceId); + memoryMetric.setIsHeap(isHeap); + memoryMetric.setInit(init); + memoryMetric.setMax(max); + memoryMetric.setUsed(used); + memoryMetric.setCommitted(commited); + memoryMetric.setTimeBucket(timeBucket); + + logger.debug("push to memory metric graph, id: {}", memoryMetric.getId()); + getMemoryMetricGraph().start(memoryMetric); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java new file mode 100644 index 000000000000..981dd6f2c777 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricPersistenceWorker extends PersistenceWorker { + + @Override public int id() { + return 122; + } + + public MemoryPoolMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IMemoryPoolMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public MemoryPoolMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new MemoryPoolMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java new file mode 100644 index 000000000000..cb9c12a6cc1a --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.jvm; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricService implements IMemoryPoolMetricService { + + private final Logger logger = LoggerFactory.getLogger(MemoryPoolMetricService.class); + + private Graph memoryPoolMetricGraph; + + private Graph getMemoryPoolMetricGraph() { + if (ObjectUtils.isEmpty(memoryPoolMetricGraph)) { + this.memoryPoolMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_POOL_METRIC_GRAPH_ID, MemoryPoolMetric.class); + } + return memoryPoolMetricGraph; + } + + @Override + public void send(int instanceId, long timeBucket, int poolType, long init, long max, long used, long commited) { + MemoryPoolMetric memoryPoolMetric = new MemoryPoolMetric(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(poolType)); + memoryPoolMetric.setInstanceId(instanceId); + memoryPoolMetric.setPoolType(poolType); + memoryPoolMetric.setInit(init); + memoryPoolMetric.setMax(max); + memoryPoolMetric.setUsed(used); + memoryPoolMetric.setCommitted(commited); + memoryPoolMetric.setTimeBucket(timeBucket); + + logger.debug("push to memory pool metric graph, id: {}", memoryPoolMetric.getId()); + getMemoryPoolMetricGraph().start(memoryPoolMetric); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java new file mode 100644 index 000000000000..caceb7a7da11 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationIDService implements IApplicationIDService { + + private final Logger logger = LoggerFactory.getLogger(ApplicationIDService.class); + + private final ModuleManager moduleManager; + private ApplicationCacheService applicationCacheService; + private Graph applicationRegisterGraph; + + public ApplicationIDService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private Graph getApplicationRegisterGraph() { + if (ObjectUtils.isEmpty(applicationRegisterGraph)) { + this.applicationRegisterGraph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.APPLICATION_REGISTER_GRAPH_ID, Application.class); + } + return this.applicationRegisterGraph; + } + + private ApplicationCacheService getApplicationCacheService() { + if (ObjectUtils.isEmpty(applicationCacheService)) { + this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + return applicationCacheService; + } + + public int getOrCreate(String applicationCode) { + int applicationId = getApplicationCacheService().get(applicationCode); + + if (applicationId == 0) { + Application application = new Application(applicationCode); + application.setApplicationCode(applicationCode); + application.setApplicationId(0); + + getApplicationRegisterGraph().start(application); + } + return applicationId; + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java new file mode 100644 index 000000000000..82ffc96038a4 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationRegisterRemoteWorker extends AbstractRemoteWorker { + + private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterRemoteWorker.class); + + public ApplicationRegisterRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10006; + } + + @Override protected void onWork(Application message) throws WorkerException { + logger.debug("application code: {}", message.getApplicationCode()); + onNext(message); + } + + @Override public Selector selector() { + return Selector.ForeverFirst; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ApplicationRegisterRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationRegisterRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java new file mode 100644 index 000000000000..b6776e3f35ce --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.agent.stream.IdAutoIncrement; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationRegisterSerialWorker extends AbstractLocalAsyncWorker { + + private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterSerialWorker.class); + + private final IApplicationRegisterDAO applicationRegisterDAO; + private final ApplicationCacheService applicationCacheService; + + public ApplicationRegisterSerialWorker(ModuleManager moduleManager) { + super(moduleManager); + this.applicationRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IApplicationRegisterDAO.class); + this.applicationCacheService = getModuleManager().find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + + @Override public int id() { + return 101; + } + + @Override protected void onWork(Application application) throws WorkerException { + logger.debug("register application, application code: {}", application.getApplicationCode()); + int applicationId = applicationCacheService.get(application.getApplicationCode()); + + if (applicationId == 0) { + Application newApplication; + int min = applicationRegisterDAO.getMinApplicationId(); + if (min == 0) { + Application userApplication = new Application(String.valueOf(Const.USER_ID)); + userApplication.setApplicationCode(Const.USER_CODE); + userApplication.setApplicationId(Const.USER_ID); + applicationRegisterDAO.save(userApplication); + + newApplication = new Application("-1"); + newApplication.setApplicationId(-1); + newApplication.setApplicationCode(application.getApplicationCode()); + } else { + int max = applicationRegisterDAO.getMaxApplicationId(); + applicationId = IdAutoIncrement.INSTANCE.increment(min, max); + + newApplication = new Application(String.valueOf(applicationId)); + newApplication.setApplicationId(applicationId); + newApplication.setApplicationCode(application.getApplicationCode()); + } + applicationRegisterDAO.save(newApplication); + } + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationRegisterSerialWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationRegisterSerialWorker(moduleManager); + } + + @Override public int queueSize() { + return 256; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java new file mode 100644 index 000000000000..d595993d3380 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceIDService implements IInstanceIDService { + + private final Logger logger = LoggerFactory.getLogger(InstanceIDService.class); + + private final ModuleManager moduleManager; + private InstanceCacheService instanceCacheService; + private Graph instanceRegisterGraph; + private IInstanceRegisterDAO instanceRegisterDAO; + + public InstanceIDService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private InstanceCacheService getInstanceCacheService() { + if (ObjectUtils.isEmpty(instanceCacheService)) { + instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class); + } + return instanceCacheService; + } + + private Graph getInstanceRegisterGraph() { + if (ObjectUtils.isEmpty(instanceRegisterGraph)) { + this.instanceRegisterGraph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.INSTANCE_REGISTER_GRAPH_ID, Instance.class); + } + return instanceRegisterGraph; + } + + private IInstanceRegisterDAO getInstanceRegisterDAO() { + if (ObjectUtils.isEmpty(instanceRegisterDAO)) { + instanceRegisterDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceRegisterDAO.class); + } + return instanceRegisterDAO; + } + + public int getOrCreate(int applicationId, String agentUUID, long registerTime, String osInfo) { + logger.debug("get or create instance id, application id: {}, agentUUID: {}, registerTime: {}, osInfo: {}", applicationId, agentUUID, registerTime, osInfo); + int instanceId = getInstanceCacheService().getInstanceId(applicationId, agentUUID); + + if (instanceId == 0) { + Instance instance = new Instance("0"); + instance.setApplicationId(applicationId); + instance.setAgentUUID(agentUUID); + instance.setRegisterTime(registerTime); + instance.setHeartBeatTime(registerTime); + instance.setInstanceId(0); + instance.setOsInfo(osInfo); + + getInstanceRegisterGraph().start(instance); + } + return instanceId; + } + + public void recover(int instanceId, int applicationId, long registerTime, String osInfo) { + logger.debug("instance recover, instance id: {}, application id: {}, register time: {}", instanceId, applicationId, registerTime); + Instance instance = new Instance(String.valueOf(instanceId)); + instance.setApplicationId(applicationId); + instance.setAgentUUID(""); + instance.setRegisterTime(registerTime); + instance.setHeartBeatTime(registerTime); + instance.setInstanceId(instanceId); + instance.setOsInfo(osInfo); + + getInstanceRegisterDAO().save(instance); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java new file mode 100644 index 000000000000..969688b067a9 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceRegisterRemoteWorker extends AbstractRemoteWorker { + + private final Logger logger = LoggerFactory.getLogger(InstanceRegisterRemoteWorker.class); + + @Override public int id() { + return 10001; + } + + InstanceRegisterRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override protected void onWork(Instance instance) throws WorkerException { + logger.debug("application id: {}, agentUUID: {}, register time: {}", instance.getApplicationId(), instance.getAgentUUID(), instance.getRegisterTime()); + onNext(instance); + } + + @Override public Selector selector() { + return Selector.ForeverFirst; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public InstanceRegisterRemoteWorker workerInstance(ModuleManager moduleManager) { + return new InstanceRegisterRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java new file mode 100644 index 000000000000..c0068a54d0d7 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceRegisterSerialWorker extends AbstractLocalAsyncWorker { + + private final Logger logger = LoggerFactory.getLogger(InstanceRegisterSerialWorker.class); + + private final InstanceCacheService instanceCacheService; + private final IInstanceRegisterDAO instanceRegisterDAO; + + public InstanceRegisterSerialWorker(ModuleManager moduleManager) { + super(moduleManager); + this.instanceCacheService = getModuleManager().find(CacheModule.NAME).getService(InstanceCacheService.class); + this.instanceRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IInstanceRegisterDAO.class); + } + + @Override public int id() { + return 102; + } + + @Override protected void onWork(Instance instance) throws WorkerException { + logger.debug("register instance, application id: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID()); + int instanceId = instanceCacheService.getInstanceId(instance.getApplicationId(), instance.getAgentUUID()); + if (instanceId == 0) { + Instance newInstance; + + int min = instanceRegisterDAO.getMinInstanceId(); + int max = instanceRegisterDAO.getMaxInstanceId(); + if (min == 0 && max == 0) { + newInstance = new Instance("1"); + newInstance.setInstanceId(1); + newInstance.setApplicationId(instance.getApplicationId()); + newInstance.setAgentUUID(instance.getAgentUUID()); + newInstance.setHeartBeatTime(instance.getHeartBeatTime()); + newInstance.setOsInfo(instance.getOsInfo()); + newInstance.setRegisterTime(instance.getRegisterTime()); + } else { + newInstance = new Instance(String.valueOf(max + 1)); + newInstance.setInstanceId(max + 1); + newInstance.setApplicationId(instance.getApplicationId()); + newInstance.setAgentUUID(instance.getAgentUUID()); + newInstance.setHeartBeatTime(instance.getHeartBeatTime()); + newInstance.setOsInfo(instance.getOsInfo()); + newInstance.setRegisterTime(instance.getRegisterTime()); + } + instanceRegisterDAO.save(newInstance); + } + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public InstanceRegisterSerialWorker workerInstance(ModuleManager moduleManager) { + return new InstanceRegisterSerialWorker(moduleManager); + } + + @Override public int queueSize() { + return 256; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java new file mode 100644 index 000000000000..c2144e815cb4 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameRegisterRemoteWorker extends AbstractRemoteWorker { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameRegisterRemoteWorker.class); + + public ServiceNameRegisterRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10000; + } + + @Override protected void onWork(ServiceName serviceName) throws WorkerException { + onNext(serviceName); + } + + @Override public Selector selector() { + return Selector.ForeverFirst; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ServiceNameRegisterRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ServiceNameRegisterRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java new file mode 100644 index 000000000000..39d247002c0d --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.agent.stream.IdAutoIncrement; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameRegisterSerialWorker.class); + + private final IServiceNameRegisterDAO serviceNameRegisterDAO; + private final ServiceIdCacheService serviceIdCacheService; + + public ServiceNameRegisterSerialWorker(ModuleManager moduleManager) { + super(moduleManager); + this.serviceNameRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IServiceNameRegisterDAO.class); + this.serviceIdCacheService = getModuleManager().find(CacheModule.NAME).getService(ServiceIdCacheService.class); + } + + @Override public int id() { + return 100; + } + + @Override protected void onWork(ServiceName serviceName) throws WorkerException { + logger.debug("register service name: {}, application id: {}", serviceName.getServiceName(), serviceName.getApplicationId()); + int serviceId = serviceIdCacheService.get(serviceName.getApplicationId(), serviceName.getServiceName()); + if (serviceId == 0) { + ServiceName newServiceName; + + int min = serviceNameRegisterDAO.getMinServiceId(); + if (min == 0) { + ServiceName noneServiceName = new ServiceName("1"); + noneServiceName.setApplicationId(0); + noneServiceName.setServiceId(Const.NONE_SERVICE_ID); + noneServiceName.setServiceName(Const.NONE_SERVICE_NAME); + serviceNameRegisterDAO.save(noneServiceName); + + newServiceName = new ServiceName("-1"); + newServiceName.setApplicationId(serviceName.getApplicationId()); + newServiceName.setServiceId(-1); + newServiceName.setServiceName(serviceName.getServiceName()); + } else { + int max = serviceNameRegisterDAO.getMaxServiceId(); + serviceId = IdAutoIncrement.INSTANCE.increment(min, max); + + newServiceName = new ServiceName(String.valueOf(serviceId)); + newServiceName.setApplicationId(serviceName.getApplicationId()); + newServiceName.setServiceId(serviceId); + newServiceName.setServiceName(serviceName.getServiceName()); + } + serviceNameRegisterDAO.save(newServiceName); + } + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceNameRegisterSerialWorker workerInstance(ModuleManager moduleManager) { + return new ServiceNameRegisterSerialWorker(moduleManager); + } + + @Override public int queueSize() { + return 256; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java new file mode 100644 index 000000000000..2fab8c7e5963 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.register; + +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; +import org.apache.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; +import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameService implements IServiceNameService { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameService.class); + + private final ModuleManager moduleManager; + private ServiceIdCacheService serviceIdCacheService; + private Graph serviceNameRegisterGraph; + + public ServiceNameService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private ServiceIdCacheService getServiceIdCacheService() { + if (ObjectUtils.isEmpty(serviceIdCacheService)) { + serviceIdCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceIdCacheService.class); + } + return serviceIdCacheService; + } + + private Graph getServiceNameRegisterGraph() { + if (ObjectUtils.isEmpty(serviceNameRegisterGraph)) { + this.serviceNameRegisterGraph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.SERVICE_NAME_REGISTER_GRAPH_ID, ServiceName.class); + } + return serviceNameRegisterGraph; + } + + public int getOrCreate(int applicationId, String serviceName) { + int serviceId = getServiceIdCacheService().get(applicationId, serviceName); + + if (serviceId == 0) { + ServiceName service = new ServiceName("0"); + service.setApplicationId(applicationId); + service.setServiceName(serviceName); + service.setServiceId(0); + + getServiceNameRegisterGraph().start(service); + } + return serviceId; + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java new file mode 100644 index 000000000000..292d81866526 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace; + +import org.apache.skywalking.apm.collector.agent.stream.parser.SegmentParse; +import org.apache.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +/** + * @author peng-yongsheng + */ +public class TraceSegmentService implements ITraceSegmentService { + + private final ModuleManager moduleManager; + + public TraceSegmentService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + public void send(UpstreamSegment segment) { + SegmentParse segmentParse = new SegmentParse(moduleManager); + segmentParse.parse(segment, SegmentParse.Source.Agent); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java new file mode 100644 index 000000000000..0ca67376df63 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentAggregationWorker extends AggregationWorker { + + public ApplicationComponentAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 104; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationComponentAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationComponentAggregationWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java new file mode 100644 index 000000000000..eb098723d5cf --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentPersistenceWorker extends PersistenceWorker { + + public ApplicationComponentPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ApplicationComponentPersistenceWorker.class.hashCode(); + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IApplicationComponentPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationComponentPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationComponentPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java new file mode 100644 index 000000000000..8c19df69de9b --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentRemoteWorker extends AbstractRemoteWorker { + + ApplicationComponentRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10005; + } + + @Override protected void onWork(ApplicationComponent applicationComponent) throws WorkerException { + onNext(applicationComponent); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ApplicationComponentRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationComponentRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java new file mode 100644 index 000000000000..8e559be55c7f --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentSpanListener implements EntrySpanListener, ExitSpanListener, FirstSpanListener { + + private final Logger logger = LoggerFactory.getLogger(ApplicationComponentSpanListener.class); + + private List applicationComponents = new ArrayList<>(); + private long timeBucket; + + @Override + public void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { + ApplicationComponent applicationComponent = new ApplicationComponent(Const.EMPTY_STRING); + applicationComponent.setComponentId(spanDecorator.getComponentId()); + applicationComponent.setPeerId(spanDecorator.getPeerId()); + + String id = String.valueOf(applicationComponent.getComponentId()) + Const.ID_SPLIT + applicationComponent.getPeerId(); + + applicationComponent.setId(id); + applicationComponents.add(applicationComponent); + } + + @Override + public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + ApplicationComponent applicationComponent = new ApplicationComponent(Const.EMPTY_STRING); + applicationComponent.setComponentId(spanDecorator.getComponentId()); + applicationComponent.setPeerId(applicationId); + + String id = String.valueOf(applicationComponent.getComponentId()) + Const.ID_SPLIT + String.valueOf(applicationId); + applicationComponent.setId(id); + + applicationComponents.add(applicationComponent); + } + + @Override + public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + } + + @Override public void build() { + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.APPLICATION_COMPONENT_GRAPH_ID, ApplicationComponent.class); + + applicationComponents.forEach(applicationComponent -> { + applicationComponent.setId(timeBucket + Const.ID_SPLIT + applicationComponent.getId()); + applicationComponent.setTimeBucket(timeBucket); + graph.start(applicationComponent); + }); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java new file mode 100644 index 000000000000..1c9d58e41552 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingAggregationWorker extends AggregationWorker { + + ApplicationMappingAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 105; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationMappingAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationMappingAggregationWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java new file mode 100644 index 000000000000..beb4b364f4a5 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingPersistenceWorker extends PersistenceWorker { + + ApplicationMappingPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ApplicationMappingPersistenceWorker.class.hashCode(); + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IApplicationMappingPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationMappingPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationMappingPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java new file mode 100644 index 000000000000..f40194cf4978 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingRemoteWorker extends AbstractRemoteWorker { + + ApplicationMappingRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10007; + } + + @Override protected void onWork(ApplicationMapping applicationMapping) throws WorkerException { + onNext(applicationMapping); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ApplicationMappingRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationMappingRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java new file mode 100644 index 000000000000..df2e04cd719e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingSpanListener implements FirstSpanListener, EntrySpanListener { + + private final Logger logger = LoggerFactory.getLogger(ApplicationMappingSpanListener.class); + + private List applicationMappings = new LinkedList<>(); + private long timeBucket; + + @Override public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { + logger.debug("node mapping listener parse reference"); + if (spanDecorator.getRefsCount() > 0) { + ApplicationMapping applicationMapping = new ApplicationMapping(Const.EMPTY_STRING); + applicationMapping.setApplicationId(applicationId); + applicationMapping.setAddressId(spanDecorator.getRefs(0).getNetworkAddressId()); + String id = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(applicationMapping.getAddressId()); + applicationMapping.setId(id); + applicationMappings.add(applicationMapping); + } + } + + @Override + public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + } + + @Override public void build() { + logger.debug("node mapping listener build"); + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.APPLICATION_MAPPING_GRAPH_ID, ApplicationMapping.class); + applicationMappings.forEach(applicationMapping -> { + applicationMapping.setId(timeBucket + Const.ID_SPLIT + applicationMapping.getId()); + applicationMapping.setTimeBucket(timeBucket); + logger.debug("push to node mapping aggregation worker, id: {}", applicationMapping.getId()); + graph.start(applicationMapping); + }); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java new file mode 100644 index 000000000000..4891bda365a5 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationMetricAggregationWorker extends AggregationWorker { + + public ApplicationMetricAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ApplicationMetricAggregationWorker.class.hashCode(); + } + + @Override protected ApplicationMetric transform(ApplicationReferenceMetric applicationReferenceMetric) { + Integer applicationId = applicationReferenceMetric.getBehindApplicationId(); + Long timeBucket = applicationReferenceMetric.getTimeBucket(); + ApplicationMetric applicationMetric = new ApplicationMetric(String.valueOf(timeBucket) + Const.ID_SPLIT + String.valueOf(applicationId)); + applicationMetric.setApplicationId(applicationId); +// applicationMetric.setCalls(applicationReferenceMetric.getCalls()); +// applicationMetric.setErrorCalls(applicationReferenceMetric.getErrorCalls()); +// applicationMetric.setDurationSum(applicationReferenceMetric.getDurationSum()); +// applicationMetric.setErrorDurationSum(applicationReferenceMetric.getErrorDurationSum()); + applicationMetric.setSatisfiedCount(applicationReferenceMetric.getSatisfiedCount()); + applicationMetric.setToleratingCount(applicationReferenceMetric.getToleratingCount()); + applicationMetric.setFrustratedCount(applicationReferenceMetric.getFrustratedCount()); + applicationMetric.setTimeBucket(timeBucket); + + return applicationMetric; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, + QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationMetricAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationMetricAggregationWorker(moduleManager); + } + + @Override public int queueSize() { + return 256; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java new file mode 100644 index 000000000000..9ecafe57e963 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationMetricPersistenceWorker extends PersistenceWorker { + + public ApplicationMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 111; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IApplicationMetricPersistenceDAO.class); + } + + @Override protected boolean needMergeDBData() { + return true; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java new file mode 100644 index 000000000000..cd7b032f23cb --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class ApplicationMetricRemoteWorker extends AbstractRemoteWorker { + + public ApplicationMetricRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10002; + } + + @Override protected void onWork(ApplicationMetric applicationMetric) throws WorkerException { + onNext(applicationMetric); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ApplicationMetricRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationMetricRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java new file mode 100644 index 000000000000..772e02ac0f72 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.ApplicationGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationReferenceMetricAggregationWorker extends AggregationWorker { + + private final InstanceCacheService instanceCacheService; + + public ApplicationReferenceMetricAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class); + } + + @Override public int id() { + return ApplicationGraphNodeIdDefine.APPLICATION_REFERENCE_METRIC_AGGREGATION_NODE_ID; + } + + @Override protected ApplicationReferenceMetric transform(InstanceReferenceMetric instanceReferenceMetric) { + Integer frontApplicationId = instanceCacheService.get(instanceReferenceMetric.getFrontInstanceId()); + Integer behindApplicationId = instanceCacheService.get(instanceReferenceMetric.getBehindInstanceId()); + + String id = instanceReferenceMetric.getTimeBucket() + Const.ID_SPLIT + frontApplicationId + Const.ID_SPLIT + behindApplicationId; + + ApplicationReferenceMetric applicationReferenceMetric = new ApplicationReferenceMetric(id); + applicationReferenceMetric.setFrontApplicationId(frontApplicationId); + applicationReferenceMetric.setBehindApplicationId(behindApplicationId); + + applicationReferenceMetric.setTransactionCalls(instanceReferenceMetric.getTransactionCalls()); + applicationReferenceMetric.setTransactionErrorCalls(instanceReferenceMetric.getTransactionErrorCalls()); + applicationReferenceMetric.setTransactionDurationSum(instanceReferenceMetric.getTransactionDurationSum()); + applicationReferenceMetric.setTransactionErrorDurationSum(instanceReferenceMetric.getTransactionErrorDurationSum()); + + applicationReferenceMetric.setBusinessTransactionCalls(instanceReferenceMetric.getBusinessTransactionCalls()); + applicationReferenceMetric.setBusinessTransactionErrorCalls(instanceReferenceMetric.getBusinessTransactionErrorCalls()); + applicationReferenceMetric.setBusinessTransactionDurationSum(instanceReferenceMetric.getBusinessTransactionDurationSum()); + applicationReferenceMetric.setBusinessTransactionErrorDurationSum(instanceReferenceMetric.getBusinessTransactionErrorDurationSum()); + + applicationReferenceMetric.setMqTransactionCalls(instanceReferenceMetric.getMqTransactionCalls()); + applicationReferenceMetric.setMqTransactionErrorCalls(instanceReferenceMetric.getMqTransactionErrorCalls()); + applicationReferenceMetric.setMqTransactionDurationSum(instanceReferenceMetric.getMqTransactionDurationSum()); + applicationReferenceMetric.setMqTransactionErrorDurationSum(instanceReferenceMetric.getMqTransactionErrorDurationSum()); + + return applicationReferenceMetric; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, + QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationReferenceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationReferenceMetricAggregationWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java new file mode 100644 index 000000000000..1535cd0a8e93 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.ApplicationGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class ApplicationReferenceMetricPersistenceWorker extends PersistenceWorker { + + public ApplicationReferenceMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ApplicationGraphNodeIdDefine.APPLICATION_REFERENCE_METRIC_PERSISTENCE_NODE_ID; + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IApplicationReferenceMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, + QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ApplicationReferenceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationReferenceMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java new file mode 100644 index 000000000000..f0476a0acb61 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.ApplicationGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; + +/** + * @author peng-yongsheng + */ +public class ApplicationReferenceMetricRemoteWorker extends AbstractRemoteWorker { + + ApplicationReferenceMetricRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ApplicationGraphNodeIdDefine.APPLICATION_REFERENCE_METRIC_REMOTE_NODE_ID; + } + + @Override protected void onWork(ApplicationReferenceMetric applicationReferenceMetric) throws WorkerException { + onNext(applicationReferenceMetric); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ApplicationReferenceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ApplicationReferenceMetricRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java similarity index 77% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java index 2d84c0e0aa68..75eeb2286fec 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricSpanListener.java @@ -16,23 +16,41 @@ * */ -package org.skywalking.apm.collector.agent.stream.worker.trace.application; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.application; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.configuration.ConfigurationModule; -import org.skywalking.apm.collector.configuration.service.IApdexThresholdService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ApdexThresholdUtils; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.configuration.ConfigurationModule; +import org.apache.skywalking.apm.collector.configuration.service.IApdexThresholdService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ApdexThresholdUtils; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java new file mode 100644 index 000000000000..ee528e01957a --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.global; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTrace; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; + +/** + * @author peng-yongsheng + */ +public class GlobalTracePersistenceWorker extends PersistenceWorker { + + public GlobalTracePersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 120; + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IGlobalTracePersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public GlobalTracePersistenceWorker workerInstance(ModuleManager moduleManager) { + return new GlobalTracePersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java new file mode 100644 index 000000000000..6ee90d56430a --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.global; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTrace; +import org.apache.skywalking.apm.collector.agent.stream.parser.GlobalTraceIdsListener; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.network.proto.UniqueId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceSpanListener implements FirstSpanListener, GlobalTraceIdsListener { + + private final Logger logger = LoggerFactory.getLogger(GlobalTraceSpanListener.class); + + private List globalTraceIds = new ArrayList<>(); + private String segmentId; + private long timeBucket; + + @Override + public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + this.timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + this.segmentId = segmentId; + } + + @Override public void parseGlobalTraceId(UniqueId uniqueId) { + StringBuilder globalTraceIdBuilder = new StringBuilder(); + for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) { + if (i == 0) { + globalTraceIdBuilder.append(uniqueId.getIdPartsList().get(i)); + } else { + globalTraceIdBuilder.append(".").append(uniqueId.getIdPartsList().get(i)); + } + } + globalTraceIds.add(globalTraceIdBuilder.toString()); + } + + @Override public void build() { + logger.debug("global trace listener build"); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.GLOBAL_TRACE_GRAPH_ID, GlobalTrace.class); + for (String globalTraceId : globalTraceIds) { + GlobalTrace globalTrace = new GlobalTrace(segmentId + Const.ID_SPLIT + globalTraceId); + globalTrace.setGlobalTraceId(globalTraceId); + globalTrace.setSegmentId(segmentId); + globalTrace.setTimeBucket(timeBucket); + graph.start(globalTrace); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java new file mode 100644 index 000000000000..1286d4194aa0 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricPersistenceWorker extends PersistenceWorker { + + public InstanceMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 118; + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IInstanceMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public InstanceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new InstanceMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java new file mode 100644 index 000000000000..809d85cbf1a3 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance; + +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricSpanListener implements EntrySpanListener, FirstSpanListener { + + private final Logger logger = LoggerFactory.getLogger(InstanceMetricSpanListener.class); + + private int applicationId; + private int instanceId; + private boolean isError; + private long duration; + private long timeBucket; + + @Override + public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + } + + @Override + public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + this.applicationId = applicationId; + this.instanceId = instanceId; + this.isError = spanDecorator.getIsError(); + this.duration = spanDecorator.getEndTime() - spanDecorator.getStartTime(); + timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanDecorator.getStartTime()); + } + + @Override public void build() { + InstanceMetric instanceMetric = new InstanceMetric(timeBucket + Const.ID_SPLIT + instanceId); + instanceMetric.setApplicationId(applicationId); + instanceMetric.setInstanceId(instanceId); + instanceMetric.setTransactionCalls(1L); + instanceMetric.setTransactionDurationSum(duration); + + if (isError) { + instanceMetric.setTransactionErrorCalls(1L); + instanceMetric.setTransactionErrorDurationSum(duration); + } + instanceMetric.setTimeBucket(timeBucket); + + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.INSTANCE_METRIC_GRAPH_ID, InstanceMetric.class); + graph.start(instanceMetric); + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java new file mode 100644 index 000000000000..278a23d2eb73 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.InstanceGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class InstanceReferenceMetricAggregationWorker extends AggregationWorker { + + public InstanceReferenceMetricAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return InstanceGraphNodeIdDefine.INSTANCE_REFERENCE_METRIC_AGGREGATION_NODE_ID; + } + + @Override protected InstanceReferenceMetric transform(ServiceReferenceMetric serviceReferenceMetric) { + String id = serviceReferenceMetric.getTimeBucket() + Const.ID_SPLIT + serviceReferenceMetric.getFrontInstanceId() + Const.ID_SPLIT + serviceReferenceMetric.getBehindInstanceId(); + + InstanceReferenceMetric instanceReferenceMetric = new InstanceReferenceMetric(id); + instanceReferenceMetric.setFrontInstanceId(serviceReferenceMetric.getFrontInstanceId()); + instanceReferenceMetric.setBehindInstanceId(serviceReferenceMetric.getBehindInstanceId()); + + instanceReferenceMetric.setTransactionCalls(serviceReferenceMetric.getTransactionCalls()); + instanceReferenceMetric.setTransactionErrorCalls(serviceReferenceMetric.getTransactionErrorCalls()); + instanceReferenceMetric.setTransactionDurationSum(serviceReferenceMetric.getTransactionDurationSum()); + instanceReferenceMetric.setTransactionErrorDurationSum(serviceReferenceMetric.getTransactionErrorDurationSum()); + + instanceReferenceMetric.setBusinessTransactionCalls(serviceReferenceMetric.getBusinessTransactionCalls()); + instanceReferenceMetric.setBusinessTransactionErrorCalls(instanceReferenceMetric.getBusinessTransactionErrorCalls()); + instanceReferenceMetric.setBusinessTransactionDurationSum(instanceReferenceMetric.getBusinessTransactionDurationSum()); + instanceReferenceMetric.setBusinessTransactionErrorDurationSum(instanceReferenceMetric.getBusinessTransactionErrorDurationSum()); + + instanceReferenceMetric.setMqTransactionCalls(instanceReferenceMetric.getMqTransactionCalls()); + instanceReferenceMetric.setMqTransactionErrorCalls(instanceReferenceMetric.getMqTransactionErrorCalls()); + instanceReferenceMetric.setMqTransactionDurationSum(instanceReferenceMetric.getMqTransactionDurationSum()); + instanceReferenceMetric.setMqTransactionErrorDurationSum(instanceReferenceMetric.getMqTransactionErrorDurationSum()); + + instanceReferenceMetric.setSourceValue(serviceReferenceMetric.getSourceValue()); + return instanceReferenceMetric; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public InstanceReferenceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { + return new InstanceReferenceMetricAggregationWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java new file mode 100644 index 000000000000..9b116ff71009 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.InstanceGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class InstanceReferenceMetricRemoteWorker extends AbstractRemoteWorker { + + public InstanceReferenceMetricRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return InstanceGraphNodeIdDefine.INSTANCE_REFERENCE_METRIC_REMOTE_NODE_ID; + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + @Override protected void onWork(InstanceReferenceMetric instanceReferenceMetric) throws WorkerException { + onNext(instanceReferenceMetric); + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public InstanceReferenceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { + return new InstanceReferenceMetricRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java new file mode 100644 index 000000000000..d7f4b0c2beae --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.instance; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.InstanceGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class InstanceReferencePersistenceWorker extends PersistenceWorker { + + public InstanceReferencePersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return InstanceGraphNodeIdDefine.INSTANCE_REFERENCE_METRIC_PERSISTENCE_NODE_ID; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IInstanceReferenceMetricPersistenceDAO.class); + } + + @Override protected boolean needMergeDBData() { + return true; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public InstanceReferencePersistenceWorker workerInstance(ModuleManager moduleManager) { + return new InstanceReferencePersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java new file mode 100644 index 000000000000..5496a560c1ba --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.segment; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class SegmentCostPersistenceWorker extends PersistenceWorker { + + public SegmentCostPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 110; + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(ISegmentCostPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public SegmentCostPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new SegmentCostPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java new file mode 100644 index 000000000000..2cda135c0eca --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.segment; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.LocalSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener, FirstSpanListener { + + private final Logger logger = LoggerFactory.getLogger(SegmentCostSpanListener.class); + + private final List segmentCosts; + private final ServiceNameCacheService serviceNameCacheService; + private boolean isError = false; + private long timeBucket; + + public SegmentCostSpanListener(ModuleManager moduleManager) { + this.segmentCosts = new ArrayList<>(); + this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); + } + + @Override + public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + + SegmentCost segmentCost = new SegmentCost(Const.EMPTY_STRING); + segmentCost.setSegmentId(segmentId); + segmentCost.setApplicationId(applicationId); + segmentCost.setCost(spanDecorator.getEndTime() - spanDecorator.getStartTime()); + segmentCost.setStartTime(spanDecorator.getStartTime()); + segmentCost.setEndTime(spanDecorator.getEndTime()); + segmentCost.setId(segmentId); + if (spanDecorator.getOperationNameId() == 0) { + segmentCost.setServiceName(spanDecorator.getOperationName()); + } else { + segmentCost.setServiceName(serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(spanDecorator.getOperationNameId()))); + } + + segmentCosts.add(segmentCost); + isError = isError || spanDecorator.getIsError(); + } + + @Override + public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + isError = isError || spanDecorator.getIsError(); + } + + @Override + public void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { + isError = isError || spanDecorator.getIsError(); + } + + @Override + public void parseLocal(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + isError = isError || spanDecorator.getIsError(); + } + + @Override public void build() { + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SEGMENT_COST_GRAPH_ID, SegmentCost.class); + logger.debug("segment cost listener build"); + for (SegmentCost segmentCost : segmentCosts) { + segmentCost.setIsError(isError); + segmentCost.setTimeBucket(timeBucket); + graph.start(segmentCost); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java new file mode 100644 index 000000000000..3ec5f3d3faf6 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.segment; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.Segment; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class SegmentPersistenceWorker extends PersistenceWorker { + + public SegmentPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 117; + } + + @Override protected boolean needMergeDBData() { + return false; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(ISegmentPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public SegmentPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new SegmentPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java new file mode 100644 index 000000000000..dbdebc3f553e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryAggregationWorker extends AggregationWorker { + + public ServiceEntryAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 103; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceEntryAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ServiceEntryAggregationWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java new file mode 100644 index 000000000000..6441d764b51e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryPersistenceWorker extends PersistenceWorker { + + public ServiceEntryPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 121; + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IServiceEntryPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceEntryPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ServiceEntryPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java new file mode 100644 index 000000000000..35be725c2f12 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryRemoteWorker extends AbstractRemoteWorker { + + public ServiceEntryRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10003; + } + + @Override protected void onWork(ServiceEntry serviceEntry) throws WorkerException { + onNext(serviceEntry); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ServiceEntryRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ServiceEntryRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java new file mode 100644 index 000000000000..5cc0405f50ec --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceEntrySpanListener implements FirstSpanListener, EntrySpanListener { + + private final Logger logger = LoggerFactory.getLogger(ServiceEntrySpanListener.class); + + private long timeBucket; + private boolean hasReference = false; + private int applicationId; + private int entryServiceId; + private String entryServiceName; + private boolean hasEntry = false; + private final ServiceNameCacheService serviceNameCacheService; + + public ServiceEntrySpanListener(ModuleManager moduleManager) { + this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); + } + + @Override + public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + this.applicationId = applicationId; + this.entryServiceId = spanDecorator.getOperationNameId(); + this.entryServiceName = serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(entryServiceId)); + this.hasEntry = true; + if (spanDecorator.getRefsCount() > 0) { + this.hasReference = true; + } + } + + @Override + public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, + String segmentId) { + timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + } + + @Override public void build() { + logger.debug("entry service listener build"); + if (!hasReference && hasEntry) { + ServiceEntry serviceEntry = new ServiceEntry(applicationId + Const.ID_SPLIT + entryServiceId); + serviceEntry.setApplicationId(applicationId); + serviceEntry.setEntryServiceId(entryServiceId); + serviceEntry.setEntryServiceName(entryServiceName); + serviceEntry.setRegisterTime(timeBucket); + serviceEntry.setNewestTime(timeBucket); + + logger.debug("push to service entry aggregation worker, id: {}", serviceEntry.getId()); + Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SERVICE_ENTRY_GRAPH_ID, ServiceEntry.class); + graph.start(serviceEntry); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java new file mode 100644 index 000000000000..52d93184829e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetric; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricAggregationWorker extends AggregationWorker { + + public ServiceMetricAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ServiceMetricAggregationWorker.class.hashCode(); + } + + @Override protected ServiceMetric transform(ServiceReferenceMetric serviceReferenceMetric) { + Integer serviceId = serviceReferenceMetric.getBehindServiceId(); + Long timeBucket = serviceReferenceMetric.getTimeBucket(); + ServiceMetric serviceMetric = new ServiceMetric(String.valueOf(timeBucket) + Const.ID_SPLIT + String.valueOf(serviceId)); + serviceMetric.setServiceId(serviceId); +// serviceMetric.setCalls(serviceReferenceMetric.getCalls()); +// serviceMetric.setErrorCalls(serviceReferenceMetric.getErrorCalls()); +// serviceMetric.setDurationSum(serviceReferenceMetric.getDurationSum()); +// serviceMetric.setErrorDurationSum(serviceReferenceMetric.getErrorDurationSum()); + serviceMetric.setTimeBucket(timeBucket); + + return serviceMetric; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, + QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ServiceMetricAggregationWorker(moduleManager); + } + + @Override public int queueSize() { + return 256; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java new file mode 100644 index 000000000000..001989396039 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricPersistenceWorker extends PersistenceWorker { + + public ServiceMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 116; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IServiceMetricPersistenceDAO.class); + } + + @Override protected boolean needMergeDBData() { + return true; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ServiceMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java new file mode 100644 index 000000000000..dbd832faab1e --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.apache.skywalking.apm.collector.remote.service.Selector; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricRemoteWorker extends AbstractRemoteWorker { + + public ServiceMetricRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 10004; + } + + @Override protected void onWork(ServiceMetric serviceMetric) throws WorkerException { + onNext(serviceMetric); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ServiceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ServiceMetricRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java new file mode 100644 index 000000000000..924e346035cd --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.ServiceGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.AggregationWorker; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceMetricAggregationWorker extends AggregationWorker { + + public ServiceReferenceMetricAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID; + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceReferenceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { + return new ServiceReferenceMetricAggregationWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java new file mode 100644 index 000000000000..d158665dd7d3 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.agent.stream.service.graph.ServiceGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceMetricPersistenceWorker extends PersistenceWorker { + + public ServiceReferenceMetricPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_PERSISTENCE_NODE_ID; + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IServiceReferenceMetricPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public ServiceReferenceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new ServiceReferenceMetricPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java new file mode 100644 index 000000000000..f3c01399bf2a --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; + +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; +import org.apache.skywalking.apm.collector.agent.stream.service.graph.ServiceGraphNodeIdDefine; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.Selector; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceMetricRemoteWorker extends AbstractRemoteWorker { + + public ServiceReferenceMetricRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_REMOTE_NODE_ID; + } + + @Override protected void onWork(ServiceReferenceMetric serviceReferenceMetric) throws WorkerException { + onNext(serviceReferenceMetric); + } + + @Override public Selector selector() { + return Selector.HashCode; + } + + public static class Factory extends AbstractRemoteWorkerProvider { + + public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { + super(moduleManager, remoteSenderService, graphId); + } + + @Override public ServiceReferenceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { + return new ServiceReferenceMetricRemoteWorker(moduleManager); + } + } +} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java similarity index 79% rename from apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java rename to apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java index ae0bc6ebe1aa..f12d58b06b71 100644 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/apache/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricSpanListener.java @@ -16,24 +16,42 @@ * */ -package org.skywalking.apm.collector.agent.stream.worker.trace.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.agent.stream.worker.trace.service; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.ReferenceDecorator; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.agent.stream.service.trace.MetricSource; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.network.proto.SpanLayer; +import org.apache.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; +import org.apache.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; +import org.apache.skywalking.apm.collector.agent.stream.service.trace.MetricSource; +import org.apache.skywalking.apm.collector.core.graph.Graph; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.agent.stream.parser.standardization.ReferenceDecorator; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.network.proto.SpanLayer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java deleted file mode 100644 index 6a1d5c61af85..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamBootStartup.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream; - -import org.skywalking.apm.collector.agent.stream.graph.JvmMetricStreamGraph; -import org.skywalking.apm.collector.agent.stream.graph.RegisterStreamGraph; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.stream.timer.PersistenceTimer; -import org.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; - -/** - * @author peng-yongsheng - */ -public class AgentStreamBootStartup { - - private final ModuleManager moduleManager; - private final WorkerCreateListener workerCreateListener; - - public AgentStreamBootStartup(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - this.workerCreateListener = new WorkerCreateListener(); - } - - public void start() { - createJVMGraph(); - createRegisterGraph(); - createTraceGraph(); - - PersistenceTimer timer = new PersistenceTimer(); - timer.start(moduleManager, workerCreateListener.getPersistenceWorkers()); - } - - private void createJVMGraph() { - JvmMetricStreamGraph jvmMetricStreamGraph = new JvmMetricStreamGraph(moduleManager, workerCreateListener); - jvmMetricStreamGraph.createCpuMetricGraph(); - jvmMetricStreamGraph.createGcMetricGraph(); - jvmMetricStreamGraph.createMemoryMetricGraph(); - jvmMetricStreamGraph.createMemoryPoolMetricGraph(); - jvmMetricStreamGraph.createHeartBeatGraph(); - } - - private void createRegisterGraph() { - RegisterStreamGraph registerStreamGraph = new RegisterStreamGraph(moduleManager, workerCreateListener); - registerStreamGraph.createApplicationRegisterGraph(); - registerStreamGraph.createInstanceRegisterGraph(); - registerStreamGraph.createServiceNameRegisterGraph(); - } - - private void createTraceGraph() { - TraceStreamGraph traceStreamGraph = new TraceStreamGraph(moduleManager, workerCreateListener); - traceStreamGraph.createSegmentStandardizationGraph(); - traceStreamGraph.createGlobalTraceGraph(); - traceStreamGraph.createInstanceMetricGraph(); - traceStreamGraph.createApplicationComponentGraph(); - traceStreamGraph.createApplicationMappingGraph(); -// traceStreamGraph.createApplicationReferenceMetricGraph(); - traceStreamGraph.createServiceEntryGraph(); - traceStreamGraph.createSegmentGraph(); - traceStreamGraph.createSegmentCostGraph(); - - traceStreamGraph.createServiceReferenceGraph(); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java deleted file mode 100644 index e914b412ed77..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/AgentStreamModuleProvider.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream; - -import java.util.Properties; -import org.skywalking.apm.collector.agent.stream.buffer.BufferFileConfig; -import org.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; -import org.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; -import org.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; -import org.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; -import org.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; -import org.skywalking.apm.collector.agent.stream.worker.AgentStreamRemoteDataRegister; -import org.skywalking.apm.collector.agent.stream.worker.jvm.CpuMetricService; -import org.skywalking.apm.collector.agent.stream.worker.jvm.GCMetricService; -import org.skywalking.apm.collector.agent.stream.worker.jvm.InstanceHeartBeatService; -import org.skywalking.apm.collector.agent.stream.worker.jvm.MemoryMetricService; -import org.skywalking.apm.collector.agent.stream.worker.jvm.MemoryPoolMetricService; -import org.skywalking.apm.collector.agent.stream.worker.register.ApplicationIDService; -import org.skywalking.apm.collector.agent.stream.worker.register.InstanceIDService; -import org.skywalking.apm.collector.agent.stream.worker.register.ServiceNameService; -import org.skywalking.apm.collector.agent.stream.worker.trace.TraceSegmentService; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.configuration.ConfigurationModule; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.remote.RemoteModule; -import org.skywalking.apm.collector.remote.service.RemoteDataRegisterService; -import org.skywalking.apm.collector.storage.StorageModule; - -/** - * @author peng-yongsheng - */ -public class AgentStreamModuleProvider extends ModuleProvider { - - @Override public String name() { - return "default"; - } - - @Override public Class module() { - return AgentStreamModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(IApplicationIDService.class, new ApplicationIDService(getManager())); - this.registerServiceImplementation(IInstanceIDService.class, new InstanceIDService(getManager())); - this.registerServiceImplementation(IServiceNameService.class, new ServiceNameService(getManager())); - - this.registerServiceImplementation(ICpuMetricService.class, new CpuMetricService()); - this.registerServiceImplementation(IGCMetricService.class, new GCMetricService()); - this.registerServiceImplementation(IMemoryMetricService.class, new MemoryMetricService()); - this.registerServiceImplementation(IMemoryPoolMetricService.class, new MemoryPoolMetricService()); - this.registerServiceImplementation(IInstanceHeartBeatService.class, new InstanceHeartBeatService()); - - this.registerServiceImplementation(ITraceSegmentService.class, new TraceSegmentService(getManager())); - - BufferFileConfig.Parser parser = new BufferFileConfig.Parser(); - parser.parse(config); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - RemoteDataRegisterService remoteDataRegisterService = getManager().find(RemoteModule.NAME).getService(RemoteDataRegisterService.class); - AgentStreamRemoteDataRegister agentStreamRemoteDataRegister = new AgentStreamRemoteDataRegister(remoteDataRegisterService); - agentStreamRemoteDataRegister.register(); - - AgentStreamBootStartup bootStartup = new AgentStreamBootStartup(getManager()); - bootStartup.start(); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {StorageModule.NAME, CacheModule.NAME, ConfigurationModule.NAME}; - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/IdAutoIncrement.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/IdAutoIncrement.java deleted file mode 100644 index 991e3e31cd83..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/IdAutoIncrement.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream; - -/** - * @author peng-yongsheng - */ -public enum IdAutoIncrement { - INSTANCE; - - public int increment(int min, int max) { - int instanceId; - if (min == max) { - instanceId = -1; - } else if (min + max == 0) { - instanceId = max + 1; - } else if (min + max > 0) { - instanceId = min - 1; - } else if (max < 0) { - instanceId = 1; - } else { - instanceId = max + 1; - } - return instanceId; - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/GraphDefine.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/GraphDefine.java deleted file mode 100644 index 5469c02651b4..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/GraphDefine.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.graph; - -/** - * @author peng-yongsheng - */ -public interface GraphDefine { - - -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java deleted file mode 100644 index 84688c59f8cd..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/JvmMetricStreamGraph.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.graph; - -import org.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.worker.jvm.CpuMetricPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.jvm.GCMetricPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.jvm.InstHeartBeatPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.jvm.MemoryMetricPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.jvm.MemoryPoolMetricPersistenceWorker; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.QueueModule; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetric; -import org.skywalking.apm.collector.storage.table.jvm.GCMetric; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetric; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; - -/** - * @author peng-yongsheng - */ -public class JvmMetricStreamGraph { - - private final ModuleManager moduleManager; - private final WorkerCreateListener workerCreateListener; - - public JvmMetricStreamGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { - this.moduleManager = moduleManager; - this.workerCreateListener = workerCreateListener; - } - - @SuppressWarnings("unchecked") - public void createGcMetricGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.GC_METRIC_GRAPH_ID, GCMetric.class); - graph.addNode(new GCMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createCpuMetricGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.CPU_METRIC_GRAPH_ID, CpuMetric.class); - graph.addNode(new CpuMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createMemoryMetricGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_METRIC_GRAPH_ID, MemoryMetric.class); - graph.addNode(new MemoryMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createMemoryPoolMetricGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_POOL_METRIC_GRAPH_ID, MemoryPoolMetric.class); - graph.addNode(new MemoryPoolMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createHeartBeatGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.INST_HEART_BEAT_GRAPH_ID, Instance.class); - graph.addNode(new InstHeartBeatPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java deleted file mode 100644 index 95a1da3497d4..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/RegisterStreamGraph.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.graph; - -import org.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.worker.register.ApplicationRegisterRemoteWorker; -import org.skywalking.apm.collector.agent.stream.worker.register.ApplicationRegisterSerialWorker; -import org.skywalking.apm.collector.agent.stream.worker.register.InstanceRegisterRemoteWorker; -import org.skywalking.apm.collector.agent.stream.worker.register.InstanceRegisterSerialWorker; -import org.skywalking.apm.collector.agent.stream.worker.register.ServiceNameRegisterRemoteWorker; -import org.skywalking.apm.collector.agent.stream.worker.register.ServiceNameRegisterSerialWorker; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.QueueModule; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.remote.RemoteModule; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; - -/** - * @author peng-yongsheng - */ -public class RegisterStreamGraph { - - private final ModuleManager moduleManager; - private final WorkerCreateListener workerCreateListener; - - public RegisterStreamGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { - this.moduleManager = moduleManager; - this.workerCreateListener = workerCreateListener; - } - - @SuppressWarnings("unchecked") - public void createApplicationRegisterGraph() { - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.APPLICATION_REGISTER_GRAPH_ID, Application.class); - graph.addNode(new ApplicationRegisterRemoteWorker.Factory(moduleManager, remoteSenderService, RegisterStreamGraphDefine.APPLICATION_REGISTER_GRAPH_ID).create(workerCreateListener)) - .addNext(new ApplicationRegisterSerialWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createInstanceRegisterGraph() { - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.INSTANCE_REGISTER_GRAPH_ID, Instance.class); - graph.addNode(new InstanceRegisterRemoteWorker.Factory(moduleManager, remoteSenderService, RegisterStreamGraphDefine.INSTANCE_REGISTER_GRAPH_ID).create(workerCreateListener)) - .addNext(new InstanceRegisterSerialWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createServiceNameRegisterGraph() { - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.SERVICE_NAME_REGISTER_GRAPH_ID, ServiceName.class); - graph.addNode(new ServiceNameRegisterRemoteWorker.Factory(moduleManager, remoteSenderService, RegisterStreamGraphDefine.SERVICE_NAME_REGISTER_GRAPH_ID).create(workerCreateListener)) - .addNext(new ServiceNameRegisterSerialWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java deleted file mode 100644 index a697ad9f494d..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/graph/TraceStreamGraph.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.graph; - -import org.skywalking.apm.collector.agent.stream.parser.standardization.SegmentStandardization; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SegmentStandardizationWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentAggregationWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentRemoteWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingAggregationWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingRemoteWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.global.GlobalTracePersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.instance.InstanceMetricPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.segment.SegmentCostPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.segment.SegmentPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntryAggregationWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntryPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntryRemoteWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricAggregationWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricPersistenceWorker; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricRemoteWorker; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.QueueModule; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.remote.RemoteModule; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.storage.table.global.GlobalTrace; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetric; -import org.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; -import org.skywalking.apm.collector.storage.table.segment.Segment; -import org.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.WorkerCreateListener; - -/** - * @author peng-yongsheng - */ -public class TraceStreamGraph { - public static final int GLOBAL_TRACE_GRAPH_ID = 300; - public static final int INSTANCE_METRIC_GRAPH_ID = 301; - public static final int APPLICATION_COMPONENT_GRAPH_ID = 302; - public static final int APPLICATION_MAPPING_GRAPH_ID = 303; - public static final int SERVICE_ENTRY_GRAPH_ID = 305; - public static final int SERVICE_REFERENCE_GRAPH_ID = 306; - public static final int SEGMENT_GRAPH_ID = 307; - public static final int SEGMENT_COST_GRAPH_ID = 308; - public static final int SEGMENT_STANDARDIZATION_GRAPH_ID = 309; - - private final ModuleManager moduleManager; - private final WorkerCreateListener workerCreateListener; - - public TraceStreamGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { - this.moduleManager = moduleManager; - this.workerCreateListener = workerCreateListener; - } - - @SuppressWarnings("unchecked") - public void createSegmentStandardizationGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(SEGMENT_STANDARDIZATION_GRAPH_ID, SegmentStandardization.class); - graph.addNode(new SegmentStandardizationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createGlobalTraceGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(GLOBAL_TRACE_GRAPH_ID, GlobalTrace.class); - graph.addNode(new GlobalTracePersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createInstanceMetricGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(INSTANCE_METRIC_GRAPH_ID, InstanceMetric.class); - graph.addNode(new InstanceMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createApplicationComponentGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(APPLICATION_COMPONENT_GRAPH_ID, ApplicationComponent.class); - graph.addNode(new ApplicationComponentAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) - .addNext(new ApplicationComponentRemoteWorker.Factory(moduleManager, remoteSenderService, APPLICATION_COMPONENT_GRAPH_ID).create(workerCreateListener)) - .addNext(new ApplicationComponentPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createApplicationMappingGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(APPLICATION_MAPPING_GRAPH_ID, ApplicationMapping.class); - graph.addNode(new ApplicationMappingAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) - .addNext(new ApplicationMappingRemoteWorker.Factory(moduleManager, remoteSenderService, APPLICATION_MAPPING_GRAPH_ID).create(workerCreateListener)) - .addNext(new ApplicationMappingPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createServiceEntryGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(SERVICE_ENTRY_GRAPH_ID, ServiceEntry.class); - graph.addNode(new ServiceEntryAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) - .addNext(new ServiceEntryRemoteWorker.Factory(moduleManager, remoteSenderService, SERVICE_ENTRY_GRAPH_ID).create(workerCreateListener)) - .addNext(new ServiceEntryPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createServiceReferenceGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(SERVICE_REFERENCE_GRAPH_ID, ServiceReferenceMetric.class); - graph.addNode(new ServiceReferenceMetricAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) - .addNext(new ServiceReferenceMetricRemoteWorker.Factory(moduleManager, remoteSenderService, SERVICE_REFERENCE_GRAPH_ID).create(workerCreateListener)) - .addNext(new ServiceReferenceMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - - createInstanceReferenceGraph(graph); - } - - @SuppressWarnings("unchecked") - private void createInstanceReferenceGraph(Graph graph) { - QueueCreatorService aggregationQueueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - QueueCreatorService persistenceQueueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - -// Node serviceReferenceMetricNode = graph.toFinder().findNode(ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID, ServiceReferenceMetric.class); -// serviceReferenceMetricNode.addNext(new InstanceReferenceMetricAggregationWorker.Factory(moduleManager, aggregationQueueCreatorService).create(workerCreateListener)) -// .addNext(new InstanceReferenceMetricRemoteWorker.Factory(moduleManager, remoteSenderService, SERVICE_REFERENCE_GRAPH_ID).create(workerCreateListener)) -// .addNext(new InstanceReferencePersistenceWorker.Factory(moduleManager, persistenceQueueCreatorService).create(workerCreateListener)); - - createApplicationReferenceMetricGraph(graph); - } - - @SuppressWarnings("unchecked") - private void createApplicationReferenceMetricGraph(Graph graph) { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - RemoteSenderService remoteSenderService = moduleManager.find(RemoteModule.NAME).getService(RemoteSenderService.class); - -// Node serviceReferenceMetricNode = graph.toFinder().findNode(ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID, ServiceReferenceMetric.class); -// graph.addNode(new ApplicationReferenceMetricAggregationWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)) -// .addNext(new ApplicationReferenceMetricRemoteWorker.Factory(moduleManager, remoteSenderService, APPLICATION_REFERENCE_METRIC_GRAPH_ID).create(workerCreateListener)) -// .addNext(new ApplicationReferenceMetricPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createSegmentGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(SEGMENT_GRAPH_ID, Segment.class); - graph.addNode(new SegmentPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } - - @SuppressWarnings("unchecked") - public void createSegmentCostGraph() { - QueueCreatorService queueCreatorService = moduleManager.find(QueueModule.NAME).getService(QueueCreatorService.class); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(SEGMENT_COST_GRAPH_ID, SegmentCost.class); - graph.addNode(new SegmentCostPersistenceWorker.Factory(moduleManager, queueCreatorService).create(workerCreateListener)); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java deleted file mode 100644 index 6bcb912caec5..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/EntrySpanListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; - -/** - * @author peng-yongsheng - */ -public interface EntrySpanListener extends SpanListener { - void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java deleted file mode 100644 index 3112b2873201..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/ExitSpanListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; - -/** - * @author peng-yongsheng - */ -public interface ExitSpanListener extends SpanListener { - void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java deleted file mode 100644 index 6e92d1c1a325..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/FirstSpanListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; - -/** - * @author peng-yongsheng - */ -public interface FirstSpanListener extends SpanListener { - void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java deleted file mode 100644 index 0c4ca7a6071f..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/GlobalTraceIdsListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -import org.skywalking.apm.network.proto.UniqueId; - -/** - * @author peng-yongsheng - */ -public interface GlobalTraceIdsListener extends SpanListener { - void parseGlobalTraceId(UniqueId uniqueId); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java deleted file mode 100644 index 5bf58d525825..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/LocalSpanListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; - -/** - * @author peng-yongsheng - */ -public interface LocalSpanListener extends SpanListener { - void parseLocal(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SegmentParse.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SegmentParse.java deleted file mode 100644 index d92e7c73d6bc..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SegmentParse.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -import com.google.protobuf.InvalidProtocolBufferException; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.standardization.ReferenceDecorator; -import org.skywalking.apm.collector.agent.stream.parser.standardization.ReferenceIdExchanger; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SegmentDecorator; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SegmentStandardization; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanIdExchanger; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationComponentSpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationMappingSpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.application.ApplicationReferenceMetricSpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.global.GlobalTraceSpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.instance.InstanceMetricSpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.segment.SegmentCostSpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceEntrySpanListener; -import org.skywalking.apm.collector.agent.stream.worker.trace.service.ServiceReferenceMetricSpanListener; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.segment.Segment; -import org.skywalking.apm.network.proto.SpanType; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.proto.UniqueId; -import org.skywalking.apm.network.proto.UpstreamSegment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentParse { - - private final Logger logger = LoggerFactory.getLogger(SegmentParse.class); - - private final List spanListeners; - private final ModuleManager moduleManager; - private String segmentId; - private long timeBucket = 0; - - public SegmentParse(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - this.spanListeners = new ArrayList<>(); - this.spanListeners.add(new ApplicationComponentSpanListener()); - this.spanListeners.add(new ApplicationMappingSpanListener()); - this.spanListeners.add(new ApplicationReferenceMetricSpanListener(moduleManager)); - this.spanListeners.add(new SegmentCostSpanListener(moduleManager)); - this.spanListeners.add(new GlobalTraceSpanListener()); - this.spanListeners.add(new ServiceEntrySpanListener(moduleManager)); - this.spanListeners.add(new ServiceReferenceMetricSpanListener()); - this.spanListeners.add(new InstanceMetricSpanListener()); - } - - public boolean parse(UpstreamSegment segment, Source source) { - try { - List traceIds = segment.getGlobalTraceIdsList(); - TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getSegment()); - - SegmentDecorator segmentDecorator = new SegmentDecorator(segmentObject); - - if (!preBuild(traceIds, segmentDecorator)) { - logger.debug("This segment id exchange not success, write to buffer file, id: {}", segmentId); - - if (source.equals(Source.Agent)) { - writeToBufferFile(segmentId, segment); - } - return false; - } else { - logger.debug("This segment id exchange success, id: {}", segmentId); - notifyListenerToBuild(); - buildSegment(segmentId, segmentDecorator.toByteArray()); - return true; - } - } catch (InvalidProtocolBufferException e) { - logger.error(e.getMessage(), e); - } - return false; - } - - private boolean preBuild(List traceIds, SegmentDecorator segmentDecorator) { - StringBuilder segmentIdBuilder = new StringBuilder(); - - for (int i = 0; i < segmentDecorator.getTraceSegmentId().getIdPartsList().size(); i++) { - if (i == 0) { - segmentIdBuilder.append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i)); - } else { - segmentIdBuilder.append(".").append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i)); - } - } - - segmentId = segmentIdBuilder.toString(); - - for (UniqueId uniqueId : traceIds) { - notifyGlobalsListener(uniqueId); - } - - int applicationId = segmentDecorator.getApplicationId(); - int applicationInstanceId = segmentDecorator.getApplicationInstanceId(); - - int entrySpanCount = 0; - for (int i = 0; i < segmentDecorator.getSpansCount(); i++) { - SpanDecorator spanDecorator = segmentDecorator.getSpans(i); - - if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, applicationId)) { - return false; - } else { - for (int j = 0; j < spanDecorator.getRefsCount(); j++) { - ReferenceDecorator referenceDecorator = spanDecorator.getRefs(j); - if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, applicationId)) { - return false; - } - } - } - - if (SpanType.Entry.equals(spanDecorator.getSpanType())) { - entrySpanCount++; - } - - if (entrySpanCount > 1) { - throw new UnexpectedException("This segment contains multiple entry span."); - } - } - - for (int i = 0; i < segmentDecorator.getSpansCount(); i++) { - SpanDecorator spanDecorator = segmentDecorator.getSpans(i); - - if (spanDecorator.getSpanId() == 0) { - notifyFirstListener(spanDecorator, applicationId, applicationInstanceId, segmentId); - timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); - } - - if (SpanType.Exit.equals(spanDecorator.getSpanType())) { - notifyExitListener(spanDecorator, applicationId, applicationInstanceId, segmentId); - } else if (SpanType.Entry.equals(spanDecorator.getSpanType())) { - notifyEntryListener(spanDecorator, applicationId, applicationInstanceId, segmentId); - } else if (SpanType.Local.equals(spanDecorator.getSpanType())) { - notifyLocalListener(spanDecorator, applicationId, applicationInstanceId, segmentId); - } else { - logger.error("span type value was unexpected, span type name: {}", spanDecorator.getSpanType().name()); - } - } - - return true; - } - - private void buildSegment(String id, byte[] dataBinary) { - Segment segment = new Segment(id); - segment.setDataBinary(dataBinary); - segment.setTimeBucket(timeBucket); - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SEGMENT_GRAPH_ID, Segment.class); - graph.start(segment); - } - - private void writeToBufferFile(String id, UpstreamSegment upstreamSegment) { - logger.debug("push to segment buffer write worker, id: {}", id); - SegmentStandardization standardization = new SegmentStandardization(id); - standardization.setUpstreamSegment(upstreamSegment); - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SEGMENT_STANDARDIZATION_GRAPH_ID, SegmentStandardization.class); - graph.start(standardization); - } - - private void notifyListenerToBuild() { - spanListeners.forEach(SpanListener::build); - } - - private void notifyExitListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, - String segmentId) { - for (SpanListener listener : spanListeners) { - if (listener instanceof ExitSpanListener) { - ((ExitSpanListener)listener).parseExit(spanDecorator, applicationId, applicationInstanceId, segmentId); - } - } - } - - private void notifyEntryListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, - String segmentId) { - for (SpanListener listener : spanListeners) { - if (listener instanceof EntrySpanListener) { - ((EntrySpanListener)listener).parseEntry(spanDecorator, applicationId, applicationInstanceId, segmentId); - } - } - } - - private void notifyLocalListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, - String segmentId) { - for (SpanListener listener : spanListeners) { - if (listener instanceof LocalSpanListener) { - ((LocalSpanListener)listener).parseLocal(spanDecorator, applicationId, applicationInstanceId, segmentId); - } - } - } - - private void notifyFirstListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, - String segmentId) { - for (SpanListener listener : spanListeners) { - if (listener instanceof FirstSpanListener) { - ((FirstSpanListener)listener).parseFirst(spanDecorator, applicationId, applicationInstanceId, segmentId); - } - } - } - - private void notifyGlobalsListener(UniqueId uniqueId) { - for (SpanListener listener : spanListeners) { - if (listener instanceof GlobalTraceIdsListener) { - ((GlobalTraceIdsListener)listener).parseGlobalTraceId(uniqueId); - } - } - } - - public enum Source { - Agent, Buffer - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SpanListener.java deleted file mode 100644 index e64b9de92a8d..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/SpanListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser; - -/** - * @author peng-yongsheng - */ -public interface SpanListener { - void build(); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java deleted file mode 100644 index 890946c9de4c..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/IdExchanger.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser.standardization; - -/** - * @author peng-yongsheng - */ -public interface IdExchanger { - boolean exchange(T standardBuilder, int applicationId); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java deleted file mode 100644 index a96777c29673..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentDecorator.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser.standardization; - -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.proto.UniqueId; - -/** - * @author peng-yongsheng - */ -public class SegmentDecorator implements StandardBuilder { - private boolean isOrigin = true; - private final TraceSegmentObject segmentObject; - private TraceSegmentObject.Builder segmentBuilder; - - public SegmentDecorator(TraceSegmentObject segmentObject) { - this.segmentObject = segmentObject; - } - - public int getApplicationId() { - return segmentObject.getApplicationId(); - } - - public int getApplicationInstanceId() { - return segmentObject.getApplicationInstanceId(); - } - - public UniqueId getTraceSegmentId() { - return segmentObject.getTraceSegmentId(); - } - - public int getSpansCount() { - return segmentObject.getSpansCount(); - } - - public SpanDecorator getSpans(int index) { - if (isOrigin) { - return new SpanDecorator(segmentObject.getSpans(index), this); - } else { - return new SpanDecorator(segmentBuilder.getSpansBuilder(index), this); - } - } - - public byte[] toByteArray() { - if (isOrigin) { - return segmentObject.toByteArray(); - } else { - return segmentBuilder.build().toByteArray(); - } - } - - @Override public void toBuilder() { - if (isOrigin) { - this.isOrigin = false; - this.segmentBuilder = segmentObject.toBuilder(); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java deleted file mode 100644 index f0b00f4f701b..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardization.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser.standardization; - -import org.skywalking.apm.collector.core.data.EndOfBatchQueueMessage; -import org.skywalking.apm.network.proto.UpstreamSegment; - -/** - * @author peng-yongsheng - */ -public class SegmentStandardization extends EndOfBatchQueueMessage { - - public SegmentStandardization(String key) { - super(key); - } - - private UpstreamSegment upstreamSegment; - - public UpstreamSegment getUpstreamSegment() { - return upstreamSegment; - } - - public void setUpstreamSegment(UpstreamSegment upstreamSegment) { - this.upstreamSegment = upstreamSegment; - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java deleted file mode 100644 index 437222074674..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SegmentStandardizationWorker.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser.standardization; - -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import org.skywalking.apm.collector.agent.stream.buffer.SegmentBufferManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentStandardizationWorker extends AbstractLocalAsyncWorker { - - private final Logger logger = LoggerFactory.getLogger(SegmentStandardizationWorker.class); - - public SegmentStandardizationWorker(ModuleManager moduleManager) { - super(moduleManager); - SegmentBufferManager.INSTANCE.initialize(moduleManager); - } - - @Override public int id() { - return 108; - } - - @Override protected void onWork(SegmentStandardization segmentStandardization) throws WorkerException { - SegmentBufferManager.INSTANCE.writeBuffer(segmentStandardization.getUpstreamSegment()); - } - - public final void flushAndSwitch() { - SegmentBufferManager.INSTANCE.flush(); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public SegmentStandardizationWorker workerInstance(ModuleManager moduleManager) { - SegmentStandardizationWorker standardizationWorker = new SegmentStandardizationWorker(moduleManager); - startTimer(standardizationWorker); - return standardizationWorker; - } - - @Override public int queueSize() { - return 1024; - } - - private void startTimer(SegmentStandardizationWorker standardizationWorker) { - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(standardizationWorker::flushAndSwitch, 10, 3, TimeUnit.SECONDS); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java deleted file mode 100644 index 624e460dbbcc..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/SpanIdExchanger.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser.standardization; - -import org.skywalking.apm.collector.agent.stream.worker.register.ApplicationIDService; -import org.skywalking.apm.collector.agent.stream.worker.register.ServiceNameService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SpanIdExchanger implements IdExchanger { - - private final Logger logger = LoggerFactory.getLogger(SpanIdExchanger.class); - - private static SpanIdExchanger EXCHANGER; - private final ApplicationIDService applicationIDService; - private final ServiceNameService serviceNameService; - - public static SpanIdExchanger getInstance(ModuleManager moduleManager) { - if (EXCHANGER == null) { - EXCHANGER = new SpanIdExchanger(moduleManager); - } - return EXCHANGER; - } - - private SpanIdExchanger(ModuleManager moduleManager) { - this.applicationIDService = new ApplicationIDService(moduleManager); - this.serviceNameService = new ServiceNameService(moduleManager); - } - - @Override public boolean exchange(SpanDecorator standardBuilder, int applicationId) { - if (standardBuilder.getPeerId() == 0 && StringUtils.isNotEmpty(standardBuilder.getPeer())) { - int peerId = applicationIDService.getOrCreate(standardBuilder.getPeer()); - if (peerId == 0) { - logger.debug("peer: {} in application: {} exchange failed", standardBuilder.getPeer(), applicationId); - return false; - } else { - standardBuilder.toBuilder(); - standardBuilder.setPeerId(peerId); - standardBuilder.setPeer(Const.EMPTY_STRING); - } - } - - if (standardBuilder.getOperationNameId() == 0 && StringUtils.isNotEmpty(standardBuilder.getOperationName())) { - int operationNameId = serviceNameService.getOrCreate(applicationId, standardBuilder.getOperationName()); - - if (operationNameId == 0) { - logger.debug("service name: {} from application id: {} exchange failed", standardBuilder.getOperationName(), applicationId); - return false; - } else { - standardBuilder.toBuilder(); - standardBuilder.setOperationNameId(operationNameId); - standardBuilder.setOperationName(Const.EMPTY_STRING); - } - } - return true; - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java deleted file mode 100644 index 5fa9d5854b86..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/parser/standardization/StandardBuilder.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.parser.standardization; - -/** - * @author peng-yongsheng - */ -public interface StandardBuilder { - void toBuilder(); -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java deleted file mode 100644 index 3dd10fd19539..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/AgentStreamRemoteDataRegister.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker; - -import org.skywalking.apm.collector.remote.service.RemoteDataRegisterService; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; - -/** - * @author peng-yongsheng - */ -public class AgentStreamRemoteDataRegister { - - private final RemoteDataRegisterService remoteDataRegisterService; - - public AgentStreamRemoteDataRegister(RemoteDataRegisterService remoteDataRegisterService) { - this.remoteDataRegisterService = remoteDataRegisterService; - } - - public void register() { - remoteDataRegisterService.register(Application.class, Application::new); - remoteDataRegisterService.register(Instance.class, Instance::new); - remoteDataRegisterService.register(ServiceName.class, ServiceName::new); - - remoteDataRegisterService.register(ApplicationComponent.class, ApplicationComponent::new); - remoteDataRegisterService.register(ApplicationMapping.class, ApplicationMapping::new); - remoteDataRegisterService.register(ApplicationReferenceMetric.class, ApplicationReferenceMetric::new); - remoteDataRegisterService.register(ServiceEntry.class, ServiceEntry::new); - remoteDataRegisterService.register(ServiceReferenceMetric.class, ServiceReferenceMetric::new); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java deleted file mode 100644 index 7ed0aab4b784..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class CpuMetricPersistenceWorker extends PersistenceWorker { - - public CpuMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 115; - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(ICpuMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public CpuMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new CpuMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java deleted file mode 100644 index b3a215b44e1e..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricService.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.jvm.ICpuMetricService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetric; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class CpuMetricService implements ICpuMetricService { - - private final Logger logger = LoggerFactory.getLogger(CpuMetricService.class); - - private Graph cpuMetricGraph; - - private Graph getCpuMetricGraph() { - if (ObjectUtils.isEmpty(cpuMetricGraph)) { - cpuMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.CPU_METRIC_GRAPH_ID, CpuMetric.class); - } - return cpuMetricGraph; - } - - @Override public void send(int instanceId, long timeBucket, double usagePercent) { - CpuMetric cpuMetric = new CpuMetric(timeBucket + Const.ID_SPLIT + instanceId); - cpuMetric.setInstanceId(instanceId); - cpuMetric.setUsagePercent(usagePercent); - cpuMetric.setTimeBucket(timeBucket); - - logger.debug("push to cpu metric graph, id: {}", cpuMetric.getId()); - getCpuMetricGraph().start(cpuMetric); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java deleted file mode 100644 index bf5abf4a3913..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.jvm.GCMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class GCMetricPersistenceWorker extends PersistenceWorker { - - public GCMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 112; - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IGCMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public GCMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new GCMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java deleted file mode 100644 index 20d49f15335f..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/GCMetricService.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.jvm.IGCMetricService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.table.jvm.GCMetric; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GCMetricService implements IGCMetricService { - - private final Logger logger = LoggerFactory.getLogger(GCMetricService.class); - - private Graph gcMetricGraph; - - private Graph getGcMetricGraph() { - if (ObjectUtils.isEmpty(gcMetricGraph)) { - gcMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.GC_METRIC_GRAPH_ID, GCMetric.class); - } - return gcMetricGraph; - } - - @Override public void send(int instanceId, long timeBucket, int phraseValue, long count, long time) { - GCMetric gcMetric = new GCMetric(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(phraseValue)); - gcMetric.setInstanceId(instanceId); - gcMetric.setPhrase(phraseValue); - gcMetric.setCount(count); - gcMetric.setTime(time); - gcMetric.setTimeBucket(timeBucket); - - logger.debug("push to gc metric graph, id: {}", gcMetric.getId()); - getGcMetricGraph().start(gcMetric); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java deleted file mode 100644 index e6836d1b845c..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstHeartBeatPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class InstHeartBeatPersistenceWorker extends PersistenceWorker { - - public InstHeartBeatPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 113; - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IInstanceHeartBeatPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public InstHeartBeatPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new InstHeartBeatPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java deleted file mode 100644 index dceb75fb2db3..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/InstanceHeartBeatService.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.jvm.IInstanceHeartBeatService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceHeartBeatService implements IInstanceHeartBeatService { - - private final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatService.class); - - private Graph heartBeatGraph; - - private Graph getHeartBeatGraph() { - if (ObjectUtils.isEmpty(heartBeatGraph)) { - this.heartBeatGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.INST_HEART_BEAT_GRAPH_ID, Instance.class); - } - return heartBeatGraph; - } - - @Override public void send(int instanceId, long heartBeatTime) { - Instance instance = new Instance(String.valueOf(instanceId)); - instance.setHeartBeatTime(TimeBucketUtils.INSTANCE.getSecondTimeBucket(heartBeatTime)); - instance.setInstanceId(instanceId); - - logger.debug("push to instance heart beat persistence worker, id: {}", instance.getId()); - getHeartBeatGraph().start(instance); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java deleted file mode 100644 index bd7ad4f99f80..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricPersistenceWorker extends PersistenceWorker { - - public MemoryMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 119; - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IMemoryMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public MemoryMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new MemoryMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java deleted file mode 100644 index 6e714bf84984..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryMetricService.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryMetricService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetric; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricService implements IMemoryMetricService { - - private final Logger logger = LoggerFactory.getLogger(MemoryMetricService.class); - - private Graph memoryMetricGraph; - - private Graph getMemoryMetricGraph() { - if (ObjectUtils.isEmpty(memoryMetricGraph)) { - this.memoryMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_METRIC_GRAPH_ID, MemoryMetric.class); - } - return memoryMetricGraph; - } - - @Override - public void send(int instanceId, long timeBucket, boolean isHeap, long init, long max, long used, long commited) { - MemoryMetric memoryMetric = new MemoryMetric(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(isHeap)); - memoryMetric.setInstanceId(instanceId); - memoryMetric.setIsHeap(isHeap); - memoryMetric.setInit(init); - memoryMetric.setMax(max); - memoryMetric.setUsed(used); - memoryMetric.setCommitted(commited); - memoryMetric.setTimeBucket(timeBucket); - - logger.debug("push to memory metric graph, id: {}", memoryMetric.getId()); - getMemoryMetricGraph().start(memoryMetric); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java deleted file mode 100644 index d4b29938d789..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricPersistenceWorker extends PersistenceWorker { - - @Override public int id() { - return 122; - } - - public MemoryPoolMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IMemoryPoolMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public MemoryPoolMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new MemoryPoolMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java deleted file mode 100644 index b8bd94d79e81..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/MemoryPoolMetricService.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.jvm; - -import org.skywalking.apm.collector.agent.stream.service.graph.JvmMetricStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.jvm.IMemoryPoolMetricService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricService implements IMemoryPoolMetricService { - - private final Logger logger = LoggerFactory.getLogger(MemoryPoolMetricService.class); - - private Graph memoryPoolMetricGraph; - - private Graph getMemoryPoolMetricGraph() { - if (ObjectUtils.isEmpty(memoryPoolMetricGraph)) { - this.memoryPoolMetricGraph = GraphManager.INSTANCE.createIfAbsent(JvmMetricStreamGraphDefine.MEMORY_POOL_METRIC_GRAPH_ID, MemoryPoolMetric.class); - } - return memoryPoolMetricGraph; - } - - @Override - public void send(int instanceId, long timeBucket, int poolType, long init, long max, long used, long commited) { - MemoryPoolMetric memoryPoolMetric = new MemoryPoolMetric(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(poolType)); - memoryPoolMetric.setInstanceId(instanceId); - memoryPoolMetric.setPoolType(poolType); - memoryPoolMetric.setInit(init); - memoryPoolMetric.setMax(max); - memoryPoolMetric.setUsed(used); - memoryPoolMetric.setCommitted(commited); - memoryPoolMetric.setTimeBucket(timeBucket); - - logger.debug("push to memory pool metric graph, id: {}", memoryPoolMetric.getId()); - getMemoryPoolMetricGraph().start(memoryPoolMetric); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java deleted file mode 100644 index 74ac2d6c7e47..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationIDService.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.register.IApplicationIDService; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationIDService implements IApplicationIDService { - - private final Logger logger = LoggerFactory.getLogger(ApplicationIDService.class); - - private final ModuleManager moduleManager; - private ApplicationCacheService applicationCacheService; - private Graph applicationRegisterGraph; - - public ApplicationIDService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private Graph getApplicationRegisterGraph() { - if (ObjectUtils.isEmpty(applicationRegisterGraph)) { - this.applicationRegisterGraph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.APPLICATION_REGISTER_GRAPH_ID, Application.class); - } - return this.applicationRegisterGraph; - } - - private ApplicationCacheService getApplicationCacheService() { - if (ObjectUtils.isEmpty(applicationCacheService)) { - this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); - } - return applicationCacheService; - } - - public int getOrCreate(String applicationCode) { - int applicationId = getApplicationCacheService().get(applicationCode); - - if (applicationId == 0) { - Application application = new Application(applicationCode); - application.setApplicationCode(applicationCode); - application.setApplicationId(0); - - getApplicationRegisterGraph().start(application); - } - return applicationId; - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java deleted file mode 100644 index 6a886a46682c..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterRemoteWorker.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationRegisterRemoteWorker extends AbstractRemoteWorker { - - private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterRemoteWorker.class); - - public ApplicationRegisterRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10006; - } - - @Override protected void onWork(Application message) throws WorkerException { - logger.debug("application code: {}", message.getApplicationCode()); - onNext(message); - } - - @Override public Selector selector() { - return Selector.ForeverFirst; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ApplicationRegisterRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationRegisterRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java deleted file mode 100644 index c14d0be5d58b..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ApplicationRegisterSerialWorker.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.agent.stream.IdAutoIncrement; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationRegisterSerialWorker extends AbstractLocalAsyncWorker { - - private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterSerialWorker.class); - - private final IApplicationRegisterDAO applicationRegisterDAO; - private final ApplicationCacheService applicationCacheService; - - public ApplicationRegisterSerialWorker(ModuleManager moduleManager) { - super(moduleManager); - this.applicationRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IApplicationRegisterDAO.class); - this.applicationCacheService = getModuleManager().find(CacheModule.NAME).getService(ApplicationCacheService.class); - } - - @Override public int id() { - return 101; - } - - @Override protected void onWork(Application application) throws WorkerException { - logger.debug("register application, application code: {}", application.getApplicationCode()); - int applicationId = applicationCacheService.get(application.getApplicationCode()); - - if (applicationId == 0) { - Application newApplication; - int min = applicationRegisterDAO.getMinApplicationId(); - if (min == 0) { - Application userApplication = new Application(String.valueOf(Const.USER_ID)); - userApplication.setApplicationCode(Const.USER_CODE); - userApplication.setApplicationId(Const.USER_ID); - applicationRegisterDAO.save(userApplication); - - newApplication = new Application("-1"); - newApplication.setApplicationId(-1); - newApplication.setApplicationCode(application.getApplicationCode()); - } else { - int max = applicationRegisterDAO.getMaxApplicationId(); - applicationId = IdAutoIncrement.INSTANCE.increment(min, max); - - newApplication = new Application(String.valueOf(applicationId)); - newApplication.setApplicationId(applicationId); - newApplication.setApplicationCode(application.getApplicationCode()); - } - applicationRegisterDAO.save(newApplication); - } - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationRegisterSerialWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationRegisterSerialWorker(moduleManager); - } - - @Override public int queueSize() { - return 256; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java deleted file mode 100644 index 35ee58ea11ed..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceIDService.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.register.IInstanceIDService; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceIDService implements IInstanceIDService { - - private final Logger logger = LoggerFactory.getLogger(InstanceIDService.class); - - private final ModuleManager moduleManager; - private InstanceCacheService instanceCacheService; - private Graph instanceRegisterGraph; - private IInstanceRegisterDAO instanceRegisterDAO; - - public InstanceIDService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private InstanceCacheService getInstanceCacheService() { - if (ObjectUtils.isEmpty(instanceCacheService)) { - instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class); - } - return instanceCacheService; - } - - private Graph getInstanceRegisterGraph() { - if (ObjectUtils.isEmpty(instanceRegisterGraph)) { - this.instanceRegisterGraph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.INSTANCE_REGISTER_GRAPH_ID, Instance.class); - } - return instanceRegisterGraph; - } - - private IInstanceRegisterDAO getInstanceRegisterDAO() { - if (ObjectUtils.isEmpty(instanceRegisterDAO)) { - instanceRegisterDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceRegisterDAO.class); - } - return instanceRegisterDAO; - } - - public int getOrCreate(int applicationId, String agentUUID, long registerTime, String osInfo) { - logger.debug("get or create instance id, application id: {}, agentUUID: {}, registerTime: {}, osInfo: {}", applicationId, agentUUID, registerTime, osInfo); - int instanceId = getInstanceCacheService().getInstanceId(applicationId, agentUUID); - - if (instanceId == 0) { - Instance instance = new Instance("0"); - instance.setApplicationId(applicationId); - instance.setAgentUUID(agentUUID); - instance.setRegisterTime(registerTime); - instance.setHeartBeatTime(registerTime); - instance.setInstanceId(0); - instance.setOsInfo(osInfo); - - getInstanceRegisterGraph().start(instance); - } - return instanceId; - } - - public void recover(int instanceId, int applicationId, long registerTime, String osInfo) { - logger.debug("instance recover, instance id: {}, application id: {}, register time: {}", instanceId, applicationId, registerTime); - Instance instance = new Instance(String.valueOf(instanceId)); - instance.setApplicationId(applicationId); - instance.setAgentUUID(""); - instance.setRegisterTime(registerTime); - instance.setHeartBeatTime(registerTime); - instance.setInstanceId(instanceId); - instance.setOsInfo(osInfo); - - getInstanceRegisterDAO().save(instance); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java deleted file mode 100644 index 16ffec917abc..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterRemoteWorker.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceRegisterRemoteWorker extends AbstractRemoteWorker { - - private final Logger logger = LoggerFactory.getLogger(InstanceRegisterRemoteWorker.class); - - @Override public int id() { - return 10001; - } - - InstanceRegisterRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override protected void onWork(Instance instance) throws WorkerException { - logger.debug("application id: {}, agentUUID: {}, register time: {}", instance.getApplicationId(), instance.getAgentUUID(), instance.getRegisterTime()); - onNext(instance); - } - - @Override public Selector selector() { - return Selector.ForeverFirst; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public InstanceRegisterRemoteWorker workerInstance(ModuleManager moduleManager) { - return new InstanceRegisterRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java deleted file mode 100644 index 0e45893b5681..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/InstanceRegisterSerialWorker.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceRegisterSerialWorker extends AbstractLocalAsyncWorker { - - private final Logger logger = LoggerFactory.getLogger(InstanceRegisterSerialWorker.class); - - private final InstanceCacheService instanceCacheService; - private final IInstanceRegisterDAO instanceRegisterDAO; - - public InstanceRegisterSerialWorker(ModuleManager moduleManager) { - super(moduleManager); - this.instanceCacheService = getModuleManager().find(CacheModule.NAME).getService(InstanceCacheService.class); - this.instanceRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IInstanceRegisterDAO.class); - } - - @Override public int id() { - return 102; - } - - @Override protected void onWork(Instance instance) throws WorkerException { - logger.debug("register instance, application id: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID()); - int instanceId = instanceCacheService.getInstanceId(instance.getApplicationId(), instance.getAgentUUID()); - if (instanceId == 0) { - Instance newInstance; - - int min = instanceRegisterDAO.getMinInstanceId(); - int max = instanceRegisterDAO.getMaxInstanceId(); - if (min == 0 && max == 0) { - newInstance = new Instance("1"); - newInstance.setInstanceId(1); - newInstance.setApplicationId(instance.getApplicationId()); - newInstance.setAgentUUID(instance.getAgentUUID()); - newInstance.setHeartBeatTime(instance.getHeartBeatTime()); - newInstance.setOsInfo(instance.getOsInfo()); - newInstance.setRegisterTime(instance.getRegisterTime()); - } else { - newInstance = new Instance(String.valueOf(max + 1)); - newInstance.setInstanceId(max + 1); - newInstance.setApplicationId(instance.getApplicationId()); - newInstance.setAgentUUID(instance.getAgentUUID()); - newInstance.setHeartBeatTime(instance.getHeartBeatTime()); - newInstance.setOsInfo(instance.getOsInfo()); - newInstance.setRegisterTime(instance.getRegisterTime()); - } - instanceRegisterDAO.save(newInstance); - } - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public InstanceRegisterSerialWorker workerInstance(ModuleManager moduleManager) { - return new InstanceRegisterSerialWorker(moduleManager); - } - - @Override public int queueSize() { - return 256; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java deleted file mode 100644 index 179f4025fc7b..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterRemoteWorker.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameRegisterRemoteWorker extends AbstractRemoteWorker { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameRegisterRemoteWorker.class); - - public ServiceNameRegisterRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10000; - } - - @Override protected void onWork(ServiceName serviceName) throws WorkerException { - onNext(serviceName); - } - - @Override public Selector selector() { - return Selector.ForeverFirst; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ServiceNameRegisterRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ServiceNameRegisterRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java deleted file mode 100644 index 4d5ff2a79e75..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameRegisterSerialWorker.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.agent.stream.IdAutoIncrement; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ServiceIdCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameRegisterSerialWorker.class); - - private final IServiceNameRegisterDAO serviceNameRegisterDAO; - private final ServiceIdCacheService serviceIdCacheService; - - public ServiceNameRegisterSerialWorker(ModuleManager moduleManager) { - super(moduleManager); - this.serviceNameRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IServiceNameRegisterDAO.class); - this.serviceIdCacheService = getModuleManager().find(CacheModule.NAME).getService(ServiceIdCacheService.class); - } - - @Override public int id() { - return 100; - } - - @Override protected void onWork(ServiceName serviceName) throws WorkerException { - logger.debug("register service name: {}, application id: {}", serviceName.getServiceName(), serviceName.getApplicationId()); - int serviceId = serviceIdCacheService.get(serviceName.getApplicationId(), serviceName.getServiceName()); - if (serviceId == 0) { - ServiceName newServiceName; - - int min = serviceNameRegisterDAO.getMinServiceId(); - if (min == 0) { - ServiceName noneServiceName = new ServiceName("1"); - noneServiceName.setApplicationId(0); - noneServiceName.setServiceId(Const.NONE_SERVICE_ID); - noneServiceName.setServiceName(Const.NONE_SERVICE_NAME); - serviceNameRegisterDAO.save(noneServiceName); - - newServiceName = new ServiceName("-1"); - newServiceName.setApplicationId(serviceName.getApplicationId()); - newServiceName.setServiceId(-1); - newServiceName.setServiceName(serviceName.getServiceName()); - } else { - int max = serviceNameRegisterDAO.getMaxServiceId(); - serviceId = IdAutoIncrement.INSTANCE.increment(min, max); - - newServiceName = new ServiceName(String.valueOf(serviceId)); - newServiceName.setApplicationId(serviceName.getApplicationId()); - newServiceName.setServiceId(serviceId); - newServiceName.setServiceName(serviceName.getServiceName()); - } - serviceNameRegisterDAO.save(newServiceName); - } - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceNameRegisterSerialWorker workerInstance(ModuleManager moduleManager) { - return new ServiceNameRegisterSerialWorker(moduleManager); - } - - @Override public int queueSize() { - return 256; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java deleted file mode 100644 index cb60151fae00..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/register/ServiceNameService.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.register; - -import org.skywalking.apm.collector.agent.stream.service.graph.RegisterStreamGraphDefine; -import org.skywalking.apm.collector.agent.stream.service.register.IServiceNameService; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ServiceIdCacheService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameService implements IServiceNameService { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameService.class); - - private final ModuleManager moduleManager; - private ServiceIdCacheService serviceIdCacheService; - private Graph serviceNameRegisterGraph; - - public ServiceNameService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private ServiceIdCacheService getServiceIdCacheService() { - if (ObjectUtils.isEmpty(serviceIdCacheService)) { - serviceIdCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceIdCacheService.class); - } - return serviceIdCacheService; - } - - private Graph getServiceNameRegisterGraph() { - if (ObjectUtils.isEmpty(serviceNameRegisterGraph)) { - this.serviceNameRegisterGraph = GraphManager.INSTANCE.createIfAbsent(RegisterStreamGraphDefine.SERVICE_NAME_REGISTER_GRAPH_ID, ServiceName.class); - } - return serviceNameRegisterGraph; - } - - public int getOrCreate(int applicationId, String serviceName) { - int serviceId = getServiceIdCacheService().get(applicationId, serviceName); - - if (serviceId == 0) { - ServiceName service = new ServiceName("0"); - service.setApplicationId(applicationId); - service.setServiceName(serviceName); - service.setServiceId(0); - - getServiceNameRegisterGraph().start(service); - } - return serviceId; - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java deleted file mode 100644 index c20c3a8a172b..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/TraceSegmentService.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace; - -import org.skywalking.apm.collector.agent.stream.parser.SegmentParse; -import org.skywalking.apm.collector.agent.stream.service.trace.ITraceSegmentService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.network.proto.UpstreamSegment; - -/** - * @author peng-yongsheng - */ -public class TraceSegmentService implements ITraceSegmentService { - - private final ModuleManager moduleManager; - - public TraceSegmentService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - public void send(UpstreamSegment segment) { - SegmentParse segmentParse = new SegmentParse(moduleManager); - segmentParse.parse(segment, SegmentParse.Source.Agent); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java deleted file mode 100644 index c95e991ce687..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentAggregationWorker.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentAggregationWorker extends AggregationWorker { - - public ApplicationComponentAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 104; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationComponentAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationComponentAggregationWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java deleted file mode 100644 index c3f6a7231704..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentPersistenceWorker extends PersistenceWorker { - - public ApplicationComponentPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ApplicationComponentPersistenceWorker.class.hashCode(); - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IApplicationComponentPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationComponentPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationComponentPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java deleted file mode 100644 index a7574b1fd1bc..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentRemoteWorker.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentRemoteWorker extends AbstractRemoteWorker { - - ApplicationComponentRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10005; - } - - @Override protected void onWork(ApplicationComponent applicationComponent) throws WorkerException { - onNext(applicationComponent); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ApplicationComponentRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationComponentRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java deleted file mode 100644 index 94f0ef4bd7c9..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationComponentSpanListener.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentSpanListener implements EntrySpanListener, ExitSpanListener, FirstSpanListener { - - private final Logger logger = LoggerFactory.getLogger(ApplicationComponentSpanListener.class); - - private List applicationComponents = new ArrayList<>(); - private long timeBucket; - - @Override - public void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { - ApplicationComponent applicationComponent = new ApplicationComponent(Const.EMPTY_STRING); - applicationComponent.setComponentId(spanDecorator.getComponentId()); - applicationComponent.setPeerId(spanDecorator.getPeerId()); - - String id = String.valueOf(applicationComponent.getComponentId()) + Const.ID_SPLIT + applicationComponent.getPeerId(); - - applicationComponent.setId(id); - applicationComponents.add(applicationComponent); - } - - @Override - public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - ApplicationComponent applicationComponent = new ApplicationComponent(Const.EMPTY_STRING); - applicationComponent.setComponentId(spanDecorator.getComponentId()); - applicationComponent.setPeerId(applicationId); - - String id = String.valueOf(applicationComponent.getComponentId()) + Const.ID_SPLIT + String.valueOf(applicationId); - applicationComponent.setId(id); - - applicationComponents.add(applicationComponent); - } - - @Override - public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); - } - - @Override public void build() { - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.APPLICATION_COMPONENT_GRAPH_ID, ApplicationComponent.class); - - applicationComponents.forEach(applicationComponent -> { - applicationComponent.setId(timeBucket + Const.ID_SPLIT + applicationComponent.getId()); - applicationComponent.setTimeBucket(timeBucket); - graph.start(applicationComponent); - }); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java deleted file mode 100644 index 99ea30a132e7..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingAggregationWorker.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingAggregationWorker extends AggregationWorker { - - ApplicationMappingAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 105; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationMappingAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationMappingAggregationWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java deleted file mode 100644 index 3560eb25ee90..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingPersistenceWorker extends PersistenceWorker { - - ApplicationMappingPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ApplicationMappingPersistenceWorker.class.hashCode(); - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IApplicationMappingPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationMappingPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationMappingPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java deleted file mode 100644 index ec8616f1c883..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingRemoteWorker.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingRemoteWorker extends AbstractRemoteWorker { - - ApplicationMappingRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10007; - } - - @Override protected void onWork(ApplicationMapping applicationMapping) throws WorkerException { - onNext(applicationMapping); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ApplicationMappingRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationMappingRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java deleted file mode 100644 index 0343f2e37731..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMappingSpanListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingSpanListener implements FirstSpanListener, EntrySpanListener { - - private final Logger logger = LoggerFactory.getLogger(ApplicationMappingSpanListener.class); - - private List applicationMappings = new LinkedList<>(); - private long timeBucket; - - @Override public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { - logger.debug("node mapping listener parse reference"); - if (spanDecorator.getRefsCount() > 0) { - ApplicationMapping applicationMapping = new ApplicationMapping(Const.EMPTY_STRING); - applicationMapping.setApplicationId(applicationId); - applicationMapping.setAddressId(spanDecorator.getRefs(0).getNetworkAddressId()); - String id = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(applicationMapping.getAddressId()); - applicationMapping.setId(id); - applicationMappings.add(applicationMapping); - } - } - - @Override - public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); - } - - @Override public void build() { - logger.debug("node mapping listener build"); - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.APPLICATION_MAPPING_GRAPH_ID, ApplicationMapping.class); - applicationMappings.forEach(applicationMapping -> { - applicationMapping.setId(timeBucket + Const.ID_SPLIT + applicationMapping.getId()); - applicationMapping.setTimeBucket(timeBucket); - logger.debug("push to node mapping aggregation worker, id: {}", applicationMapping.getId()); - graph.start(applicationMapping); - }); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java deleted file mode 100644 index c4978e39cdad..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricAggregationWorker.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetric; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationMetricAggregationWorker extends AggregationWorker { - - public ApplicationMetricAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ApplicationMetricAggregationWorker.class.hashCode(); - } - - @Override protected ApplicationMetric transform(ApplicationReferenceMetric applicationReferenceMetric) { - Integer applicationId = applicationReferenceMetric.getBehindApplicationId(); - Long timeBucket = applicationReferenceMetric.getTimeBucket(); - ApplicationMetric applicationMetric = new ApplicationMetric(String.valueOf(timeBucket) + Const.ID_SPLIT + String.valueOf(applicationId)); - applicationMetric.setApplicationId(applicationId); -// applicationMetric.setCalls(applicationReferenceMetric.getCalls()); -// applicationMetric.setErrorCalls(applicationReferenceMetric.getErrorCalls()); -// applicationMetric.setDurationSum(applicationReferenceMetric.getDurationSum()); -// applicationMetric.setErrorDurationSum(applicationReferenceMetric.getErrorDurationSum()); - applicationMetric.setSatisfiedCount(applicationReferenceMetric.getSatisfiedCount()); - applicationMetric.setToleratingCount(applicationReferenceMetric.getToleratingCount()); - applicationMetric.setFrustratedCount(applicationReferenceMetric.getFrustratedCount()); - applicationMetric.setTimeBucket(timeBucket); - - return applicationMetric; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, - QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationMetricAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationMetricAggregationWorker(moduleManager); - } - - @Override public int queueSize() { - return 256; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java deleted file mode 100644 index 831ea9204dca..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationMetricPersistenceWorker extends PersistenceWorker { - - public ApplicationMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 111; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IApplicationMetricPersistenceDAO.class); - } - - @Override protected boolean needMergeDBData() { - return true; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java deleted file mode 100644 index 12f005c9b5cb..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationMetricRemoteWorker.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ApplicationMetricRemoteWorker extends AbstractRemoteWorker { - - public ApplicationMetricRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10002; - } - - @Override protected void onWork(ApplicationMetric applicationMetric) throws WorkerException { - onNext(applicationMetric); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ApplicationMetricRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationMetricRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java deleted file mode 100644 index c31cf559c94e..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricAggregationWorker.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.agent.stream.service.graph.ApplicationGraphNodeIdDefine; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationReferenceMetricAggregationWorker extends AggregationWorker { - - private final InstanceCacheService instanceCacheService; - - public ApplicationReferenceMetricAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class); - } - - @Override public int id() { - return ApplicationGraphNodeIdDefine.APPLICATION_REFERENCE_METRIC_AGGREGATION_NODE_ID; - } - - @Override protected ApplicationReferenceMetric transform(InstanceReferenceMetric instanceReferenceMetric) { - Integer frontApplicationId = instanceCacheService.get(instanceReferenceMetric.getFrontInstanceId()); - Integer behindApplicationId = instanceCacheService.get(instanceReferenceMetric.getBehindInstanceId()); - - String id = instanceReferenceMetric.getTimeBucket() + Const.ID_SPLIT + frontApplicationId + Const.ID_SPLIT + behindApplicationId; - - ApplicationReferenceMetric applicationReferenceMetric = new ApplicationReferenceMetric(id); - applicationReferenceMetric.setFrontApplicationId(frontApplicationId); - applicationReferenceMetric.setBehindApplicationId(behindApplicationId); - - applicationReferenceMetric.setTransactionCalls(instanceReferenceMetric.getTransactionCalls()); - applicationReferenceMetric.setTransactionErrorCalls(instanceReferenceMetric.getTransactionErrorCalls()); - applicationReferenceMetric.setTransactionDurationSum(instanceReferenceMetric.getTransactionDurationSum()); - applicationReferenceMetric.setTransactionErrorDurationSum(instanceReferenceMetric.getTransactionErrorDurationSum()); - - applicationReferenceMetric.setBusinessTransactionCalls(instanceReferenceMetric.getBusinessTransactionCalls()); - applicationReferenceMetric.setBusinessTransactionErrorCalls(instanceReferenceMetric.getBusinessTransactionErrorCalls()); - applicationReferenceMetric.setBusinessTransactionDurationSum(instanceReferenceMetric.getBusinessTransactionDurationSum()); - applicationReferenceMetric.setBusinessTransactionErrorDurationSum(instanceReferenceMetric.getBusinessTransactionErrorDurationSum()); - - applicationReferenceMetric.setMqTransactionCalls(instanceReferenceMetric.getMqTransactionCalls()); - applicationReferenceMetric.setMqTransactionErrorCalls(instanceReferenceMetric.getMqTransactionErrorCalls()); - applicationReferenceMetric.setMqTransactionDurationSum(instanceReferenceMetric.getMqTransactionDurationSum()); - applicationReferenceMetric.setMqTransactionErrorDurationSum(instanceReferenceMetric.getMqTransactionErrorDurationSum()); - - return applicationReferenceMetric; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, - QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationReferenceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationReferenceMetricAggregationWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java deleted file mode 100644 index 6060eaddbfd5..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricPersistenceWorker.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.agent.stream.service.graph.ApplicationGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ApplicationReferenceMetricPersistenceWorker extends PersistenceWorker { - - public ApplicationReferenceMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ApplicationGraphNodeIdDefine.APPLICATION_REFERENCE_METRIC_PERSISTENCE_NODE_ID; - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IApplicationReferenceMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, - QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ApplicationReferenceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationReferenceMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java deleted file mode 100644 index 3286b01fbdf6..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/application/ApplicationReferenceMetricRemoteWorker.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.application; - -import org.skywalking.apm.collector.agent.stream.service.graph.ApplicationGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ApplicationReferenceMetricRemoteWorker extends AbstractRemoteWorker { - - ApplicationReferenceMetricRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ApplicationGraphNodeIdDefine.APPLICATION_REFERENCE_METRIC_REMOTE_NODE_ID; - } - - @Override protected void onWork(ApplicationReferenceMetric applicationReferenceMetric) throws WorkerException { - onNext(applicationReferenceMetric); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ApplicationReferenceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ApplicationReferenceMetricRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java deleted file mode 100644 index a5ef9c7b6eff..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTracePersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.global; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.table.global.GlobalTrace; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class GlobalTracePersistenceWorker extends PersistenceWorker { - - public GlobalTracePersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 120; - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IGlobalTracePersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public GlobalTracePersistenceWorker workerInstance(ModuleManager moduleManager) { - return new GlobalTracePersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java deleted file mode 100644 index 8d4692919fc1..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/global/GlobalTraceSpanListener.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.global; - -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.GlobalTraceIdsListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.global.GlobalTrace; -import org.skywalking.apm.network.proto.UniqueId; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GlobalTraceSpanListener implements FirstSpanListener, GlobalTraceIdsListener { - - private final Logger logger = LoggerFactory.getLogger(GlobalTraceSpanListener.class); - - private List globalTraceIds = new ArrayList<>(); - private String segmentId; - private long timeBucket; - - @Override - public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - this.timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); - this.segmentId = segmentId; - } - - @Override public void parseGlobalTraceId(UniqueId uniqueId) { - StringBuilder globalTraceIdBuilder = new StringBuilder(); - for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) { - if (i == 0) { - globalTraceIdBuilder.append(uniqueId.getIdPartsList().get(i)); - } else { - globalTraceIdBuilder.append(".").append(uniqueId.getIdPartsList().get(i)); - } - } - globalTraceIds.add(globalTraceIdBuilder.toString()); - } - - @Override public void build() { - logger.debug("global trace listener build"); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.GLOBAL_TRACE_GRAPH_ID, GlobalTrace.class); - for (String globalTraceId : globalTraceIds) { - GlobalTrace globalTrace = new GlobalTrace(segmentId + Const.ID_SPLIT + globalTraceId); - globalTrace.setGlobalTraceId(globalTraceId); - globalTrace.setSegmentId(segmentId); - globalTrace.setTimeBucket(timeBucket); - graph.start(globalTrace); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java deleted file mode 100644 index 946939789f14..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.instance; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricPersistenceWorker extends PersistenceWorker { - - public InstanceMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 118; - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IInstanceMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public InstanceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new InstanceMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java deleted file mode 100644 index bb2a7e4b8cd8..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceMetricSpanListener.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.instance; - -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetric; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricSpanListener implements EntrySpanListener, FirstSpanListener { - - private final Logger logger = LoggerFactory.getLogger(InstanceMetricSpanListener.class); - - private int applicationId; - private int instanceId; - private boolean isError; - private long duration; - private long timeBucket; - - @Override - public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - } - - @Override - public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - this.applicationId = applicationId; - this.instanceId = instanceId; - this.isError = spanDecorator.getIsError(); - this.duration = spanDecorator.getEndTime() - spanDecorator.getStartTime(); - timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanDecorator.getStartTime()); - } - - @Override public void build() { - InstanceMetric instanceMetric = new InstanceMetric(timeBucket + Const.ID_SPLIT + instanceId); - instanceMetric.setApplicationId(applicationId); - instanceMetric.setInstanceId(instanceId); - instanceMetric.setTransactionCalls(1L); - instanceMetric.setTransactionDurationSum(duration); - - if (isError) { - instanceMetric.setTransactionErrorCalls(1L); - instanceMetric.setTransactionErrorDurationSum(duration); - } - instanceMetric.setTimeBucket(timeBucket); - - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.INSTANCE_METRIC_GRAPH_ID, InstanceMetric.class); - graph.start(instanceMetric); - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java deleted file mode 100644 index a0d69da13e44..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricAggregationWorker.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.instance; - -import org.skywalking.apm.collector.agent.stream.service.graph.InstanceGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class InstanceReferenceMetricAggregationWorker extends AggregationWorker { - - public InstanceReferenceMetricAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return InstanceGraphNodeIdDefine.INSTANCE_REFERENCE_METRIC_AGGREGATION_NODE_ID; - } - - @Override protected InstanceReferenceMetric transform(ServiceReferenceMetric serviceReferenceMetric) { - String id = serviceReferenceMetric.getTimeBucket() + Const.ID_SPLIT + serviceReferenceMetric.getFrontInstanceId() + Const.ID_SPLIT + serviceReferenceMetric.getBehindInstanceId(); - - InstanceReferenceMetric instanceReferenceMetric = new InstanceReferenceMetric(id); - instanceReferenceMetric.setFrontInstanceId(serviceReferenceMetric.getFrontInstanceId()); - instanceReferenceMetric.setBehindInstanceId(serviceReferenceMetric.getBehindInstanceId()); - - instanceReferenceMetric.setTransactionCalls(serviceReferenceMetric.getTransactionCalls()); - instanceReferenceMetric.setTransactionErrorCalls(serviceReferenceMetric.getTransactionErrorCalls()); - instanceReferenceMetric.setTransactionDurationSum(serviceReferenceMetric.getTransactionDurationSum()); - instanceReferenceMetric.setTransactionErrorDurationSum(serviceReferenceMetric.getTransactionErrorDurationSum()); - - instanceReferenceMetric.setBusinessTransactionCalls(serviceReferenceMetric.getBusinessTransactionCalls()); - instanceReferenceMetric.setBusinessTransactionErrorCalls(instanceReferenceMetric.getBusinessTransactionErrorCalls()); - instanceReferenceMetric.setBusinessTransactionDurationSum(instanceReferenceMetric.getBusinessTransactionDurationSum()); - instanceReferenceMetric.setBusinessTransactionErrorDurationSum(instanceReferenceMetric.getBusinessTransactionErrorDurationSum()); - - instanceReferenceMetric.setMqTransactionCalls(instanceReferenceMetric.getMqTransactionCalls()); - instanceReferenceMetric.setMqTransactionErrorCalls(instanceReferenceMetric.getMqTransactionErrorCalls()); - instanceReferenceMetric.setMqTransactionDurationSum(instanceReferenceMetric.getMqTransactionDurationSum()); - instanceReferenceMetric.setMqTransactionErrorDurationSum(instanceReferenceMetric.getMqTransactionErrorDurationSum()); - - instanceReferenceMetric.setSourceValue(serviceReferenceMetric.getSourceValue()); - return instanceReferenceMetric; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public InstanceReferenceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { - return new InstanceReferenceMetricAggregationWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java deleted file mode 100644 index 1a479339bc1f..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferenceMetricRemoteWorker.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.instance; - -import org.skywalking.apm.collector.agent.stream.service.graph.InstanceGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class InstanceReferenceMetricRemoteWorker extends AbstractRemoteWorker { - - public InstanceReferenceMetricRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return InstanceGraphNodeIdDefine.INSTANCE_REFERENCE_METRIC_REMOTE_NODE_ID; - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - @Override protected void onWork(InstanceReferenceMetric instanceReferenceMetric) throws WorkerException { - onNext(instanceReferenceMetric); - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public InstanceReferenceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { - return new InstanceReferenceMetricRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java deleted file mode 100644 index 990b8f8f94d8..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/instance/InstanceReferencePersistenceWorker.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.instance; - -import org.skywalking.apm.collector.agent.stream.service.graph.InstanceGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.instance.InstanceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class InstanceReferencePersistenceWorker extends PersistenceWorker { - - public InstanceReferencePersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return InstanceGraphNodeIdDefine.INSTANCE_REFERENCE_METRIC_PERSISTENCE_NODE_ID; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IInstanceReferenceMetricPersistenceDAO.class); - } - - @Override protected boolean needMergeDBData() { - return true; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public InstanceReferencePersistenceWorker workerInstance(ModuleManager moduleManager) { - return new InstanceReferencePersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java deleted file mode 100644 index d051d0cd4536..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.segment; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class SegmentCostPersistenceWorker extends PersistenceWorker { - - public SegmentCostPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 110; - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(ISegmentCostPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public SegmentCostPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new SegmentCostPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java deleted file mode 100644 index c2e8664cd71e..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentCostSpanListener.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.segment; - -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.ExitSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.LocalSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener, FirstSpanListener { - - private final Logger logger = LoggerFactory.getLogger(SegmentCostSpanListener.class); - - private final List segmentCosts; - private final ServiceNameCacheService serviceNameCacheService; - private boolean isError = false; - private long timeBucket; - - public SegmentCostSpanListener(ModuleManager moduleManager) { - this.segmentCosts = new ArrayList<>(); - this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); - } - - @Override - public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); - - SegmentCost segmentCost = new SegmentCost(Const.EMPTY_STRING); - segmentCost.setSegmentId(segmentId); - segmentCost.setApplicationId(applicationId); - segmentCost.setCost(spanDecorator.getEndTime() - spanDecorator.getStartTime()); - segmentCost.setStartTime(spanDecorator.getStartTime()); - segmentCost.setEndTime(spanDecorator.getEndTime()); - segmentCost.setId(segmentId); - if (spanDecorator.getOperationNameId() == 0) { - segmentCost.setServiceName(spanDecorator.getOperationName()); - } else { - segmentCost.setServiceName(serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(spanDecorator.getOperationNameId()))); - } - - segmentCosts.add(segmentCost); - isError = isError || spanDecorator.getIsError(); - } - - @Override - public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - isError = isError || spanDecorator.getIsError(); - } - - @Override - public void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { - isError = isError || spanDecorator.getIsError(); - } - - @Override - public void parseLocal(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - isError = isError || spanDecorator.getIsError(); - } - - @Override public void build() { - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SEGMENT_COST_GRAPH_ID, SegmentCost.class); - logger.debug("segment cost listener build"); - for (SegmentCost segmentCost : segmentCosts) { - segmentCost.setIsError(isError); - segmentCost.setTimeBucket(timeBucket); - graph.start(segmentCost); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java deleted file mode 100644 index 659f1855eb00..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/segment/SegmentPersistenceWorker.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.segment; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.table.segment.Segment; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class SegmentPersistenceWorker extends PersistenceWorker { - - public SegmentPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 117; - } - - @Override protected boolean needMergeDBData() { - return false; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(ISegmentPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public SegmentPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new SegmentPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java deleted file mode 100644 index f00ea06b2b49..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryAggregationWorker.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryAggregationWorker extends AggregationWorker { - - public ServiceEntryAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 103; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceEntryAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ServiceEntryAggregationWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java deleted file mode 100644 index 82860fb57ad7..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryPersistenceWorker.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryPersistenceWorker extends PersistenceWorker { - - public ServiceEntryPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 121; - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IServiceEntryPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceEntryPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ServiceEntryPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java deleted file mode 100644 index 3be96207888d..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntryRemoteWorker.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryRemoteWorker extends AbstractRemoteWorker { - - public ServiceEntryRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10003; - } - - @Override protected void onWork(ServiceEntry serviceEntry) throws WorkerException { - onNext(serviceEntry); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ServiceEntryRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ServiceEntryRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java deleted file mode 100644 index c5735565aaf1..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceEntrySpanListener.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.agent.stream.graph.TraceStreamGraph; -import org.skywalking.apm.collector.agent.stream.parser.EntrySpanListener; -import org.skywalking.apm.collector.agent.stream.parser.FirstSpanListener; -import org.skywalking.apm.collector.agent.stream.parser.standardization.SpanDecorator; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.graph.Graph; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceEntrySpanListener implements FirstSpanListener, EntrySpanListener { - - private final Logger logger = LoggerFactory.getLogger(ServiceEntrySpanListener.class); - - private long timeBucket; - private boolean hasReference = false; - private int applicationId; - private int entryServiceId; - private String entryServiceName; - private boolean hasEntry = false; - private final ServiceNameCacheService serviceNameCacheService; - - public ServiceEntrySpanListener(ModuleManager moduleManager) { - this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); - } - - @Override - public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - this.applicationId = applicationId; - this.entryServiceId = spanDecorator.getOperationNameId(); - this.entryServiceName = serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(entryServiceId)); - this.hasEntry = true; - if (spanDecorator.getRefsCount() > 0) { - this.hasReference = true; - } - } - - @Override - public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, - String segmentId) { - timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); - } - - @Override public void build() { - logger.debug("entry service listener build"); - if (!hasReference && hasEntry) { - ServiceEntry serviceEntry = new ServiceEntry(applicationId + Const.ID_SPLIT + entryServiceId); - serviceEntry.setApplicationId(applicationId); - serviceEntry.setEntryServiceId(entryServiceId); - serviceEntry.setEntryServiceName(entryServiceName); - serviceEntry.setRegisterTime(timeBucket); - serviceEntry.setNewestTime(timeBucket); - - logger.debug("push to service entry aggregation worker, id: {}", serviceEntry.getId()); - Graph graph = GraphManager.INSTANCE.createIfAbsent(TraceStreamGraph.SERVICE_ENTRY_GRAPH_ID, ServiceEntry.class); - graph.start(serviceEntry); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java deleted file mode 100644 index 5ec9c3b71648..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricAggregationWorker.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.service.ServiceMetric; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ServiceMetricAggregationWorker extends AggregationWorker { - - public ServiceMetricAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ServiceMetricAggregationWorker.class.hashCode(); - } - - @Override protected ServiceMetric transform(ServiceReferenceMetric serviceReferenceMetric) { - Integer serviceId = serviceReferenceMetric.getBehindServiceId(); - Long timeBucket = serviceReferenceMetric.getTimeBucket(); - ServiceMetric serviceMetric = new ServiceMetric(String.valueOf(timeBucket) + Const.ID_SPLIT + String.valueOf(serviceId)); - serviceMetric.setServiceId(serviceId); -// serviceMetric.setCalls(serviceReferenceMetric.getCalls()); -// serviceMetric.setErrorCalls(serviceReferenceMetric.getErrorCalls()); -// serviceMetric.setDurationSum(serviceReferenceMetric.getDurationSum()); -// serviceMetric.setErrorDurationSum(serviceReferenceMetric.getErrorDurationSum()); - serviceMetric.setTimeBucket(timeBucket); - - return serviceMetric; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, - QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ServiceMetricAggregationWorker(moduleManager); - } - - @Override public int queueSize() { - return 256; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java deleted file mode 100644 index 8a253dffd203..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ServiceMetricPersistenceWorker extends PersistenceWorker { - - public ServiceMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 116; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IServiceMetricPersistenceDAO.class); - } - - @Override protected boolean needMergeDBData() { - return true; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ServiceMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java deleted file mode 100644 index 144a86d1cad0..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceMetricRemoteWorker.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.service.ServiceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ServiceMetricRemoteWorker extends AbstractRemoteWorker { - - public ServiceMetricRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 10004; - } - - @Override protected void onWork(ServiceMetric serviceMetric) throws WorkerException { - onNext(serviceMetric); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ServiceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ServiceMetricRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java deleted file mode 100644 index 4db1398fea87..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricAggregationWorker.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.agent.stream.service.graph.ServiceGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.AggregationWorker; - -/** - * @author peng-yongsheng - */ -public class ServiceReferenceMetricAggregationWorker extends AggregationWorker { - - public ServiceReferenceMetricAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_AGGREGATION_NODE_ID; - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceReferenceMetricAggregationWorker workerInstance(ModuleManager moduleManager) { - return new ServiceReferenceMetricAggregationWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java deleted file mode 100644 index 165f6de5778d..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricPersistenceWorker.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.agent.stream.service.graph.ServiceGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class ServiceReferenceMetricPersistenceWorker extends PersistenceWorker { - - public ServiceReferenceMetricPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_PERSISTENCE_NODE_ID; - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IServiceReferenceMetricPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public ServiceReferenceMetricPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new ServiceReferenceMetricPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java deleted file mode 100644 index b212400853dd..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/java/org/skywalking/apm/collector/agent/stream/worker/trace/service/ServiceReferenceMetricRemoteWorker.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.agent.stream.worker.trace.service; - -import org.skywalking.apm.collector.agent.stream.service.graph.ServiceGraphNodeIdDefine; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorker; -import org.skywalking.apm.collector.stream.worker.base.AbstractRemoteWorkerProvider; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class ServiceReferenceMetricRemoteWorker extends AbstractRemoteWorker { - - public ServiceReferenceMetricRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return ServiceGraphNodeIdDefine.SERVICE_REFERENCE_METRIC_REMOTE_NODE_ID; - } - - @Override protected void onWork(ServiceReferenceMetric serviceReferenceMetric) throws WorkerException { - onNext(serviceReferenceMetric); - } - - @Override public Selector selector() { - return Selector.HashCode; - } - - public static class Factory extends AbstractRemoteWorkerProvider { - - public Factory(ModuleManager moduleManager, RemoteSenderService remoteSenderService, int graphId) { - super(moduleManager, remoteSenderService, graphId); - } - - @Override public ServiceReferenceMetricRemoteWorker workerInstance(ModuleManager moduleManager) { - return new ServiceReferenceMetricRemoteWorker(moduleManager); - } - } -} diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..e63f393b9c19 --- /dev/null +++ b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.agent.stream.AgentStreamModuleProvider diff --git a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 41308a57b163..000000000000 --- a/apm-collector/apm-collector-agent-stream/collector-agent-stream-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.agent.stream.AgentStreamModuleProvider diff --git a/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModule.java b/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModule.java new file mode 100644 index 000000000000..fdff9a28ba9d --- /dev/null +++ b/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModule.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.alerting; + +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class AlertingModule extends Module { + + public static final String NAME = "alerting"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[0]; + } +} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/skywalking/apm/collector/alerting/AlertingModule.java b/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/skywalking/apm/collector/alerting/AlertingModule.java deleted file mode 100644 index 9349a1f280b2..000000000000 --- a/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/java/org/skywalking/apm/collector/alerting/AlertingModule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.alerting; - -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class AlertingModule extends Module { - - public static final String NAME = "alerting"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[0]; - } -} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..bd6975ba428b --- /dev/null +++ b/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.alerting.AlertingModule diff --git a/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 466e9c1908b7..000000000000 --- a/apm-collector/apm-collector-alerting/collector-alerting-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.alerting.AlertingModule diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModuleProvider.java b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModuleProvider.java new file mode 100644 index 000000000000..143e13e2e67c --- /dev/null +++ b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/AlertingModuleProvider.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.alerting; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.agent.stream.AgentStreamModule; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.storage.StorageModule; + +/** + * @author peng-yongsheng + */ +public class AlertingModuleProvider extends ModuleProvider { + + @Override public String name() { + return "default"; + } + + @Override public Class module() { + return AlertingModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {AgentStreamModule.NAME, StorageModule.NAME}; + } +} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java new file mode 100644 index 000000000000..897443deb213 --- /dev/null +++ b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.alerting.worker; + +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingList; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; + +/** + * @author peng-yongsheng + */ +public class AlertingListAggregationWorker extends AbstractLocalAsyncWorker { + + public AlertingListAggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 0; + } + + @Override protected void onWork(AlertingList message) throws WorkerException { + + } +} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java new file mode 100644 index 000000000000..5714031b4b60 --- /dev/null +++ b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/apache/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.alerting.worker; + +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingList; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class AlertingListPersistenceWorker extends PersistenceWorker { + + public AlertingListPersistenceWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + @Override public int id() { + return 114; + } + + @Override protected boolean needMergeDBData() { + return true; + } + + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(IAlertingListPersistenceDAO.class); + } + + public static class Factory extends AbstractLocalAsyncWorkerProvider { + + public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { + super(moduleManager, queueCreatorService); + } + + @Override public AlertingListPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new AlertingListPersistenceWorker(moduleManager); + } + + @Override + public int queueSize() { + return 1024; + } + } +} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/AlertingModuleProvider.java b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/AlertingModuleProvider.java deleted file mode 100644 index 9f7af297f780..000000000000 --- a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/AlertingModuleProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.alerting; - -import java.util.Properties; -import org.skywalking.apm.collector.agent.stream.AgentStreamModule; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.storage.StorageModule; - -/** - * @author peng-yongsheng - */ -public class AlertingModuleProvider extends ModuleProvider { - - @Override public String name() { - return "default"; - } - - @Override public Class module() { - return AlertingModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {AgentStreamModule.NAME, StorageModule.NAME}; - } -} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java deleted file mode 100644 index 660f6fd8297b..000000000000 --- a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListAggregationWorker.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.alerting.worker; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.storage.table.alerting.AlertingList; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; - -/** - * @author peng-yongsheng - */ -public class AlertingListAggregationWorker extends AbstractLocalAsyncWorker { - - public AlertingListAggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 0; - } - - @Override protected void onWork(AlertingList message) throws WorkerException { - - } -} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java deleted file mode 100644 index 78d792febec5..000000000000 --- a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/java/org/skywalking/apm/collector/alerting/worker/AlertingListPersistenceWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.alerting.worker; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; -import org.skywalking.apm.collector.storage.table.alerting.AlertingList; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorkerProvider; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class AlertingListPersistenceWorker extends PersistenceWorker { - - public AlertingListPersistenceWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - @Override public int id() { - return 114; - } - - @Override protected boolean needMergeDBData() { - return true; - } - - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(IAlertingListPersistenceDAO.class); - } - - public static class Factory extends AbstractLocalAsyncWorkerProvider { - - public Factory(ModuleManager moduleManager, QueueCreatorService queueCreatorService) { - super(moduleManager, queueCreatorService); - } - - @Override public AlertingListPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new AlertingListPersistenceWorker(moduleManager); - } - - @Override - public int queueSize() { - return 1024; - } - } -} diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..313e6650b317 --- /dev/null +++ b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.alerting.AlertingModuleProvider diff --git a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index df4f9d5603e2..000000000000 --- a/apm-collector/apm-collector-alerting/collector-alerting-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.alerting.AlertingModuleProvider diff --git a/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/apache/skywalking/apm/collector/baseline/computing/ComputingModule.java b/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/apache/skywalking/apm/collector/baseline/computing/ComputingModule.java new file mode 100644 index 000000000000..ba931975d830 --- /dev/null +++ b/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/apache/skywalking/apm/collector/baseline/computing/ComputingModule.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.baseline.computing; + +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * The ComputingModule defines the required service interfaces. + * + * @author wu-sheng + */ +public class ComputingModule extends Module { + public static final String NAME = "baseline-computing"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[0]; + } +} diff --git a/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/skywalking/apm/collector/baseline/computing/ComputingModule.java b/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/skywalking/apm/collector/baseline/computing/ComputingModule.java deleted file mode 100644 index d96e1d7a6b99..000000000000 --- a/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/java/org/skywalking/apm/collector/baseline/computing/ComputingModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.baseline.computing; - -import org.skywalking.apm.collector.core.module.Module; - -/** - * The ComputingModule defines the required service interfaces. - * - * @author wu-sheng - */ -public class ComputingModule extends Module { - public static final String NAME = "baseline-computing"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[0]; - } -} diff --git a/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/resources/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/resources/services/org.skywalking.apm.collector.core.module.Module index bca5d350395d..54e322e70a87 100644 --- a/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/resources/services/org.skywalking.apm.collector.core.module.Module +++ b/apm-collector/apm-collector-baseline/collector-baseline-computing-define/src/main/resources/services/org.skywalking.apm.collector.core.module.Module @@ -16,4 +16,4 @@ # Project repository: https://github.com/OpenSkywalking/skywalking # -org.skywalking.apm.collector.baseline.computing.ComputingModule \ No newline at end of file +ComputingModule diff --git a/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/apache/skywalking/collector/baseline/computing/provider/ComputingProvider.java b/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/apache/skywalking/collector/baseline/computing/provider/ComputingProvider.java new file mode 100644 index 000000000000..8b821618873f --- /dev/null +++ b/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/apache/skywalking/collector/baseline/computing/provider/ComputingProvider.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.collector.baseline.computing.provider; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.baseline.computing.ComputingModule; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * The ComputingProvider is the default implementation of {@link ComputingModule} + * + * @author wu-sheng + */ +public class ComputingProvider extends ModuleProvider { + public static final String NAME = "default"; + + @Override public String name() { + return NAME; + } + + @Override public Class module() { + return ComputingModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/skywalking/collector/baseline/computing/provider/ComputingProvider.java b/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/skywalking/collector/baseline/computing/provider/ComputingProvider.java deleted file mode 100644 index 9ad5b80dffd7..000000000000 --- a/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/java/org/skywalking/collector/baseline/computing/provider/ComputingProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.collector.baseline.computing.provider; - -import java.util.Properties; -import org.skywalking.apm.collector.baseline.computing.ComputingModule; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; - -/** - * The ComputingProvider is the default implementation of {@link ComputingModule} - * - * @author wu-sheng - */ -public class ComputingProvider extends ModuleProvider { - public static final String NAME = "default"; - - @Override public String name() { - return NAME; - } - - @Override public Class module() { - return ComputingModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/resources/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/resources/services/org.skywalking.apm.collector.core.module.ModuleProvider index d31a7818a1dc..07c66223a904 100644 --- a/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/resources/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ b/apm-collector/apm-collector-baseline/collector-baseline-computing-provider/src/main/resources/services/org.skywalking.apm.collector.core.module.ModuleProvider @@ -16,4 +16,4 @@ # Project repository: https://github.com/OpenSkywalking/skywalking # -org.skywalking.collector.baseline.computing.provider.ComputingProvider \ No newline at end of file +ComputingProvider diff --git a/apm-collector/apm-collector-boot/bin/collectorService.bat b/apm-collector/apm-collector-boot/bin/collectorService.bat index 08660014c04c..d651d965b441 100644 --- a/apm-collector/apm-collector-boot/bin/collectorService.bat +++ b/apm-collector/apm-collector-boot/bin/collectorService.bat @@ -17,5 +17,5 @@ if not defined JAVA_HOME ( set _EXECJAVA=java ) -start "%COLLECTOR_PROCESS_TITLE%" %_EXECJAVA% "%COLLECTOR_OPTS%" -cp "%CLASSPATH%" org.skywalking.apm.collector.boot.CollectorBootStartUp +start "%COLLECTOR_PROCESS_TITLE%" %_EXECJAVA% "%COLLECTOR_OPTS%" -cp "%CLASSPATH%" CollectorBootStartUp endlocal diff --git a/apm-collector/apm-collector-boot/bin/collectorService.sh b/apm-collector/apm-collector-boot/bin/collectorService.sh index 05e1f17d0ccc..5eb45b307078 100644 --- a/apm-collector/apm-collector-boot/bin/collectorService.sh +++ b/apm-collector/apm-collector-boot/bin/collectorService.sh @@ -22,7 +22,7 @@ done COLLECTOR_OPTIONS=" -Dcollector.logDir=${COLLECT_LOG_DIR}" -eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} ${COLLECTOR_OPTIONS} -classpath $CLASSPATH org.skywalking.apm.collector.boot.CollectorBootStartUp \ +eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} ${COLLECTOR_OPTIONS} -classpath $CLASSPATH org.apache.skywalking.apm.collector.boot.CollectorBootStartUp \ 2>${COLLECT_LOG_DIR}/collector.log 1> /dev/null &" if [ $? -eq 0 ]; then diff --git a/apm-collector/apm-collector-boot/docker/collectorService.sh b/apm-collector/apm-collector-boot/docker/collectorService.sh index 919015eee5a5..f69cfdae63cb 100644 --- a/apm-collector/apm-collector-boot/docker/collectorService.sh +++ b/apm-collector/apm-collector-boot/docker/collectorService.sh @@ -20,4 +20,4 @@ do CLASSPATH="$i:$CLASSPATH" done -${_RUNJAVA} ${JAVA_OPTS} -classpath $CLASSPATH org.skywalking.apm.collector.boot.CollectorBootStartUp +${_RUNJAVA} ${JAVA_OPTS} -classpath $CLASSPATH org.apache.skywalking.apm.collector.boot.CollectorBootStartUp diff --git a/apm-collector/apm-collector-boot/docker/log4j2.xml b/apm-collector/apm-collector-boot/docker/log4j2.xml index a2b7178ec881..50b77b8d753c 100644 --- a/apm-collector/apm-collector-boot/docker/log4j2.xml +++ b/apm-collector/apm-collector-boot/docker/log4j2.xml @@ -26,8 +26,8 @@ - - + + diff --git a/apm-collector/apm-collector-boot/src/main/assembly/log4j2.xml b/apm-collector/apm-collector-boot/src/main/assembly/log4j2.xml index 77c7fe436dd8..e85143ff63cd 100644 --- a/apm-collector/apm-collector-boot/src/main/assembly/log4j2.xml +++ b/apm-collector/apm-collector-boot/src/main/assembly/log4j2.xml @@ -36,8 +36,8 @@ - - + + diff --git a/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/CollectorBootStartUp.java b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/CollectorBootStartUp.java new file mode 100644 index 000000000000..5f75601b284a --- /dev/null +++ b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/CollectorBootStartUp.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.boot; + +import org.apache.skywalking.apm.collector.boot.config.ApplicationConfigLoader; +import org.apache.skywalking.apm.collector.boot.config.ConfigFileNotFoundException; +import org.apache.skywalking.apm.collector.core.module.ApplicationConfiguration; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.module.ModuleNotFoundException; +import org.apache.skywalking.apm.collector.core.module.ProviderNotFoundException; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class CollectorBootStartUp { + + public static void main(String[] args) { + final Logger logger = LoggerFactory.getLogger(CollectorBootStartUp.class); + + ApplicationConfigLoader configLoader = new ApplicationConfigLoader(); + ModuleManager manager = new ModuleManager(); + try { + ApplicationConfiguration applicationConfiguration = configLoader.load(); + manager.init(applicationConfiguration); + } catch (ConfigFileNotFoundException e) { + logger.error(e.getMessage(), e); + } catch (ModuleNotFoundException e) { + logger.error(e.getMessage(), e); + } catch (ProviderNotFoundException e) { + logger.error(e.getMessage(), e); + } catch (ServiceNotProvidedException e) { + logger.error(e.getMessage(), e); + } + + try { + Thread.sleep(60000); + } catch (InterruptedException e) { + } + } +} diff --git a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java similarity index 81% rename from apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java rename to apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java index 54f9a219fcbc..84c2a51bf7e3 100644 --- a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java +++ b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ApplicationConfigLoader.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.collector.boot.config; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.boot.config; import java.io.FileNotFoundException; import java.io.Reader; import java.util.Map; import java.util.Properties; -import org.skywalking.apm.collector.core.module.ApplicationConfiguration; -import org.skywalking.apm.collector.core.util.ResourceUtils; +import org.apache.skywalking.apm.collector.core.module.ApplicationConfiguration; +import org.apache.skywalking.apm.collector.core.util.ResourceUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; diff --git a/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java new file mode 100644 index 000000000000..30518a42283c --- /dev/null +++ b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.boot.config; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public class ConfigFileNotFoundException extends CollectorException { + + public ConfigFileNotFoundException(String message) { + super(message); + } + + public ConfigFileNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigLoader.java b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigLoader.java new file mode 100644 index 000000000000..6b58ff07c704 --- /dev/null +++ b/apm-collector/apm-collector-boot/src/main/java/org/apache/skywalking/apm/collector/boot/config/ConfigLoader.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.boot.config; + +/** + * @author peng-yongsheng + */ +public interface ConfigLoader { + T load() throws ConfigFileNotFoundException; +} diff --git a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java deleted file mode 100644 index d0a93e03a5be..000000000000 --- a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.boot; - -import org.skywalking.apm.collector.boot.config.ApplicationConfigLoader; -import org.skywalking.apm.collector.boot.config.ConfigFileNotFoundException; -import org.skywalking.apm.collector.core.module.ApplicationConfiguration; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.module.ModuleNotFoundException; -import org.skywalking.apm.collector.core.module.ProviderNotFoundException; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class CollectorBootStartUp { - - public static void main(String[] args) { - final Logger logger = LoggerFactory.getLogger(CollectorBootStartUp.class); - - ApplicationConfigLoader configLoader = new ApplicationConfigLoader(); - ModuleManager manager = new ModuleManager(); - try { - ApplicationConfiguration applicationConfiguration = configLoader.load(); - manager.init(applicationConfiguration); - } catch (ConfigFileNotFoundException e) { - logger.error(e.getMessage(), e); - } catch (ModuleNotFoundException e) { - logger.error(e.getMessage(), e); - } catch (ProviderNotFoundException e) { - logger.error(e.getMessage(), e); - } catch (ServiceNotProvidedException e) { - logger.error(e.getMessage(), e); - } - - try { - Thread.sleep(60000); - } catch (InterruptedException e) { - } - } -} diff --git a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java deleted file mode 100644 index f556fff261ba..000000000000 --- a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigFileNotFoundException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.boot.config; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public class ConfigFileNotFoundException extends CollectorException { - - public ConfigFileNotFoundException(String message) { - super(message); - } - - public ConfigFileNotFoundException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigLoader.java b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigLoader.java deleted file mode 100644 index 48ebb8a40b2c..000000000000 --- a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/config/ConfigLoader.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.boot.config; - -/** - * @author peng-yongsheng - */ -public interface ConfigLoader { - T load() throws ConfigFileNotFoundException; -} diff --git a/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml b/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml index 0d4e406507ac..90ce682c81fb 100644 --- a/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml +++ b/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml @@ -27,8 +27,8 @@ - - + + diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/CacheModule.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/CacheModule.java new file mode 100644 index 000000000000..7c30c85d6769 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/CacheModule.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache; + +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class CacheModule extends Module { + + public static final String NAME = "cache"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {ApplicationCacheService.class, InstanceCacheService.class, ServiceIdCacheService.class, ServiceNameCacheService.class}; + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java new file mode 100644 index 000000000000..14252c2ae0c8 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.service; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface ApplicationCacheService extends Service { + int get(String applicationCode); + + String get(int applicationId); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/InstanceCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/InstanceCacheService.java new file mode 100644 index 000000000000..021107b2d16f --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/InstanceCacheService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.service; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface InstanceCacheService extends Service { + int get(int applicationInstanceId); + + int getInstanceId(int applicationId, String agentUUID); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceIdCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceIdCacheService.java new file mode 100644 index 000000000000..a3a87ca104e9 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceIdCacheService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.service; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface ServiceIdCacheService extends Service { + int get(int applicationId, String serviceName); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java new file mode 100644 index 000000000000..858aa6a4e570 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.service; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface ServiceNameCacheService extends Service { + String get(int serviceId); + + String getSplitServiceName(String serviceName); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java deleted file mode 100644 index 1adfc9c78c9d..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache; - -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.cache.service.ServiceIdCacheService; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class CacheModule extends Module { - - public static final String NAME = "cache"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {ApplicationCacheService.class, InstanceCacheService.class, ServiceIdCacheService.class, ServiceNameCacheService.class}; - } -} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java deleted file mode 100644 index 1fa236355867..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.service; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface ApplicationCacheService extends Service { - int get(String applicationCode); - - String get(int applicationId); -} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java deleted file mode 100644 index 823866fc0adb..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.service; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface InstanceCacheService extends Service { - int get(int applicationInstanceId); - - int getInstanceId(int applicationId, String agentUUID); -} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java deleted file mode 100644 index e82cc32f9c52..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.service; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface ServiceIdCacheService extends Service { - int get(int applicationId, String serviceName); -} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java deleted file mode 100644 index 1dc661c0c271..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.service; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface ServiceNameCacheService extends Service { - String get(int serviceId); - - String getSplitServiceName(String serviceName); -} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..e8c3c34fc357 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.cache.CacheModule diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index c8b7bc7bc120..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.cache.CacheModule diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java new file mode 100644 index 000000000000..89dfa469978c --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.guava; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.guava.service.ApplicationCacheGuavaService; +import org.apache.skywalking.apm.collector.cache.guava.service.InstanceCacheGuavaService; +import org.apache.skywalking.apm.collector.cache.guava.service.ServiceIdCacheGuavaService; +import org.apache.skywalking.apm.collector.cache.guava.service.ServiceNameCacheGuavaService; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.storage.StorageModule; + +/** + * @author peng-yongsheng + */ +public class CacheModuleGuavaProvider extends ModuleProvider { + + @Override public String name() { + return "guava"; + } + + @Override public Class module() { + return CacheModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(ApplicationCacheService.class, new ApplicationCacheGuavaService(getManager())); + this.registerServiceImplementation(InstanceCacheService.class, new InstanceCacheGuavaService(getManager())); + this.registerServiceImplementation(ServiceIdCacheService.class, new ServiceIdCacheGuavaService(getManager())); + this.registerServiceImplementation(ServiceNameCacheService.class, new ServiceNameCacheGuavaService(getManager())); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {StorageModule.NAME}; + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java new file mode 100644 index 000000000000..d9163bdb3b13 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.guava.service; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationCacheGuavaService implements ApplicationCacheService { + + private final Logger logger = LoggerFactory.getLogger(ApplicationCacheGuavaService.class); + + private final Cache codeCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build(); + + private final ModuleManager moduleManager; + private IApplicationCacheDAO applicationCacheDAO; + + public ApplicationCacheGuavaService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private IApplicationCacheDAO getApplicationCacheDAO() { + if (ObjectUtils.isEmpty(applicationCacheDAO)) { + this.applicationCacheDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationCacheDAO.class); + } + return this.applicationCacheDAO; + } + + public int get(String applicationCode) { + int applicationId = 0; + try { + applicationId = codeCache.get(applicationCode, () -> getApplicationCacheDAO().getApplicationId(applicationCode)); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + if (applicationId == 0) { + applicationId = getApplicationCacheDAO().getApplicationId(applicationCode); + if (applicationId != 0) { + codeCache.put(applicationCode, applicationId); + } + } + return applicationId; + } + + private final Cache idCache = CacheBuilder.newBuilder().maximumSize(1000).build(); + + public String get(int applicationId) { + String applicationCode = Const.EMPTY_STRING; + try { + applicationCode = idCache.get(applicationId, () -> getApplicationCacheDAO().getApplicationCode(applicationId)); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + if (StringUtils.isEmpty(applicationCode)) { + applicationCode = getApplicationCacheDAO().getApplicationCode(applicationId); + if (StringUtils.isNotEmpty(applicationCode)) { + codeCache.put(applicationCode, applicationId); + } + } + return applicationCode; + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java new file mode 100644 index 000000000000..744993c525c2 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.guava.service; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceCacheGuavaService implements InstanceCacheService { + + private final Logger logger = LoggerFactory.getLogger(InstanceCacheGuavaService.class); + + private final Cache integerCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build(); + + private final Cache stringCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build(); + + private final ModuleManager moduleManager; + private IInstanceCacheDAO instanceCacheDAO; + + public InstanceCacheGuavaService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private IInstanceCacheDAO getInstanceCacheDAO() { + if (ObjectUtils.isEmpty(instanceCacheDAO)) { + this.instanceCacheDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceCacheDAO.class); + } + return this.instanceCacheDAO; + } + + public int get(int applicationInstanceId) { + + int applicationId = 0; + try { + applicationId = integerCache.get(applicationInstanceId, () -> getInstanceCacheDAO().getApplicationId(applicationInstanceId)); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + if (applicationId == 0) { + applicationId = getInstanceCacheDAO().getApplicationId(applicationInstanceId); + if (applicationId != 0) { + integerCache.put(applicationInstanceId, applicationId); + } + } + return applicationId; + } + + @Override public int getInstanceId(int applicationId, String agentUUID) { + String key = applicationId + Const.ID_SPLIT + agentUUID; + + int instanceId = 0; + try { + instanceId = stringCache.get(key, () -> getInstanceCacheDAO().getInstanceId(applicationId, agentUUID)); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + if (instanceId == 0) { + instanceId = getInstanceCacheDAO().getInstanceId(applicationId, agentUUID); + if (applicationId != 0) { + stringCache.put(key, instanceId); + } + } + return instanceId; + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java new file mode 100644 index 000000000000..ba4439834f97 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.guava.service; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceIdCacheGuavaService implements ServiceIdCacheService { + + private final Logger logger = LoggerFactory.getLogger(ServiceIdCacheGuavaService.class); + + private final Cache serviceIdCache = CacheBuilder.newBuilder().maximumSize(1000).build(); + + private final ModuleManager moduleManager; + private IServiceNameCacheDAO serviceNameCacheDAO; + + public ServiceIdCacheGuavaService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private IServiceNameCacheDAO getServiceNameCacheDAO() { + if (ObjectUtils.isEmpty(serviceNameCacheDAO)) { + this.serviceNameCacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameCacheDAO.class); + } + return this.serviceNameCacheDAO; + } + + public int get(int applicationId, String serviceName) { + int serviceId = 0; + try { + serviceId = serviceIdCache.get(applicationId + Const.ID_SPLIT + serviceName, () -> getServiceNameCacheDAO().getServiceId(applicationId, serviceName)); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + if (serviceId == 0) { + serviceId = getServiceNameCacheDAO().getServiceId(applicationId, serviceName); + if (serviceId != 0) { + serviceIdCache.put(applicationId + Const.ID_SPLIT + serviceName, serviceId); + } + } + return serviceId; + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java new file mode 100644 index 000000000000..e7cb9e9d139b --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cache.guava.service; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameCacheGuavaService implements ServiceNameCacheService { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameCacheGuavaService.class); + + private final Cache serviceNameCache = CacheBuilder.newBuilder().maximumSize(10000).build(); + + private final ModuleManager moduleManager; + private IServiceNameCacheDAO serviceNameCacheDAO; + + public ServiceNameCacheGuavaService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private IServiceNameCacheDAO getServiceNameCacheDAO() { + if (ObjectUtils.isEmpty(serviceNameCacheDAO)) { + this.serviceNameCacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameCacheDAO.class); + } + return this.serviceNameCacheDAO; + } + + public String get(int serviceId) { + String serviceName = Const.EMPTY_STRING; + try { + serviceName = serviceNameCache.get(serviceId, () -> getServiceNameCacheDAO().getServiceName(serviceId)); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + if (StringUtils.isEmpty(serviceName)) { + serviceName = getServiceNameCacheDAO().getServiceName(serviceId); + if (StringUtils.isNotEmpty(serviceName)) { + serviceNameCache.put(serviceId, serviceName); + } + } + + return serviceName; + } + + public String getSplitServiceName(String serviceName) { + if (StringUtils.isNotEmpty(serviceName)) { + String[] serviceNames = serviceName.split(Const.ID_SPLIT); + if (serviceNames.length == 2) { + return serviceNames[1]; + } else { + return Const.EMPTY_STRING; + } + } else { + return Const.EMPTY_STRING; + } + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java deleted file mode 100644 index 09732b76323c..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.guava; - -import java.util.Properties; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.guava.service.ApplicationCacheGuavaService; -import org.skywalking.apm.collector.cache.guava.service.InstanceCacheGuavaService; -import org.skywalking.apm.collector.cache.guava.service.ServiceIdCacheGuavaService; -import org.skywalking.apm.collector.cache.guava.service.ServiceNameCacheGuavaService; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.cache.service.ServiceIdCacheService; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.storage.StorageModule; - -/** - * @author peng-yongsheng - */ -public class CacheModuleGuavaProvider extends ModuleProvider { - - @Override public String name() { - return "guava"; - } - - @Override public Class module() { - return CacheModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(ApplicationCacheService.class, new ApplicationCacheGuavaService(getManager())); - this.registerServiceImplementation(InstanceCacheService.class, new InstanceCacheGuavaService(getManager())); - this.registerServiceImplementation(ServiceIdCacheService.class, new ServiceIdCacheGuavaService(getManager())); - this.registerServiceImplementation(ServiceNameCacheService.class, new ServiceNameCacheGuavaService(getManager())); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {StorageModule.NAME}; - } -} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java deleted file mode 100644 index d57012e5fa1c..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.guava.service; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationCacheGuavaService implements ApplicationCacheService { - - private final Logger logger = LoggerFactory.getLogger(ApplicationCacheGuavaService.class); - - private final Cache codeCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build(); - - private final ModuleManager moduleManager; - private IApplicationCacheDAO applicationCacheDAO; - - public ApplicationCacheGuavaService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private IApplicationCacheDAO getApplicationCacheDAO() { - if (ObjectUtils.isEmpty(applicationCacheDAO)) { - this.applicationCacheDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationCacheDAO.class); - } - return this.applicationCacheDAO; - } - - public int get(String applicationCode) { - int applicationId = 0; - try { - applicationId = codeCache.get(applicationCode, () -> getApplicationCacheDAO().getApplicationId(applicationCode)); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - - if (applicationId == 0) { - applicationId = getApplicationCacheDAO().getApplicationId(applicationCode); - if (applicationId != 0) { - codeCache.put(applicationCode, applicationId); - } - } - return applicationId; - } - - private final Cache idCache = CacheBuilder.newBuilder().maximumSize(1000).build(); - - public String get(int applicationId) { - String applicationCode = Const.EMPTY_STRING; - try { - applicationCode = idCache.get(applicationId, () -> getApplicationCacheDAO().getApplicationCode(applicationId)); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - - if (StringUtils.isEmpty(applicationCode)) { - applicationCode = getApplicationCacheDAO().getApplicationCode(applicationId); - if (StringUtils.isNotEmpty(applicationCode)) { - codeCache.put(applicationCode, applicationId); - } - } - return applicationCode; - } -} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java deleted file mode 100644 index 5d71ea0facf1..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.guava.service; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.skywalking.apm.collector.cache.service.InstanceCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceCacheGuavaService implements InstanceCacheService { - - private final Logger logger = LoggerFactory.getLogger(InstanceCacheGuavaService.class); - - private final Cache integerCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build(); - - private final Cache stringCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build(); - - private final ModuleManager moduleManager; - private IInstanceCacheDAO instanceCacheDAO; - - public InstanceCacheGuavaService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private IInstanceCacheDAO getInstanceCacheDAO() { - if (ObjectUtils.isEmpty(instanceCacheDAO)) { - this.instanceCacheDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceCacheDAO.class); - } - return this.instanceCacheDAO; - } - - public int get(int applicationInstanceId) { - - int applicationId = 0; - try { - applicationId = integerCache.get(applicationInstanceId, () -> getInstanceCacheDAO().getApplicationId(applicationInstanceId)); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - - if (applicationId == 0) { - applicationId = getInstanceCacheDAO().getApplicationId(applicationInstanceId); - if (applicationId != 0) { - integerCache.put(applicationInstanceId, applicationId); - } - } - return applicationId; - } - - @Override public int getInstanceId(int applicationId, String agentUUID) { - String key = applicationId + Const.ID_SPLIT + agentUUID; - - int instanceId = 0; - try { - instanceId = stringCache.get(key, () -> getInstanceCacheDAO().getInstanceId(applicationId, agentUUID)); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - - if (instanceId == 0) { - instanceId = getInstanceCacheDAO().getInstanceId(applicationId, agentUUID); - if (applicationId != 0) { - stringCache.put(key, instanceId); - } - } - return instanceId; - } -} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java deleted file mode 100644 index 93e2614c56ef..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.guava.service; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.skywalking.apm.collector.cache.service.ServiceIdCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceIdCacheGuavaService implements ServiceIdCacheService { - - private final Logger logger = LoggerFactory.getLogger(ServiceIdCacheGuavaService.class); - - private final Cache serviceIdCache = CacheBuilder.newBuilder().maximumSize(1000).build(); - - private final ModuleManager moduleManager; - private IServiceNameCacheDAO serviceNameCacheDAO; - - public ServiceIdCacheGuavaService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private IServiceNameCacheDAO getServiceNameCacheDAO() { - if (ObjectUtils.isEmpty(serviceNameCacheDAO)) { - this.serviceNameCacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameCacheDAO.class); - } - return this.serviceNameCacheDAO; - } - - public int get(int applicationId, String serviceName) { - int serviceId = 0; - try { - serviceId = serviceIdCache.get(applicationId + Const.ID_SPLIT + serviceName, () -> getServiceNameCacheDAO().getServiceId(applicationId, serviceName)); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - - if (serviceId == 0) { - serviceId = getServiceNameCacheDAO().getServiceId(applicationId, serviceName); - if (serviceId != 0) { - serviceIdCache.put(applicationId + Const.ID_SPLIT + serviceName, serviceId); - } - } - return serviceId; - } -} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java deleted file mode 100644 index f9c10e34c763..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cache.guava.service; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameCacheGuavaService implements ServiceNameCacheService { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameCacheGuavaService.class); - - private final Cache serviceNameCache = CacheBuilder.newBuilder().maximumSize(10000).build(); - - private final ModuleManager moduleManager; - private IServiceNameCacheDAO serviceNameCacheDAO; - - public ServiceNameCacheGuavaService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - private IServiceNameCacheDAO getServiceNameCacheDAO() { - if (ObjectUtils.isEmpty(serviceNameCacheDAO)) { - this.serviceNameCacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameCacheDAO.class); - } - return this.serviceNameCacheDAO; - } - - public String get(int serviceId) { - String serviceName = Const.EMPTY_STRING; - try { - serviceName = serviceNameCache.get(serviceId, () -> getServiceNameCacheDAO().getServiceName(serviceId)); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - - if (StringUtils.isEmpty(serviceName)) { - serviceName = getServiceNameCacheDAO().getServiceName(serviceId); - if (StringUtils.isNotEmpty(serviceName)) { - serviceNameCache.put(serviceId, serviceName); - } - } - - return serviceName; - } - - public String getSplitServiceName(String serviceName) { - if (StringUtils.isNotEmpty(serviceName)) { - String[] serviceNames = serviceName.split(Const.ID_SPLIT); - if (serviceNames.length == 2) { - return serviceNames[1]; - } else { - return Const.EMPTY_STRING; - } - } else { - return Const.EMPTY_STRING; - } - } -} diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..7d55a5ed1269 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.cache.guava.CacheModuleGuavaProvider diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 790e5830365b..000000000000 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.cache.guava.CacheModuleGuavaProvider diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterException.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterException.java new file mode 100644 index 000000000000..8f54d6d83321 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public abstract class ClusterException extends CollectorException { + + public ClusterException(String message) { + super(message); + } + + public ClusterException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModule.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModule.java new file mode 100644 index 000000000000..ada773c9563f --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModule.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster; + +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class ClusterModule extends Module { + + public static final String NAME = "cluster"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {ModuleListenerService.class, ModuleRegisterService.class}; + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModuleListener.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModuleListener.java new file mode 100644 index 000000000000..514bf9a083f1 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterModuleListener.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author peng-yongsheng + */ +public abstract class ClusterModuleListener { + + private Set addresses; + + public ClusterModuleListener() { + addresses = new HashSet<>(); + } + + public abstract String path(); + + public final void addAddress(String address) { + addresses.add(address); + } + + public final void removeAddress(String address) { + addresses.remove(address); + } + + public final Set getAddresses() { + return addresses; + } + + public abstract void serverJoinNotify(String serverAddress); + + public abstract void serverQuitNotify(String serverAddress); +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterNodeExistException.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterNodeExistException.java new file mode 100644 index 000000000000..1046f33c2ac3 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ClusterNodeExistException.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster; + +/** + * @author peng-yongsheng + */ +public class ClusterNodeExistException extends ClusterException { + + public ClusterNodeExistException(String message) { + super(message); + } + + public ClusterNodeExistException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/DataMonitor.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/DataMonitor.java new file mode 100644 index 000000000000..593f9f45b263 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/DataMonitor.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster; + +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.Client; + +/** + * @author peng-yongsheng + */ +public interface DataMonitor { + String BASE_CATALOG = "/skywalking"; + + void setClient(Client client); + + void addListener(ClusterModuleListener listener) throws ClientException; + + void register(String path, ModuleRegistration registration) throws ClientException; + + ClusterModuleListener getListener(String path); + + void createPath(String path) throws ClientException; + + void setData(String path, String value) throws ClientException; +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ModuleRegistration.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ModuleRegistration.java new file mode 100644 index 000000000000..107cf8f3fa63 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/ModuleRegistration.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster; + +/** + * @author peng-yongsheng + */ +public abstract class ModuleRegistration { + + public abstract Value buildValue(); + + public static class Value { + private final String host; + private final int port; + private final String contextPath; + + public Value(String host, int port, String contextPath) { + this.host = host; + this.port = port; + this.contextPath = contextPath; + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + public String getHostPort() { + return host + ":" + port; + } + + public String getContextPath() { + return contextPath; + } + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleListenerService.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleListenerService.java new file mode 100644 index 000000000000..76c61f77baba --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleListenerService.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.service; + +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface ModuleListenerService extends Service { + void addListener(ClusterModuleListener listener); +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleRegisterService.java new file mode 100644 index 000000000000..a30c160d34af --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/apache/skywalking/apm/collector/cluster/service/ModuleRegisterService.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; + +/** + * @author peng-yongsheng + */ +public interface ModuleRegisterService extends Service { + void register(String moduleName, String providerName, ModuleRegistration registration); +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterException.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterException.java deleted file mode 100644 index 098e93830184..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public abstract class ClusterException extends CollectorException { - - public ClusterException(String message) { - super(message); - } - - public ClusterException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModule.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModule.java deleted file mode 100644 index fbacc90aa44f..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModule.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster; - -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public class ClusterModule extends Module { - - public static final String NAME = "cluster"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {ModuleListenerService.class, ModuleRegisterService.class}; - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleListener.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleListener.java deleted file mode 100644 index 001fa3743140..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleListener.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster; - -import java.util.HashSet; -import java.util.Set; - -/** - * @author peng-yongsheng - */ -public abstract class ClusterModuleListener { - - private Set addresses; - - public ClusterModuleListener() { - addresses = new HashSet<>(); - } - - public abstract String path(); - - public final void addAddress(String address) { - addresses.add(address); - } - - public final void removeAddress(String address) { - addresses.remove(address); - } - - public final Set getAddresses() { - return addresses; - } - - public abstract void serverJoinNotify(String serverAddress); - - public abstract void serverQuitNotify(String serverAddress); -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterNodeExistException.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterNodeExistException.java deleted file mode 100644 index 755de4fd63c0..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ClusterNodeExistException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster; - -/** - * @author peng-yongsheng - */ -public class ClusterNodeExistException extends ClusterException { - - public ClusterNodeExistException(String message) { - super(message); - } - - public ClusterNodeExistException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/DataMonitor.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/DataMonitor.java deleted file mode 100644 index b3b5d6798ddc..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/DataMonitor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster; - -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public interface DataMonitor { - String BASE_CATALOG = "/skywalking"; - - void setClient(Client client); - - void addListener(ClusterModuleListener listener) throws ClientException; - - void register(String path, ModuleRegistration registration) throws ClientException; - - ClusterModuleListener getListener(String path); - - void createPath(String path) throws ClientException; - - void setData(String path, String value) throws ClientException; -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ModuleRegistration.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ModuleRegistration.java deleted file mode 100644 index ceb392dec9ce..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/ModuleRegistration.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster; - -/** - * @author peng-yongsheng - */ -public abstract class ModuleRegistration { - - public abstract Value buildValue(); - - public static class Value { - private final String host; - private final int port; - private final String contextPath; - - public Value(String host, int port, String contextPath) { - this.host = host; - this.port = port; - this.contextPath = contextPath; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - public String getHostPort() { - return host + ":" + port; - } - - public String getContextPath() { - return contextPath; - } - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleListenerService.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleListenerService.java deleted file mode 100644 index 0bd849580f2f..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleListenerService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.service; - -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface ModuleListenerService extends Service { - void addListener(ClusterModuleListener listener); -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleRegisterService.java deleted file mode 100644 index 902fcaf2e99f..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/java/org/skywalking/apm/collector/cluster/service/ModuleRegisterService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.service; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface ModuleRegisterService extends Service { - void register(String moduleName, String providerName, ModuleRegistration registration); -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..874d83046ccc --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.cluster.ClusterModule diff --git a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 749a51cb8a01..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.cluster.ClusterModule diff --git a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java new file mode 100644 index 000000000000..94c2e28534a4 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.redis; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.redis.service.RedisModuleRegisterService; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; + +/** + * @author peng-yongsheng + */ +public class ClusterModuleRedisProvider extends ModuleProvider { + + @Override public String name() { + return "redis"; + } + + @Override public Class module() { + return ClusterModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(ModuleRegisterService.class, new RedisModuleRegisterService()); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java new file mode 100644 index 000000000000..383ce87c376f --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.redis.service; + +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; + +/** + * @author peng-yongsheng + */ +public class RedisModuleRegisterService implements ModuleRegisterService { + + @Override public void register(String moduleName, String providerName, ModuleRegistration registration) { + + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java deleted file mode 100644 index 9d517cdc5f14..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/ClusterModuleRedisProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.redis; - -import java.util.Properties; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.redis.service.RedisModuleRegisterService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; - -/** - * @author peng-yongsheng - */ -public class ClusterModuleRedisProvider extends ModuleProvider { - - @Override public String name() { - return "redis"; - } - - @Override public Class module() { - return ClusterModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(ModuleRegisterService.class, new RedisModuleRegisterService()); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java deleted file mode 100644 index 3453c88201ef..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/java/org/skywalking/apm/collector/cluster/redis/service/RedisModuleRegisterService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.redis.service; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; - -/** - * @author peng-yongsheng - */ -public class RedisModuleRegisterService implements ModuleRegisterService { - - @Override public void register(String moduleName, String providerName, ModuleRegistration registration) { - - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..4d1ad515d12c --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.cluster.redis.ClusterModuleRedisProvider diff --git a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 8ffeb9e1e2f7..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-redis-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.cluster.redis.ClusterModuleRedisProvider diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java new file mode 100644 index 000000000000..4d00b1f6bc8c --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.standalone; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.CollectorException; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ClusterModuleStandaloneProvider extends ModuleProvider { + + private final Logger logger = LoggerFactory.getLogger(ClusterModuleStandaloneProvider.class); + + private static final String URL = "url"; + private static final String USER_NAME = "user_name"; + + private H2Client h2Client; + private ClusterStandaloneDataMonitor dataMonitor; + + @Override public String name() { + return "standalone"; + } + + @Override public Class module() { + return ClusterModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.dataMonitor = new ClusterStandaloneDataMonitor(); + + final String url = config.getProperty(URL); + final String userName = config.getProperty(USER_NAME); + h2Client = new H2Client(url, userName, Const.EMPTY_STRING); + this.dataMonitor.setClient(h2Client); + + this.registerServiceImplementation(ModuleListenerService.class, new StandaloneModuleListenerService(dataMonitor)); + this.registerServiceImplementation(ModuleRegisterService.class, new StandaloneModuleRegisterService(dataMonitor)); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + try { + h2Client.initialize(); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + try { + dataMonitor.start(); + } catch (CollectorException e) { + throw new UnexpectedException(e.getMessage()); + } + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java new file mode 100644 index 000000000000..235c89decf29 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.standalone; + +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.cluster.DataMonitor; +import org.apache.skywalking.apm.collector.core.CollectorException; +import org.apache.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ClusterStandaloneDataMonitor implements DataMonitor { + + private final Logger logger = LoggerFactory.getLogger(ClusterStandaloneDataMonitor.class); + + private H2Client client; + + private Map listeners; + private Map registrations; + + public ClusterStandaloneDataMonitor() { + listeners = new LinkedHashMap<>(); + registrations = new LinkedHashMap<>(); + } + + @Override public void setClient(Client client) { + this.client = (H2Client)client; + } + + @Override + public void addListener(ClusterModuleListener listener) { + String path = BASE_CATALOG + listener.path(); + logger.info("listener path: {}", path); + listeners.put(path, listener); + } + + @Override public ClusterModuleListener getListener(String path) { + path = BASE_CATALOG + path; + return listeners.get(path); + } + + @Override public void register(String path, ModuleRegistration registration) { + registrations.put(BASE_CATALOG + path, registration); + } + + @Override public void createPath(String path) throws ClientException { + + } + + @Override public void setData(String path, String value) throws ClientException { + if (listeners.containsKey(path)) { + listeners.get(path).addAddress(value); + listeners.get(path).serverJoinNotify(value); + } + } + + public void start() throws CollectorException { + Iterator> entryIterator = registrations.entrySet().iterator(); + while (entryIterator.hasNext()) { + Map.Entry next = entryIterator.next(); + ModuleRegistration.Value value = next.getValue().buildValue(); + String contextPath = value.getContextPath() == null ? "" : value.getContextPath(); + setData(next.getKey(), value.getHostPort() + contextPath); + } + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java new file mode 100644 index 000000000000..fb9d8e9935b5 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.standalone.service; + +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.standalone.ClusterStandaloneDataMonitor; + +/** + * @author peng-yongsheng + */ +public class StandaloneModuleListenerService implements ModuleListenerService { + + private final ClusterStandaloneDataMonitor dataMonitor; + + public StandaloneModuleListenerService(ClusterStandaloneDataMonitor dataMonitor) { + this.dataMonitor = dataMonitor; + } + + @Override public void addListener(ClusterModuleListener listener) { + dataMonitor.addListener(listener); + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java new file mode 100644 index 000000000000..56275a57a7c1 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.standalone.service; + +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; +import org.apache.skywalking.apm.collector.cluster.standalone.ClusterStandaloneDataMonitor; + +/** + * @author peng-yongsheng + */ +public class StandaloneModuleRegisterService implements ModuleRegisterService { + + private final ClusterStandaloneDataMonitor dataMonitor; + + public StandaloneModuleRegisterService(ClusterStandaloneDataMonitor dataMonitor) { + this.dataMonitor = dataMonitor; + } + + @Override public void register(String moduleName, String providerName, ModuleRegistration registration) { + String path = "/" + moduleName + "/" + providerName; + dataMonitor.register(path, registration); + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java deleted file mode 100644 index 8b2f65750495..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterModuleStandaloneProvider.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.standalone; - -import java.util.Properties; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleListenerService; -import org.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleRegisterService; -import org.skywalking.apm.collector.core.CollectorException; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.core.util.Const; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ClusterModuleStandaloneProvider extends ModuleProvider { - - private final Logger logger = LoggerFactory.getLogger(ClusterModuleStandaloneProvider.class); - - private static final String URL = "url"; - private static final String USER_NAME = "user_name"; - - private H2Client h2Client; - private ClusterStandaloneDataMonitor dataMonitor; - - @Override public String name() { - return "standalone"; - } - - @Override public Class module() { - return ClusterModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.dataMonitor = new ClusterStandaloneDataMonitor(); - - final String url = config.getProperty(URL); - final String userName = config.getProperty(USER_NAME); - h2Client = new H2Client(url, userName, Const.EMPTY_STRING); - this.dataMonitor.setClient(h2Client); - - this.registerServiceImplementation(ModuleListenerService.class, new StandaloneModuleListenerService(dataMonitor)); - this.registerServiceImplementation(ModuleRegisterService.class, new StandaloneModuleRegisterService(dataMonitor)); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - try { - h2Client.initialize(); - } catch (H2ClientException e) { - logger.error(e.getMessage(), e); - } - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - try { - dataMonitor.start(); - } catch (CollectorException e) { - throw new UnexpectedException(e.getMessage()); - } - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java deleted file mode 100644 index c3ff41d2595f..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/ClusterStandaloneDataMonitor.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.standalone; - -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.ClientException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.cluster.DataMonitor; -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.core.CollectorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ClusterStandaloneDataMonitor implements DataMonitor { - - private final Logger logger = LoggerFactory.getLogger(ClusterStandaloneDataMonitor.class); - - private H2Client client; - - private Map listeners; - private Map registrations; - - public ClusterStandaloneDataMonitor() { - listeners = new LinkedHashMap<>(); - registrations = new LinkedHashMap<>(); - } - - @Override public void setClient(Client client) { - this.client = (H2Client)client; - } - - @Override - public void addListener(ClusterModuleListener listener) { - String path = BASE_CATALOG + listener.path(); - logger.info("listener path: {}", path); - listeners.put(path, listener); - } - - @Override public ClusterModuleListener getListener(String path) { - path = BASE_CATALOG + path; - return listeners.get(path); - } - - @Override public void register(String path, ModuleRegistration registration) { - registrations.put(BASE_CATALOG + path, registration); - } - - @Override public void createPath(String path) throws ClientException { - - } - - @Override public void setData(String path, String value) throws ClientException { - if (listeners.containsKey(path)) { - listeners.get(path).addAddress(value); - listeners.get(path).serverJoinNotify(value); - } - } - - public void start() throws CollectorException { - Iterator> entryIterator = registrations.entrySet().iterator(); - while (entryIterator.hasNext()) { - Map.Entry next = entryIterator.next(); - ModuleRegistration.Value value = next.getValue().buildValue(); - String contextPath = value.getContextPath() == null ? "" : value.getContextPath(); - setData(next.getKey(), value.getHostPort() + contextPath); - } - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java deleted file mode 100644 index a74e61f6e7fc..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleListenerService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.standalone.service; - -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.standalone.ClusterStandaloneDataMonitor; - -/** - * @author peng-yongsheng - */ -public class StandaloneModuleListenerService implements ModuleListenerService { - - private final ClusterStandaloneDataMonitor dataMonitor; - - public StandaloneModuleListenerService(ClusterStandaloneDataMonitor dataMonitor) { - this.dataMonitor = dataMonitor; - } - - @Override public void addListener(ClusterModuleListener listener) { - dataMonitor.addListener(listener); - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java deleted file mode 100644 index 23b8b1ad23f2..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/java/org/skywalking/apm/collector/cluster/standalone/service/StandaloneModuleRegisterService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.standalone.service; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.cluster.standalone.ClusterStandaloneDataMonitor; - -/** - * @author peng-yongsheng - */ -public class StandaloneModuleRegisterService implements ModuleRegisterService { - - private final ClusterStandaloneDataMonitor dataMonitor; - - public StandaloneModuleRegisterService(ClusterStandaloneDataMonitor dataMonitor) { - this.dataMonitor = dataMonitor; - } - - @Override public void register(String moduleName, String providerName, ModuleRegistration registration) { - String path = "/" + moduleName + "/" + providerName; - dataMonitor.register(path, registration); - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..a1efacc44cf5 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.cluster.standalone.ClusterModuleStandaloneProvider diff --git a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 8c29a96226df..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-standalone-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.cluster.standalone.ClusterModuleStandaloneProvider diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java new file mode 100644 index 000000000000..11a3a7b3d5c6 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.zookeeper; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.client.zookeeper.ZookeeperClientException; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.cluster.zookeeper.service.ZookeeperModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.zookeeper.service.ZookeeperModuleRegisterService; +import org.apache.skywalking.apm.collector.core.CollectorException; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.client.zookeeper.ZookeeperClient; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ClusterModuleZookeeperProvider extends ModuleProvider { + + private final Logger logger = LoggerFactory.getLogger(ClusterModuleZookeeperProvider.class); + + private static final String HOST_PORT = "hostPort"; + private static final String SESSION_TIMEOUT = "sessionTimeout"; + + private ZookeeperClient zookeeperClient; + private ClusterZKDataMonitor dataMonitor; + + @Override public String name() { + return "zookeeper"; + } + + @Override public Class module() { + return ClusterModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + dataMonitor = new ClusterZKDataMonitor(); + + final String hostPort = config.getProperty(HOST_PORT); + final int sessionTimeout = (Integer)config.get(SESSION_TIMEOUT); + zookeeperClient = new ZookeeperClient(hostPort, sessionTimeout, dataMonitor); + dataMonitor.setClient(zookeeperClient); + + this.registerServiceImplementation(ModuleListenerService.class, new ZookeeperModuleListenerService(dataMonitor)); + this.registerServiceImplementation(ModuleRegisterService.class, new ZookeeperModuleRegisterService(dataMonitor)); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + try { + zookeeperClient.initialize(); + } catch (ZookeeperClientException e) { + logger.error(e.getMessage(), e); + } + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + try { + dataMonitor.start(); + } catch (CollectorException e) { + throw new UnexpectedException(e.getMessage()); + } + } + + @Override public String[] requiredModules() { + return new String[0]; + } + +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java similarity index 80% rename from apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java rename to apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java index 15ca637bc8ca..8760e1655756 100644 --- a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java +++ b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.cluster.zookeeper; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.zookeeper; import java.util.HashSet; import java.util.Iterator; @@ -29,16 +47,16 @@ import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.Stat; -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.ClientException; -import org.skywalking.apm.collector.client.zookeeper.ZookeeperClient; -import org.skywalking.apm.collector.client.zookeeper.ZookeeperClientException; -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.cluster.ClusterNodeExistException; -import org.skywalking.apm.collector.cluster.DataMonitor; -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.core.CollectorException; -import org.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.zookeeper.ZookeeperClient; +import org.apache.skywalking.apm.collector.client.zookeeper.ZookeeperClientException; +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.cluster.ClusterNodeExistException; +import org.apache.skywalking.apm.collector.cluster.DataMonitor; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; +import org.apache.skywalking.apm.collector.core.CollectorException; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java new file mode 100644 index 000000000000..2ee2db463736 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.zookeeper.service; + +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.cluster.zookeeper.ClusterZKDataMonitor; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; + +/** + * @author peng-yongsheng + */ +public class ZookeeperModuleListenerService implements ModuleListenerService { + + private final ClusterZKDataMonitor dataMonitor; + + public ZookeeperModuleListenerService(ClusterZKDataMonitor dataMonitor) { + this.dataMonitor = dataMonitor; + } + + @Override public void addListener(ClusterModuleListener listener) { + dataMonitor.addListener(listener); + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java new file mode 100644 index 000000000000..0346e9bece42 --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/apache/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.cluster.zookeeper.service; + +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.cluster.zookeeper.ClusterZKDataMonitor; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; + +/** + * @author peng-yongsheng + */ +public class ZookeeperModuleRegisterService implements ModuleRegisterService { + + private final ClusterZKDataMonitor dataMonitor; + + public ZookeeperModuleRegisterService(ClusterZKDataMonitor dataMonitor) { + this.dataMonitor = dataMonitor; + } + + @Override public void register(String moduleName, String providerName, ModuleRegistration registration) { + String path = "/" + moduleName + "/" + providerName; + dataMonitor.register(path, registration); + } +} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java deleted file mode 100644 index 9155dd622739..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterModuleZookeeperProvider.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.zookeeper; - -import java.util.Properties; -import org.skywalking.apm.collector.client.zookeeper.ZookeeperClient; -import org.skywalking.apm.collector.client.zookeeper.ZookeeperClientException; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.cluster.zookeeper.service.ZookeeperModuleListenerService; -import org.skywalking.apm.collector.cluster.zookeeper.service.ZookeeperModuleRegisterService; -import org.skywalking.apm.collector.core.CollectorException; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ClusterModuleZookeeperProvider extends ModuleProvider { - - private final Logger logger = LoggerFactory.getLogger(ClusterModuleZookeeperProvider.class); - - private static final String HOST_PORT = "hostPort"; - private static final String SESSION_TIMEOUT = "sessionTimeout"; - - private ZookeeperClient zookeeperClient; - private ClusterZKDataMonitor dataMonitor; - - @Override public String name() { - return "zookeeper"; - } - - @Override public Class module() { - return ClusterModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - dataMonitor = new ClusterZKDataMonitor(); - - final String hostPort = config.getProperty(HOST_PORT); - final int sessionTimeout = (Integer)config.get(SESSION_TIMEOUT); - zookeeperClient = new ZookeeperClient(hostPort, sessionTimeout, dataMonitor); - dataMonitor.setClient(zookeeperClient); - - this.registerServiceImplementation(ModuleListenerService.class, new ZookeeperModuleListenerService(dataMonitor)); - this.registerServiceImplementation(ModuleRegisterService.class, new ZookeeperModuleRegisterService(dataMonitor)); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - try { - zookeeperClient.initialize(); - } catch (ZookeeperClientException e) { - logger.error(e.getMessage(), e); - } - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - try { - dataMonitor.start(); - } catch (CollectorException e) { - throw new UnexpectedException(e.getMessage()); - } - } - - @Override public String[] requiredModules() { - return new String[0]; - } - -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java deleted file mode 100644 index b12ef2c6609e..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleListenerService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.zookeeper.service; - -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.zookeeper.ClusterZKDataMonitor; - -/** - * @author peng-yongsheng - */ -public class ZookeeperModuleListenerService implements ModuleListenerService { - - private final ClusterZKDataMonitor dataMonitor; - - public ZookeeperModuleListenerService(ClusterZKDataMonitor dataMonitor) { - this.dataMonitor = dataMonitor; - } - - @Override public void addListener(ClusterModuleListener listener) { - dataMonitor.addListener(listener); - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java deleted file mode 100644 index 4a651906dac6..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/service/ZookeeperModuleRegisterService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.cluster.zookeeper.service; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.cluster.zookeeper.ClusterZKDataMonitor; - -/** - * @author peng-yongsheng - */ -public class ZookeeperModuleRegisterService implements ModuleRegisterService { - - private final ClusterZKDataMonitor dataMonitor; - - public ZookeeperModuleRegisterService(ClusterZKDataMonitor dataMonitor) { - this.dataMonitor = dataMonitor; - } - - @Override public void register(String moduleName, String providerName, ModuleRegistration registration) { - String path = "/" + moduleName + "/" + providerName; - dataMonitor.register(path, registration); - } -} diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..cafa032bd2df --- /dev/null +++ b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.cluster.zookeeper.ClusterModuleZookeeperProvider diff --git a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index dcfabeec5205..000000000000 --- a/apm-collector/apm-collector-cluster/collector-cluster-zookeeper-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.cluster.zookeeper.ClusterModuleZookeeperProvider diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/Client.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/Client.java new file mode 100644 index 000000000000..ce2a46af8bed --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/Client.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client; + +/** + * @author peng-yongsheng + */ +public interface Client { + void initialize() throws ClientException; + + void shutdown(); +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/ClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/ClientException.java new file mode 100644 index 000000000000..cc74eef58f48 --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/ClientException.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public abstract class ClientException extends CollectorException { + public ClientException(String message) { + super(message); + } + + public ClientException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java similarity index 86% rename from apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java rename to apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java index 6df9355ef2ae..805d0bd97e78 100644 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClient.java @@ -16,13 +16,32 @@ * */ -package org.skywalking.apm.collector.client.elasticsearch; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.elasticsearch; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ExecutionException; +import org.apache.skywalking.apm.collector.client.ClientException; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; @@ -40,8 +59,7 @@ import org.elasticsearch.index.reindex.DeleteByQueryAction; import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder; import org.elasticsearch.transport.client.PreBuiltTransportClient; -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.Client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java new file mode 100644 index 000000000000..85a1f1c8679d --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.elasticsearch; + +import org.apache.skywalking.apm.collector.client.ClientException; + +/** + * @author peng-yongsheng + */ +public class ElasticSearchClientException extends ClientException { + public ElasticSearchClientException(String message) { + super(message); + } + + public ElasticSearchClientException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClient.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClient.java new file mode 100644 index 000000000000..d256870b2787 --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClient.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.grpc; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.Client; + +/** + * @author peng-yongsheng + */ +public class GRPCClient implements Client { + + private final String host; + + private final int port; + + private ManagedChannel channel; + + public GRPCClient(String host, int port) { + this.host = host; + this.port = port; + } + + @Override public void initialize() throws ClientException { + channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build(); + } + + @Override public void shutdown() { + channel.shutdownNow(); + } + + public ManagedChannel getChannel() { + return channel; + } + + @Override public String toString() { + return host + ":" + port; + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClientException.java new file mode 100644 index 000000000000..3caa8312f93f --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/grpc/GRPCClientException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.grpc; + +import org.apache.skywalking.apm.collector.client.ClientException; + +/** + * @author peng-yongsheng + */ +public class GRPCClientException extends ClientException { + + public GRPCClientException(String message) { + super(message); + } + + public GRPCClientException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2Client.java similarity index 80% rename from apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java rename to apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2Client.java index 846fb6c48e1b..36a38ec1a7b2 100644 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2Client.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.client.h2; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.h2; import java.sql.Connection; import java.sql.DriverManager; @@ -25,7 +43,7 @@ import java.sql.SQLException; import java.sql.Statement; import org.h2.util.IOUtils; -import org.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.client.Client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2ClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2ClientException.java new file mode 100644 index 000000000000..70f99b969a10 --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/h2/H2ClientException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.h2; + +import org.apache.skywalking.apm.collector.client.ClientException; + +/** + * @author peng-yongsheng + */ +public class H2ClientException extends ClientException { + + public H2ClientException(String message) { + super(message); + } + + public H2ClientException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClient.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClient.java new file mode 100644 index 000000000000..e48248739e95 --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClient.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.redis; + +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.Client; +import redis.clients.jedis.Jedis; + +/** + * @author peng-yongsheng + */ +public class RedisClient implements Client { + + private Jedis jedis; + + private final String host; + private final int port; + + public RedisClient(String host, int port) { + this.host = host; + this.port = port; + } + + @Override public void initialize() throws ClientException { + jedis = new Jedis(host, port); + } + + @Override public void shutdown() { + + } + + public void setex(String key, int seconds, String value) { + jedis.setex(key, seconds, value); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClientException.java new file mode 100644 index 000000000000..84b4993f125f --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/redis/RedisClientException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.redis; + +import org.apache.skywalking.apm.collector.client.ClientException; + +/** + * @author peng-yongsheng + */ +public class RedisClientException extends ClientException { + + public RedisClientException(String message) { + super(message); + } + + public RedisClientException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java similarity index 80% rename from apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java rename to apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java index 51d484788709..f806de176d5f 100644 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClient.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.client.zookeeper; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.zookeeper; import java.io.IOException; import java.util.List; @@ -26,7 +44,7 @@ import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; -import org.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.client.Client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java new file mode 100644 index 000000000000..70e5f0adeb90 --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.zookeeper; + +import org.apache.skywalking.apm.collector.client.ClientException; + +/** + * @author peng-yongsheng + */ +public class ZookeeperClientException extends ClientException { + public ZookeeperClientException(String message) { + super(message); + } + + public ZookeeperClientException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/util/PathUtils.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/util/PathUtils.java new file mode 100644 index 000000000000..716c6e7c5f2c --- /dev/null +++ b/apm-collector/apm-collector-component/client-component/src/main/java/org/apache/skywalking/apm/collector/client/zookeeper/util/PathUtils.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.client.zookeeper.util; + +/** + * @author peng-yongsheng + */ +public class PathUtils { + + public static String convertKey2Path(String key) { + String[] keys = key.split("\\."); + StringBuilder pathBuilder = new StringBuilder(); + for (String subPath : keys) { + pathBuilder.append("/").append(subPath); + } + return pathBuilder.toString(); + } +} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/Client.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/Client.java deleted file mode 100644 index 7e78d5df6d84..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/Client.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client; - -/** - * @author peng-yongsheng - */ -public interface Client { - void initialize() throws ClientException; - - void shutdown(); -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/ClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/ClientException.java deleted file mode 100644 index 3f59ce68ff74..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/ClientException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public abstract class ClientException extends CollectorException { - public ClientException(String message) { - super(message); - } - - public ClientException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java deleted file mode 100644 index 6a6125440ee6..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/elasticsearch/ElasticSearchClientException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.elasticsearch; - -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public class ElasticSearchClientException extends ClientException { - public ElasticSearchClientException(String message) { - super(message); - } - - public ElasticSearchClientException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClient.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClient.java deleted file mode 100644 index a02a9ffaf945..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClient.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.grpc; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public class GRPCClient implements Client { - - private final String host; - - private final int port; - - private ManagedChannel channel; - - public GRPCClient(String host, int port) { - this.host = host; - this.port = port; - } - - @Override public void initialize() throws ClientException { - channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build(); - } - - @Override public void shutdown() { - channel.shutdownNow(); - } - - public ManagedChannel getChannel() { - return channel; - } - - @Override public String toString() { - return host + ":" + port; - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClientException.java deleted file mode 100644 index 55e06dfd3a9d..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/grpc/GRPCClientException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.grpc; - -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public class GRPCClientException extends ClientException { - - public GRPCClientException(String message) { - super(message); - } - - public GRPCClientException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2ClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2ClientException.java deleted file mode 100644 index 75959e6010d3..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/h2/H2ClientException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.h2; - -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public class H2ClientException extends ClientException { - - public H2ClientException(String message) { - super(message); - } - - public H2ClientException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClient.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClient.java deleted file mode 100644 index 5840d3b67034..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClient.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.redis; - -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.ClientException; -import redis.clients.jedis.Jedis; - -/** - * @author peng-yongsheng - */ -public class RedisClient implements Client { - - private Jedis jedis; - - private final String host; - private final int port; - - public RedisClient(String host, int port) { - this.host = host; - this.port = port; - } - - @Override public void initialize() throws ClientException { - jedis = new Jedis(host, port); - } - - @Override public void shutdown() { - - } - - public void setex(String key, int seconds, String value) { - jedis.setex(key, seconds, value); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClientException.java deleted file mode 100644 index 4a477c26b3fe..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/redis/RedisClientException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.redis; - -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public class RedisClientException extends ClientException { - - public RedisClientException(String message) { - super(message); - } - - public RedisClientException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java deleted file mode 100644 index 9a6e3a2739a9..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/ZookeeperClientException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.zookeeper; - -import org.skywalking.apm.collector.client.ClientException; - -/** - * @author peng-yongsheng - */ -public class ZookeeperClientException extends ClientException { - public ZookeeperClientException(String message) { - super(message); - } - - public ZookeeperClientException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/util/PathUtils.java b/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/util/PathUtils.java deleted file mode 100644 index a89df40389e7..000000000000 --- a/apm-collector/apm-collector-component/client-component/src/main/java/org/skywalking/apm/collector/client/zookeeper/util/PathUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.client.zookeeper.util; - -/** - * @author peng-yongsheng - */ -public class PathUtils { - - public static String convertKey2Path(String key) { - String[] keys = key.split("\\."); - StringBuilder pathBuilder = new StringBuilder(); - for (String subPath : keys) { - pathBuilder.append("/").append(subPath); - } - return pathBuilder.toString(); - } -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/Server.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/Server.java new file mode 100644 index 000000000000..790e2cfefc0b --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/Server.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server; + +/** + * @author peng-yongsheng + */ +public interface Server { + + String hostPort(); + + String serverClassify(); + + void initialize() throws ServerException; + + void start() throws ServerException; + + void addHandler(ServerHandler handler); +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerException.java new file mode 100644 index 000000000000..91ee25b51541 --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public abstract class ServerException extends CollectorException { + + public ServerException(String message) { + super(message); + } + + public ServerException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerHandler.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerHandler.java new file mode 100644 index 000000000000..c57702889d1f --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/ServerHandler.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server; + +/** + * @author peng-yongsheng + */ +public interface ServerHandler { +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCHandler.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCHandler.java new file mode 100644 index 000000000000..9bb65439987e --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCHandler.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.grpc; + +import org.apache.skywalking.apm.collector.server.ServerHandler; + +/** + * @author peng-yongsheng + */ +public interface GRPCHandler extends ServerHandler { +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServer.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServer.java new file mode 100644 index 000000000000..236c640d5e4c --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServer.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.grpc; + +import io.grpc.netty.NettyServerBuilder; +import java.io.IOException; +import java.net.InetSocketAddress; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.server.ServerException; +import org.apache.skywalking.apm.collector.server.ServerHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GRPCServer implements Server { + + private final Logger logger = LoggerFactory.getLogger(GRPCServer.class); + + private final String host; + private final int port; + private io.grpc.Server server; + private NettyServerBuilder nettyServerBuilder; + + public GRPCServer(String host, int port) { + this.host = host; + this.port = port; + } + + @Override public String hostPort() { + return host + ":" + port; + } + + @Override public String serverClassify() { + return "Google-RPC"; + } + + @Override public void initialize() throws ServerException { + InetSocketAddress address = new InetSocketAddress(host, port); + nettyServerBuilder = NettyServerBuilder.forAddress(address); + logger.info("Server started, host {} listening on {}", host, port); + } + + @Override public void start() throws ServerException { + try { + server = nettyServerBuilder.build(); + server.start(); + } catch (IOException e) { + throw new GRPCServerException(e.getMessage(), e); + } + } + + @Override public void addHandler(ServerHandler handler) { + nettyServerBuilder.addService((io.grpc.BindableService)handler); + } +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServerException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServerException.java new file mode 100644 index 000000000000..f8461307c0ce --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/grpc/GRPCServerException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.grpc; + +import org.apache.skywalking.apm.collector.server.ServerException; + +/** + * @author peng-yongsheng + */ +public class GRPCServerException extends ServerException { + + public GRPCServerException(String message) { + super(message); + } + + public GRPCServerException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/ArgumentsParseException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/ArgumentsParseException.java new file mode 100644 index 000000000000..900d1e30731a --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/ArgumentsParseException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.jetty; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public class ArgumentsParseException extends CollectorException { + + public ArgumentsParseException(String message) { + super(message); + } + + public ArgumentsParseException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyHandler.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java similarity index 84% rename from apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyHandler.java rename to apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java index 2af23b0a3aa3..4eb8cf8d204e 100644 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyHandler.java +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.server.jetty; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.jetty; import com.google.gson.JsonElement; import java.io.IOException; @@ -30,8 +48,8 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.server.ServerHandler; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.server.ServerHandler; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServer.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServer.java new file mode 100644 index 000000000000..f7e6c237206d --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServer.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.jetty; + +import java.net.InetSocketAddress; +import javax.servlet.http.HttpServlet; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.servlet.ServletMapping; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.server.ServerException; +import org.apache.skywalking.apm.collector.server.ServerHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class JettyServer implements Server { + + private final Logger logger = LoggerFactory.getLogger(JettyServer.class); + + private final String host; + private final int port; + private final String contextPath; + private org.eclipse.jetty.server.Server server; + private ServletContextHandler servletContextHandler; + + public JettyServer(String host, int port, String contextPath) { + this.host = host; + this.port = port; + this.contextPath = contextPath; + } + + @Override public String hostPort() { + return host + ":" + port; + } + + @Override public String serverClassify() { + return "Jetty"; + } + + @Override public void initialize() throws ServerException { + server = new org.eclipse.jetty.server.Server(new InetSocketAddress(host, port)); + + servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); + servletContextHandler.setContextPath(contextPath); + logger.info("http server root context path: {}", contextPath); + + server.setHandler(servletContextHandler); + } + + @Override public void addHandler(ServerHandler handler) { + ServletHolder servletHolder = new ServletHolder(); + servletHolder.setServlet((HttpServlet)handler); + servletContextHandler.addServlet(servletHolder, ((JettyHandler)handler).pathSpec()); + } + + @Override public void start() throws ServerException { + logger.info("start server, host: {}, port: {}", host, port); + try { + for (ServletMapping servletMapping : servletContextHandler.getServletHandler().getServletMappings()) { + logger.info("jetty servlet mappings: {} register by {}", servletMapping.getPathSpecs(), servletMapping.getServletName()); + } + server.start(); + } catch (Exception e) { + throw new JettyServerException(e.getMessage(), e); + } + } +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServerException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServerException.java new file mode 100644 index 000000000000..ea839027ee24 --- /dev/null +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyServerException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.server.jetty; + +import org.apache.skywalking.apm.collector.server.ServerException; + +/** + * @author peng-yongsheng + */ +public class JettyServerException extends ServerException { + + public JettyServerException(String message) { + super(message); + } + + public JettyServerException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/Server.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/Server.java deleted file mode 100644 index 8d93b09efc99..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/Server.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server; - -/** - * @author peng-yongsheng - */ -public interface Server { - - String hostPort(); - - String serverClassify(); - - void initialize() throws ServerException; - - void start() throws ServerException; - - void addHandler(ServerHandler handler); -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerException.java deleted file mode 100644 index 4d656ddb5831..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public abstract class ServerException extends CollectorException { - - public ServerException(String message) { - super(message); - } - - public ServerException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerHandler.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerHandler.java deleted file mode 100644 index d9500605dadf..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/ServerHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server; - -/** - * @author peng-yongsheng - */ -public interface ServerHandler { -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCHandler.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCHandler.java deleted file mode 100644 index 0f78ff06ac12..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server.grpc; - -import org.skywalking.apm.collector.server.ServerHandler; - -/** - * @author peng-yongsheng - */ -public interface GRPCHandler extends ServerHandler { -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServer.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServer.java deleted file mode 100644 index f35b43378e5d..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server.grpc; - -import io.grpc.netty.NettyServerBuilder; -import java.io.IOException; -import java.net.InetSocketAddress; -import org.skywalking.apm.collector.server.Server; -import org.skywalking.apm.collector.server.ServerException; -import org.skywalking.apm.collector.server.ServerHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GRPCServer implements Server { - - private final Logger logger = LoggerFactory.getLogger(GRPCServer.class); - - private final String host; - private final int port; - private io.grpc.Server server; - private NettyServerBuilder nettyServerBuilder; - - public GRPCServer(String host, int port) { - this.host = host; - this.port = port; - } - - @Override public String hostPort() { - return host + ":" + port; - } - - @Override public String serverClassify() { - return "Google-RPC"; - } - - @Override public void initialize() throws ServerException { - InetSocketAddress address = new InetSocketAddress(host, port); - nettyServerBuilder = NettyServerBuilder.forAddress(address); - logger.info("Server started, host {} listening on {}", host, port); - } - - @Override public void start() throws ServerException { - try { - server = nettyServerBuilder.build(); - server.start(); - } catch (IOException e) { - throw new GRPCServerException(e.getMessage(), e); - } - } - - @Override public void addHandler(ServerHandler handler) { - nettyServerBuilder.addService((io.grpc.BindableService)handler); - } -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServerException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServerException.java deleted file mode 100644 index fe87f64206b0..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/grpc/GRPCServerException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server.grpc; - -import org.skywalking.apm.collector.server.ServerException; - -/** - * @author peng-yongsheng - */ -public class GRPCServerException extends ServerException { - - public GRPCServerException(String message) { - super(message); - } - - public GRPCServerException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/ArgumentsParseException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/ArgumentsParseException.java deleted file mode 100644 index b3876ab7a7b6..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/ArgumentsParseException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server.jetty; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public class ArgumentsParseException extends CollectorException { - - public ArgumentsParseException(String message) { - super(message); - } - - public ArgumentsParseException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServer.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServer.java deleted file mode 100644 index 3fd4f989ef15..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServer.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server.jetty; - -import java.net.InetSocketAddress; -import javax.servlet.http.HttpServlet; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.servlet.ServletMapping; -import org.skywalking.apm.collector.server.Server; -import org.skywalking.apm.collector.server.ServerException; -import org.skywalking.apm.collector.server.ServerHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class JettyServer implements Server { - - private final Logger logger = LoggerFactory.getLogger(JettyServer.class); - - private final String host; - private final int port; - private final String contextPath; - private org.eclipse.jetty.server.Server server; - private ServletContextHandler servletContextHandler; - - public JettyServer(String host, int port, String contextPath) { - this.host = host; - this.port = port; - this.contextPath = contextPath; - } - - @Override public String hostPort() { - return host + ":" + port; - } - - @Override public String serverClassify() { - return "Jetty"; - } - - @Override public void initialize() throws ServerException { - server = new org.eclipse.jetty.server.Server(new InetSocketAddress(host, port)); - - servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); - servletContextHandler.setContextPath(contextPath); - logger.info("http server root context path: {}", contextPath); - - server.setHandler(servletContextHandler); - } - - @Override public void addHandler(ServerHandler handler) { - ServletHolder servletHolder = new ServletHolder(); - servletHolder.setServlet((HttpServlet)handler); - servletContextHandler.addServlet(servletHolder, ((JettyHandler)handler).pathSpec()); - } - - @Override public void start() throws ServerException { - logger.info("start server, host: {}, port: {}", host, port); - try { - for (ServletMapping servletMapping : servletContextHandler.getServletHandler().getServletMappings()) { - logger.info("jetty servlet mappings: {} register by {}", servletMapping.getPathSpecs(), servletMapping.getServletName()); - } - server.start(); - } catch (Exception e) { - throw new JettyServerException(e.getMessage(), e); - } - } -} diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServerException.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServerException.java deleted file mode 100644 index 32fdffaa7fcf..000000000000 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/skywalking/apm/collector/server/jetty/JettyServerException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.server.jetty; - -import org.skywalking.apm.collector.server.ServerException; - -/** - * @author peng-yongsheng - */ -public class JettyServerException extends ServerException { - - public JettyServerException(String message) { - super(message); - } - - public JettyServerException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModule.java b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModule.java new file mode 100644 index 000000000000..4adbf7b53a5d --- /dev/null +++ b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModule.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.configuration; + +import org.apache.skywalking.apm.collector.configuration.service.IApdexThresholdService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class ConfigurationModule extends Module { + + public static final String NAME = "configuration"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {IApdexThresholdService.class}; + } +} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/service/IApdexThresholdService.java b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/service/IApdexThresholdService.java new file mode 100644 index 000000000000..82b0736a21e5 --- /dev/null +++ b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/apache/skywalking/apm/collector/configuration/service/IApdexThresholdService.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.configuration.service; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface IApdexThresholdService extends Service { + + /** + * Apdex T applies to web transactions only + * + * @param applicationId + * @return This value is in milli-seconds. + */ + Integer getApplicationApdexThreshold(int applicationId); +} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModule.java b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModule.java deleted file mode 100644 index 1e5afa3108e8..000000000000 --- a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.configuration; - -import org.skywalking.apm.collector.configuration.service.IApdexThresholdService; -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class ConfigurationModule extends Module { - - public static final String NAME = "configuration"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {IApdexThresholdService.class}; - } -} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/service/IApdexThresholdService.java b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/service/IApdexThresholdService.java deleted file mode 100644 index 5bfbfef2139c..000000000000 --- a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/java/org/skywalking/apm/collector/configuration/service/IApdexThresholdService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.configuration.service; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface IApdexThresholdService extends Service { - - /** - * Apdex T applies to web transactions only - * - * @param applicationId - * @return This value is in milli-seconds. - */ - Integer getApplicationApdexThreshold(int applicationId); -} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..5e282b6518ea --- /dev/null +++ b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.configuration.ConfigurationModule diff --git a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 6b31dd1e9b88..000000000000 --- a/apm-collector/apm-collector-configuration/collector-configuration-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.configuration.ConfigurationModule diff --git a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java new file mode 100644 index 000000000000..cb55b9e3cc60 --- /dev/null +++ b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.configuration; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.configuration.service.ApdexThresholdService; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.configuration.service.IApdexThresholdService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class ConfigurationModuleProvider extends ModuleProvider { + + @Override public String name() { + return "default"; + } + + @Override public Class module() { + return ConfigurationModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(IApdexThresholdService.class, new ApdexThresholdService()); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/service/ApdexThresholdService.java b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/service/ApdexThresholdService.java new file mode 100644 index 000000000000..49bb023ba338 --- /dev/null +++ b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/apache/skywalking/apm/collector/configuration/service/ApdexThresholdService.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.configuration.service; + +/** + * @author peng-yongsheng + */ +public class ApdexThresholdService implements IApdexThresholdService { + + /** + * Apdex T applies to web transactions only + * + * @param applicationId + * @return This value is in milli-seconds. + */ + @Override public Integer getApplicationApdexThreshold(int applicationId) { + return 1000; + } +} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java deleted file mode 100644 index 744c47a6e45a..000000000000 --- a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/ConfigurationModuleProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.configuration; - -import java.util.Properties; -import org.skywalking.apm.collector.configuration.service.ApdexThresholdService; -import org.skywalking.apm.collector.configuration.service.IApdexThresholdService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; - -/** - * @author peng-yongsheng - */ -public class ConfigurationModuleProvider extends ModuleProvider { - - @Override public String name() { - return "default"; - } - - @Override public Class module() { - return ConfigurationModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(IApdexThresholdService.class, new ApdexThresholdService()); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/service/ApdexThresholdService.java b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/service/ApdexThresholdService.java deleted file mode 100644 index f28fe5e821c3..000000000000 --- a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/java/org/skywalking/apm/collector/configuration/service/ApdexThresholdService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.configuration.service; - -/** - * @author peng-yongsheng - */ -public class ApdexThresholdService implements IApdexThresholdService { - - /** - * Apdex T applies to web transactions only - * - * @param applicationId - * @return This value is in milli-seconds. - */ - @Override public Integer getApplicationApdexThreshold(int applicationId) { - return 1000; - } -} diff --git a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..716552e3604c --- /dev/null +++ b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.configuration.ConfigurationModuleProvider diff --git a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 5f0a0b553f35..000000000000 --- a/apm-collector/apm-collector-configuration/collector-configuration-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.configuration.ConfigurationModuleProvider diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/CollectorException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/CollectorException.java new file mode 100644 index 000000000000..755094702392 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/CollectorException.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core; + +/** + * @author peng-yongsheng + */ +public class CollectorException extends Exception { + + public CollectorException(String message) { + super(message); + } + + public CollectorException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/UnexpectedException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/UnexpectedException.java new file mode 100644 index 000000000000..df667b988c33 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/UnexpectedException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core; + +/** + * @author wu-sheng + */ +public class UnexpectedException extends RuntimeException { + public UnexpectedException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Collection.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Collection.java new file mode 100644 index 000000000000..f192c1d8c9be --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Collection.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.cache; + +/** + * @author peng-yongsheng + */ +public interface Collection { + + void reading(); + + boolean isReading(); + + void writing(); + + boolean isWriting(); + + void clear(); + + int size(); + + void finishReading(); + + void finishWriting(); + + Data collection(); +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Window.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Window.java new file mode 100644 index 000000000000..f46b1bfa9196 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/cache/Window.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.cache; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author peng-yongsheng + */ +public abstract class Window { + + private AtomicInteger windowSwitch = new AtomicInteger(0); + + private WINDOW_COLLECTION pointer; + + private WINDOW_COLLECTION windowDataA; + private WINDOW_COLLECTION windowDataB; + + protected Window() { + this.windowDataA = collectionInstance(); + this.windowDataB = collectionInstance(); + this.pointer = windowDataA; + } + + public abstract WINDOW_COLLECTION collectionInstance(); + + public boolean trySwitchPointer() { + return windowSwitch.incrementAndGet() == 1 && !getLast().isReading(); + } + + public void trySwitchPointerFinally() { + windowSwitch.addAndGet(-1); + } + + public void switchPointer() { + if (pointer == windowDataA) { + pointer = windowDataB; + } else { + pointer = windowDataA; + } + getLast().reading(); + } + + protected WINDOW_COLLECTION getCurrentAndWriting() { + if (pointer == windowDataA) { + windowDataA.writing(); + return windowDataA; + } else { + windowDataB.writing(); + return windowDataB; + } + } + + protected WINDOW_COLLECTION getCurrent() { + return pointer; + } + + public WINDOW_COLLECTION getLast() { + if (pointer == windowDataA) { + return windowDataB; + } else { + return windowDataA; + } + } + + public void finishReadingLast() { + getLast().clear(); + getLast().finishReading(); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessage.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessage.java new file mode 100644 index 000000000000..0b008855639d --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessage.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * The AbstractHashMessage implementations represent aggregate message, + * which use to aggregate metric. + *

+ * + * @author peng-yongsheng + * @since v3.0-2017 + */ +public abstract class AbstractHashMessage { + private int hashCode; + + public AbstractHashMessage(String key) { + this.hashCode = key.hashCode(); + } + + public int getHashCode() { + return hashCode; + } + + public void setKey(String key) { + this.hashCode = key.hashCode(); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Attribute.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Attribute.java new file mode 100644 index 000000000000..5ec9a7e4ff3e --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Attribute.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public class Attribute { + private final String name; + private final AttributeType type; + private final Operation operation; + + public Attribute(String name, AttributeType type, Operation operation) { + this.name = name; + this.type = type; + this.operation = operation; + } + + public String getName() { + return name; + } + + public AttributeType getType() { + return type; + } + + public Operation getOperation() { + return operation; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AttributeType.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AttributeType.java new file mode 100644 index 000000000000..874e34badc43 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/AttributeType.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public enum AttributeType { + STRING, LONG, DOUBLE, INTEGER, BYTE, BOOLEAN +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Column.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Column.java new file mode 100644 index 000000000000..78037f511106 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Column.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public class Column { + private final String name; + private final Operation operation; + + public Column(String name, Operation operation) { + this.name = name; + this.operation = operation; + } + + public String getName() { + return name; + } + + public Operation getOperation() { + return operation; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/ColumnDefine.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/ColumnDefine.java new file mode 100644 index 000000000000..50b92e5358bf --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/ColumnDefine.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public abstract class ColumnDefine { + private final String name; + private final String type; + + public ColumnDefine(String name, String type) { + this.name = name; + this.type = type; + } + + public final String getName() { + return name; + } + + public String getType() { + return type; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/CommonTable.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/CommonTable.java new file mode 100644 index 000000000000..9c01e8eefde5 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/CommonTable.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public abstract class CommonTable { + public static final String TABLE_TYPE = "type"; + public static final String COLUMN_ID = "id"; + public static final String COLUMN_TIME_BUCKET = "time_bucket"; +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Data.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Data.java similarity index 89% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Data.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Data.java index 6e59d7542000..37b083ef5557 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Data.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Data.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.data; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java new file mode 100644 index 000000000000..815b9aad413c --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public abstract class EndOfBatchQueueMessage extends AbstractHashMessage { + + private boolean endOfBatch; + + public EndOfBatchQueueMessage(String key) { + super(key); + endOfBatch = false; + } + + public final boolean isEndOfBatch() { + return endOfBatch; + } + + public final void setEndOfBatch(boolean endOfBatch) { + this.endOfBatch = endOfBatch; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Operation.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Operation.java new file mode 100644 index 000000000000..eca3c5b752cd --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/Operation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +/** + * @author peng-yongsheng + */ +public interface Operation { + String operate(String newValue, String oldValue); + + Long operate(Long newValue, Long oldValue); + + Double operate(Double newValue, Double oldValue); + + Integer operate(Integer newValue, Integer oldValue); + + Boolean operate(Boolean newValue, Boolean oldValue); + + byte[] operate(byte[] newValue, byte[] oldValue); +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefineLoader.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefineLoader.java new file mode 100644 index 000000000000..e35ae90bc0a1 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefineLoader.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.define.DefineException; +import org.apache.skywalking.apm.collector.core.define.DefinitionLoader; +import org.apache.skywalking.apm.collector.core.define.Loader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class StorageDefineLoader implements Loader> { + + private final Logger logger = LoggerFactory.getLogger(StorageDefineLoader.class); + + @Override public List load() throws DefineException { + List tableDefines = new LinkedList<>(); + + StorageDefinitionFile definitionFile = new StorageDefinitionFile(); + logger.info("storage definition file name: {}", definitionFile.fileName()); + DefinitionLoader definitionLoader = DefinitionLoader.load(TableDefine.class, definitionFile); + for (TableDefine tableDefine : definitionLoader) { + logger.info("loaded storage definition class: {}", tableDefine.getClass().getName()); + tableDefines.add(tableDefine); + } + return tableDefines; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefinitionFile.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefinitionFile.java new file mode 100644 index 000000000000..4060afa8a811 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/StorageDefinitionFile.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +import org.apache.skywalking.apm.collector.core.define.DefinitionFile; + +/** + * @author peng-yongsheng + */ +public class StorageDefinitionFile extends DefinitionFile { + @Override protected String fileName() { + return "storage.define"; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/TableDefine.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/TableDefine.java new file mode 100644 index 000000000000..34fd27484dab --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/TableDefine.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public abstract class TableDefine { + private final String name; + private final List columnDefines; + + public TableDefine(String name) { + this.name = name; + this.columnDefines = new LinkedList<>(); + } + + public abstract void initialize(); + + public final void addColumn(ColumnDefine columnDefine) { + columnDefines.add(columnDefine); + } + + public final String getName() { + return name; + } + + public final List getColumnDefines() { + return columnDefines; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/AddOperation.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/AddOperation.java new file mode 100644 index 000000000000..475ab73d582a --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/AddOperation.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data.operator; + +import org.apache.skywalking.apm.collector.core.data.Operation; + +/** + * @author peng-yongsheng + */ +public class AddOperation implements Operation { + + @Override public String operate(String newValue, String oldValue) { + throw new UnsupportedOperationException("not support string addition operation"); + } + + @Override public Long operate(Long newValue, Long oldValue) { + return newValue + oldValue; + } + + @Override public Double operate(Double newValue, Double oldValue) { + return newValue + oldValue; + } + + @Override public Integer operate(Integer newValue, Integer oldValue) { + return newValue + oldValue; + } + + @Override public Boolean operate(Boolean newValue, Boolean oldValue) { + throw new UnsupportedOperationException("not support boolean addition operation"); + } + + @Override public byte[] operate(byte[] newValue, byte[] oldValue) { + throw new UnsupportedOperationException("not support byte addition operation"); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/CoverOperation.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/CoverOperation.java new file mode 100644 index 000000000000..3140e9177397 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/CoverOperation.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data.operator; + +import org.apache.skywalking.apm.collector.core.data.Operation; + +/** + * @author peng-yongsheng + */ +public class CoverOperation implements Operation { + @Override public String operate(String newValue, String oldValue) { + return newValue; + } + + @Override public Long operate(Long newValue, Long oldValue) { + return newValue; + } + + @Override public Double operate(Double newValue, Double oldValue) { + return newValue; + } + + @Override public Integer operate(Integer newValue, Integer oldValue) { + return newValue; + } + + @Override public Boolean operate(Boolean newValue, Boolean oldValue) { + return newValue; + } + + @Override public byte[] operate(byte[] newValue, byte[] oldValue) { + return newValue; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/NonOperation.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/NonOperation.java new file mode 100644 index 000000000000..578cf9fe7ff3 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/data/operator/NonOperation.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data.operator; + +import org.apache.skywalking.apm.collector.core.data.Operation; + +/** + * @author peng-yongsheng + */ +public class NonOperation implements Operation { + @Override public String operate(String newValue, String oldValue) { + return oldValue; + } + + @Override public Long operate(Long newValue, Long oldValue) { + return oldValue; + } + + @Override public Double operate(Double newValue, Double oldValue) { + return oldValue; + } + + @Override public Integer operate(Integer newValue, Integer oldValue) { + return oldValue; + } + + @Override public Boolean operate(Boolean newValue, Boolean oldValue) { + return oldValue; + } + + @Override public byte[] operate(byte[] newValue, byte[] oldValue) { + return oldValue; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefineException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefineException.java new file mode 100644 index 000000000000..3bc66f5306c7 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefineException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public abstract class DefineException extends CollectorException { + + public DefineException(String message) { + super(message); + } + + public DefineException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionFile.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionFile.java new file mode 100644 index 000000000000..743523506210 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionFile.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; + +/** + * @author peng-yongsheng + */ +public abstract class DefinitionFile { + + private static final String CATALOG = "META-INF/defines/"; + + protected abstract String fileName(); + + public final String get() { + return CATALOG + fileName(); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionLoader.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionLoader.java similarity index 80% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionLoader.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionLoader.java index 18e709b10aa9..72249b2b8306 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionLoader.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/DefinitionLoader.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; import java.io.BufferedReader; import java.io.IOException; diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/Loader.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/Loader.java new file mode 100644 index 000000000000..ec30081fdf1a --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/define/Loader.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; + +/** + * @author peng-yongsheng + */ +public interface Loader { + T load() throws DefineException; +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/framework/Executor.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/framework/Executor.java new file mode 100644 index 000000000000..adc51afe10f9 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/framework/Executor.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.framework; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public interface Executor { + void execute(INPUT input) throws CollectorException; +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/DirectWay.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/DirectWay.java new file mode 100644 index 000000000000..7c6bd2689d0a --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/DirectWay.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class DirectWay extends WayToNode { + public DirectWay(NodeProcessor destinationHandler) { + super(destinationHandler); + } + + @Override protected void in(INPUT o) { + out(o); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Graph.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Graph.java new file mode 100644 index 000000000000..6fa81ecb5f7d --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Graph.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author peng-yongsheng, wu-sheng + */ +public final class Graph { + private int id; + private WayToNode entryWay; + private ConcurrentHashMap nodeIndex = new ConcurrentHashMap<>(); + + Graph(int id) { + this.id = id; + } + + public void start(INPUT input) { + entryWay.in(input); + } + + public Node addNode(NodeProcessor nodeProcessor) { + return addNode(new DirectWay(nodeProcessor)); + } + + public Node addNode(WayToNode entryWay) { + synchronized (this) { + this.entryWay = entryWay; + this.entryWay.buildDestination(this); + return entryWay.getDestination(); + } + } + + void checkForNewNode(Node node) { + int nodeId = node.getHandler().id(); + if (nodeIndex.containsKey(nodeId)) { + throw new PotentialCyclicGraphException("handler=" + + node.getHandler().getClass().getName() + + " already exists in graph[" + id + "]"); + } + nodeIndex.put(nodeId, node); + } + + public GraphNodeFinder toFinder() { + return new GraphNodeFinder(this); + } + + ConcurrentHashMap getNodeIndex() { + return nodeIndex; + } + + int getId() { + return id; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphManager.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphManager.java new file mode 100644 index 000000000000..aad18a485b6b --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphManager.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author wusheng + */ +public enum GraphManager { + INSTANCE; + + private Map allGraphs = new HashMap<>(); + + /** + * Create a stream process graph. + * + * @param graphId represents a graph, which is used for finding it. + * @return + */ + public synchronized Graph createIfAbsent(int graphId, Class input) { + if (!allGraphs.containsKey(graphId)) { + Graph graph = new Graph(graphId); + allGraphs.put(graphId, graph); + return graph; + } else { + return allGraphs.get(graphId); + } + } + + public Graph findGraph(int graphId) { + Graph graph = allGraphs.get(graphId); + if (graph == null) { + throw new GraphNotFoundException("Graph id=" + graphId + " not found in this GraphManager"); + } + return graph; + } + + public void reset() { + allGraphs.clear(); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNodeFinder.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNodeFinder.java new file mode 100644 index 000000000000..a9e7f554f77c --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNodeFinder.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author wu-sheng + */ +public class GraphNodeFinder { + private Graph graph; + + GraphNodeFinder(Graph graph) { + this.graph = graph; + } + + public Next findNext(int handlerId) { + ConcurrentHashMap graphNodeIndex = graph.getNodeIndex(); + Node node = graphNodeIndex.get(handlerId); + if (node == null) { + throw new NodeNotFoundException("Can't find node with handlerId=" + + handlerId + + " in graph[" + graph.getId() + "]"); + } + return node.getNext(); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNotFoundException.java new file mode 100644 index 000000000000..3d88efb675ae --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/GraphNotFoundException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class GraphNotFoundException extends RuntimeException { + public GraphNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Next.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Next.java new file mode 100644 index 000000000000..937107b6e7fe --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Next.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.framework.Executor; + +/** + * The Next is a delegate object for the following {@link Node}. + * + * @author peng-yongsheng, wu-sheng + */ +public class Next implements Executor { + + private final List ways; + + public Next() { + this.ways = new LinkedList<>(); + } + + final void addWay(WayToNode way) { + ways.add(way); + } + + /** + * Drive to the next nodes + * + * @param input + */ + @Override public void execute(INPUT input) { + ways.forEach(way -> way.in(input)); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Node.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Node.java new file mode 100644 index 000000000000..fd446104fa8e --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/Node.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * The Node in the graph with explicit INPUT and OUTPUT types. + * + * @author peng-yongsheng, wu-sheng + */ +public final class Node { + private final NodeProcessor nodeProcessor; + private final Next next; + private final Graph graph; + + Node(Graph graph, NodeProcessor nodeProcessor) { + this.graph = graph; + this.nodeProcessor = nodeProcessor; + this.next = new Next<>(); + this.graph.checkForNewNode(this); + } + + public final Node addNext(NodeProcessor nodeProcessor) { + return this.addNext(new DirectWay(nodeProcessor)); + } + + public final Node addNext(WayToNode way) { + synchronized (graph) { + way.buildDestination(graph); + next.addWay(way); + return way.getDestination(); + } + } + + final void execute(INPUT input) { + nodeProcessor.process(input, next); + } + + NodeProcessor getHandler() { + return nodeProcessor; + } + + Next getNext() { + return next; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeNotFoundException.java new file mode 100644 index 000000000000..379c99b822a1 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeNotFoundException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class NodeNotFoundException extends RuntimeException { + public NodeNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeProcessor.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeProcessor.java new file mode 100644 index 000000000000..bf510621bb77 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/NodeProcessor.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author peng-yongsheng, wu-sheng + */ +public interface NodeProcessor { + /** + * The unique id in the certain graph. + * + * @return id + */ + int id(); + + void process(input input, Next next); +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java new file mode 100644 index 000000000000..d6066933f7d7 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class PotentialCyclicGraphException extends RuntimeException { + public PotentialCyclicGraphException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/WayToNode.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/WayToNode.java new file mode 100644 index 000000000000..9a61d8d425fb --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/graph/WayToNode.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public abstract class WayToNode { + private Node destination; + private NodeProcessor destinationHandler; + + public WayToNode(NodeProcessor destinationHandler) { + this.destinationHandler = destinationHandler; + } + + void buildDestination(Graph graph) { + destination = new Node(graph, destinationHandler); + } + + protected abstract void in(INPUT input); + + protected void out(INPUT input) { + destination.execute(input); + } + + Node getDestination() { + return destination; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ApplicationConfiguration.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfiguration.java similarity index 76% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ApplicationConfiguration.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfiguration.java index 6c024d54e263..e50215306070 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ApplicationConfiguration.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfiguration.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.module; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; import java.util.HashMap; import java.util.Properties; diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/BootstrapFlow.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/BootstrapFlow.java similarity index 84% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/BootstrapFlow.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/BootstrapFlow.java index e51d2551ff23..e31118bbca96 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/BootstrapFlow.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/BootstrapFlow.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.collector.core.module; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/CycleDependencyException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/CycleDependencyException.java new file mode 100644 index 000000000000..3219cde94521 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/CycleDependencyException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class CycleDependencyException extends RuntimeException { + public CycleDependencyException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/DuplicateProviderException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/DuplicateProviderException.java new file mode 100644 index 000000000000..8f4a2712e60e --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/DuplicateProviderException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +public class DuplicateProviderException extends Exception { + public DuplicateProviderException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Module.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Module.java similarity index 82% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Module.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Module.java index 41312faf0d27..8b21f3e6c608 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Module.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Module.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.module; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; import java.util.LinkedList; import java.util.List; diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleManager.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleManager.java similarity index 78% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleManager.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleManager.java index 8b8805e59699..34a31f9db4ef 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleManager.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleManager.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.module; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; import java.util.Arrays; import java.util.HashMap; diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundException.java new file mode 100644 index 000000000000..50e5a33967bb --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +public class ModuleNotFoundException extends Exception { + + public ModuleNotFoundException(Throwable cause) { + super(cause); + } + + public ModuleNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java new file mode 100644 index 000000000000..f4456032f7f1 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author peng-yongsheng + */ +public class ModuleNotFoundRuntimeException extends RuntimeException { + + public ModuleNotFoundRuntimeException(Throwable cause) { + super(cause); + } + + public ModuleNotFoundRuntimeException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleProvider.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleProvider.java similarity index 83% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleProvider.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleProvider.java index 7c763a43242e..060435a5ecf3 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleProvider.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ModuleProvider.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.module; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; import java.util.HashMap; import java.util.Map; diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ProviderNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ProviderNotFoundException.java new file mode 100644 index 000000000000..4617cc49440c --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ProviderNotFoundException.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +public class ProviderNotFoundException extends Exception { + public ProviderNotFoundException(String message) { + super(message); + } + + public ProviderNotFoundException(Throwable e) { + super(e); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Service.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Service.java new file mode 100644 index 000000000000..e0b84b058e98 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/Service.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * The Service implementation is a service provided by its own modules. + * + * And every {@link ModuleProvider} must provide all the given services of the {@link Module}. + * + * @author wu-sheng + */ +public interface Service { +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedException.java new file mode 100644 index 000000000000..352e64892f34 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +public class ServiceNotProvidedException extends Exception { + public ServiceNotProvidedException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java new file mode 100644 index 000000000000..71d6ce12634b --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +public class ServiceNotProvidedRuntimeException extends RuntimeException { + public ServiceNotProvidedRuntimeException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ApdexThresholdUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ApdexThresholdUtils.java new file mode 100644 index 000000000000..ed3f93e44f88 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ApdexThresholdUtils.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +/** + * @author peng-yongsheng + */ +public class ApdexThresholdUtils { + + public static Apdex compute(int threshold, long duration) { + if (duration <= threshold) { + return Apdex.Satisfied; + } else if (duration <= threshold * 4) { + return Apdex.Tolerating; + } else { + return Apdex.Frustrated; + } + } + + public enum Apdex { + Satisfied, Tolerating, Frustrated + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BytesUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BytesUtils.java new file mode 100644 index 000000000000..172f61cea163 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BytesUtils.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +/** + * @author peng-yongsheng + */ +public class BytesUtils { + + public static byte[] long2Bytes(long num) { + byte[] byteNum = new byte[8]; + for (int ix = 0; ix < 8; ++ix) { + int offset = 64 - (ix + 1) * 8; + byteNum[ix] = (byte)((num >> offset) & 0xff); + } + return byteNum; + } + + public static long bytes2Long(byte[] byteNum) { + long num = 0; + for (int ix = 0; ix < 8; ++ix) { + num <<= 8; + num |= byteNum[ix] & 0xff; + } + return num; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/CollectionUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/CollectionUtils.java new file mode 100644 index 000000000000..4bfa74760e5d --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/CollectionUtils.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author peng-yongsheng + */ +public class CollectionUtils { + + public static boolean isEmpty(Map map) { + return map == null || map.size() == 0; + } + + public static boolean isEmpty(List list) { + return list == null || list.size() == 0; + } + + public static boolean isEmpty(Set set) { + return set == null || set.size() == 0; + } + + public static boolean isNotEmpty(List list) { + return !isEmpty(list); + } + + public static boolean isNotEmpty(Set set) { + return !isEmpty(set); + } + + public static boolean isNotEmpty(Map map) { + return !isEmpty(map); + } + + public static boolean isNotEmpty(T[] array) { + return array != null && array.length > 0; + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtils.java new file mode 100644 index 000000000000..d2ad518b63d0 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtils.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +/** + * @author peng-yongsheng + */ +public enum ColumnNameUtils { + INSTANCE; + + public String rename(String columnName) { + StringBuilder renamedColumnName = new StringBuilder(); + char[] chars = columnName.toLowerCase().toCharArray(); + + boolean findUnderline = false; + for (char character : chars) { + if (character == '_') { + findUnderline = true; + } else if (findUnderline) { + renamedColumnName.append(String.valueOf(character).toUpperCase()); + findUnderline = false; + } else { + renamedColumnName.append(character); + } + } + return renamedColumnName.toString(); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/Const.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/Const.java new file mode 100644 index 000000000000..7e6ee2f4f5c9 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/Const.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +/** + * @author peng-yongsheng + */ +public class Const { + public static final String ID_SPLIT = "_"; + public static final int USER_ID = 1; + public static final int NONE_SERVICE_ID = 1; + public static final int NONE_INSTANCE_ID = 1; + public static final String NONE_SERVICE_NAME = "None"; + public static final String USER_CODE = "User"; + public static final String SEGMENT_SPAN_SPLIT = "S"; + public static final String UNKNOWN = "Unknown"; + public static final String EXCEPTION = "Exception"; + public static final String EMPTY_STRING = ""; + public static final String FILE_SUFFIX = "sw"; +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ObjectUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ObjectUtils.java new file mode 100644 index 000000000000..79d55b6b55c0 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ObjectUtils.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +/** + * @author peng-yongsheng + */ +public class ObjectUtils { + public static boolean isEmpty(Object obj) { + return obj == null; + } + + public static boolean isNotEmpty(Object obj) { + return !isEmpty(obj); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ResourceUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ResourceUtils.java new file mode 100644 index 000000000000..2afde3bf65a7 --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/ResourceUtils.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; + +/** + * @author peng-yongsheng + */ +public class ResourceUtils { + + public static Reader read(String fileName) throws FileNotFoundException { + URL url = ResourceUtils.class.getClassLoader().getResource(fileName); + if (url == null) { + throw new FileNotFoundException("file not found: " + fileName); + } + InputStream inputStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName); + return new InputStreamReader(inputStream); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/StringUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/StringUtils.java new file mode 100644 index 000000000000..98ecf476191d --- /dev/null +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/StringUtils.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +/** + * @author peng-yongsheng + */ +public class StringUtils { + + public static final String EMPTY_STRING = ""; + + public static boolean isEmpty(Object str) { + return str == null || EMPTY_STRING.equals(str); + } + + public static boolean isNotEmpty(Object str) { + return !isEmpty(str); + } +} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/TimeBucketUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java similarity index 85% rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/TimeBucketUtils.java rename to apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java index f9ad3233b7c5..15e23a333ace 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/TimeBucketUtils.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.collector.core.util; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; -import org.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.UnexpectedException; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/CollectorException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/CollectorException.java deleted file mode 100644 index 4937a3262227..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/CollectorException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core; - -/** - * @author peng-yongsheng - */ -public class CollectorException extends Exception { - - public CollectorException(String message) { - super(message); - } - - public CollectorException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/UnexpectedException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/UnexpectedException.java deleted file mode 100644 index 1b5ef252653c..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/UnexpectedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core; - -/** - * @author wu-sheng - */ -public class UnexpectedException extends RuntimeException { - public UnexpectedException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Collection.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Collection.java deleted file mode 100644 index 91a471952d8b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Collection.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.cache; - -/** - * @author peng-yongsheng - */ -public interface Collection { - - void reading(); - - boolean isReading(); - - void writing(); - - boolean isWriting(); - - void clear(); - - int size(); - - void finishReading(); - - void finishWriting(); - - Data collection(); -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Window.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Window.java deleted file mode 100644 index 69f098b5c1d0..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/cache/Window.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.cache; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author peng-yongsheng - */ -public abstract class Window { - - private AtomicInteger windowSwitch = new AtomicInteger(0); - - private WINDOW_COLLECTION pointer; - - private WINDOW_COLLECTION windowDataA; - private WINDOW_COLLECTION windowDataB; - - protected Window() { - this.windowDataA = collectionInstance(); - this.windowDataB = collectionInstance(); - this.pointer = windowDataA; - } - - public abstract WINDOW_COLLECTION collectionInstance(); - - public boolean trySwitchPointer() { - return windowSwitch.incrementAndGet() == 1 && !getLast().isReading(); - } - - public void trySwitchPointerFinally() { - windowSwitch.addAndGet(-1); - } - - public void switchPointer() { - if (pointer == windowDataA) { - pointer = windowDataB; - } else { - pointer = windowDataA; - } - getLast().reading(); - } - - protected WINDOW_COLLECTION getCurrentAndWriting() { - if (pointer == windowDataA) { - windowDataA.writing(); - return windowDataA; - } else { - windowDataB.writing(); - return windowDataB; - } - } - - protected WINDOW_COLLECTION getCurrent() { - return pointer; - } - - public WINDOW_COLLECTION getLast() { - if (pointer == windowDataA) { - return windowDataB; - } else { - return windowDataA; - } - } - - public void finishReadingLast() { - getLast().clear(); - getLast().finishReading(); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AbstractHashMessage.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AbstractHashMessage.java deleted file mode 100644 index bf7a00b32d3f..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AbstractHashMessage.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * The AbstractHashMessage implementations represent aggregate message, - * which use to aggregate metric. - *

- * - * @author peng-yongsheng - * @since v3.0-2017 - */ -public abstract class AbstractHashMessage { - private int hashCode; - - public AbstractHashMessage(String key) { - this.hashCode = key.hashCode(); - } - - public int getHashCode() { - return hashCode; - } - - public void setKey(String key) { - this.hashCode = key.hashCode(); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Attribute.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Attribute.java deleted file mode 100644 index dd1324cceaff..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Attribute.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public class Attribute { - private final String name; - private final AttributeType type; - private final Operation operation; - - public Attribute(String name, AttributeType type, Operation operation) { - this.name = name; - this.type = type; - this.operation = operation; - } - - public String getName() { - return name; - } - - public AttributeType getType() { - return type; - } - - public Operation getOperation() { - return operation; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AttributeType.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AttributeType.java deleted file mode 100644 index 38ad9eb2ad1c..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/AttributeType.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public enum AttributeType { - STRING, LONG, DOUBLE, INTEGER, BYTE, BOOLEAN -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Column.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Column.java deleted file mode 100644 index d980106a8595..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Column.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public class Column { - private final String name; - private final Operation operation; - - public Column(String name, Operation operation) { - this.name = name; - this.operation = operation; - } - - public String getName() { - return name; - } - - public Operation getOperation() { - return operation; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/ColumnDefine.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/ColumnDefine.java deleted file mode 100644 index 067fe9a94259..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/ColumnDefine.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public abstract class ColumnDefine { - private final String name; - private final String type; - - public ColumnDefine(String name, String type) { - this.name = name; - this.type = type; - } - - public final String getName() { - return name; - } - - public String getType() { - return type; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/CommonTable.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/CommonTable.java deleted file mode 100644 index 475657d7e204..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/CommonTable.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public abstract class CommonTable { - public static final String TABLE_TYPE = "type"; - public static final String COLUMN_ID = "id"; - public static final String COLUMN_TIME_BUCKET = "time_bucket"; -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java deleted file mode 100644 index 6c97903659a0..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/EndOfBatchQueueMessage.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public abstract class EndOfBatchQueueMessage extends AbstractHashMessage { - - private boolean endOfBatch; - - public EndOfBatchQueueMessage(String key) { - super(key); - endOfBatch = false; - } - - public final boolean isEndOfBatch() { - return endOfBatch; - } - - public final void setEndOfBatch(boolean endOfBatch) { - this.endOfBatch = endOfBatch; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Operation.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Operation.java deleted file mode 100644 index dd78ee1f6723..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/Operation.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -/** - * @author peng-yongsheng - */ -public interface Operation { - String operate(String newValue, String oldValue); - - Long operate(Long newValue, Long oldValue); - - Double operate(Double newValue, Double oldValue); - - Integer operate(Integer newValue, Integer oldValue); - - Boolean operate(Boolean newValue, Boolean oldValue); - - byte[] operate(byte[] newValue, byte[] oldValue); -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefineLoader.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefineLoader.java deleted file mode 100644 index 53f5177e981a..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefineLoader.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.collector.core.define.DefineException; -import org.skywalking.apm.collector.core.define.DefinitionLoader; -import org.skywalking.apm.collector.core.define.Loader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class StorageDefineLoader implements Loader> { - - private final Logger logger = LoggerFactory.getLogger(StorageDefineLoader.class); - - @Override public List load() throws DefineException { - List tableDefines = new LinkedList<>(); - - StorageDefinitionFile definitionFile = new StorageDefinitionFile(); - logger.info("storage definition file name: {}", definitionFile.fileName()); - DefinitionLoader definitionLoader = DefinitionLoader.load(TableDefine.class, definitionFile); - for (TableDefine tableDefine : definitionLoader) { - logger.info("loaded storage definition class: {}", tableDefine.getClass().getName()); - tableDefines.add(tableDefine); - } - return tableDefines; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefinitionFile.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefinitionFile.java deleted file mode 100644 index 2ec180910a3b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/StorageDefinitionFile.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -import org.skywalking.apm.collector.core.define.DefinitionFile; - -/** - * @author peng-yongsheng - */ -public class StorageDefinitionFile extends DefinitionFile { - @Override protected String fileName() { - return "storage.define"; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/TableDefine.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/TableDefine.java deleted file mode 100644 index 2813e17139ea..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/TableDefine.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -import java.util.LinkedList; -import java.util.List; - -/** - * @author peng-yongsheng - */ -public abstract class TableDefine { - private final String name; - private final List columnDefines; - - public TableDefine(String name) { - this.name = name; - this.columnDefines = new LinkedList<>(); - } - - public abstract void initialize(); - - public final void addColumn(ColumnDefine columnDefine) { - columnDefines.add(columnDefine); - } - - public final String getName() { - return name; - } - - public final List getColumnDefines() { - return columnDefines; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/AddOperation.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/AddOperation.java deleted file mode 100644 index 1eb4b9c45146..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/AddOperation.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data.operator; - -import org.skywalking.apm.collector.core.data.Operation; - -/** - * @author peng-yongsheng - */ -public class AddOperation implements Operation { - - @Override public String operate(String newValue, String oldValue) { - throw new UnsupportedOperationException("not support string addition operation"); - } - - @Override public Long operate(Long newValue, Long oldValue) { - return newValue + oldValue; - } - - @Override public Double operate(Double newValue, Double oldValue) { - return newValue + oldValue; - } - - @Override public Integer operate(Integer newValue, Integer oldValue) { - return newValue + oldValue; - } - - @Override public Boolean operate(Boolean newValue, Boolean oldValue) { - throw new UnsupportedOperationException("not support boolean addition operation"); - } - - @Override public byte[] operate(byte[] newValue, byte[] oldValue) { - throw new UnsupportedOperationException("not support byte addition operation"); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/CoverOperation.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/CoverOperation.java deleted file mode 100644 index ae2b5388f88a..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/CoverOperation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data.operator; - -import org.skywalking.apm.collector.core.data.Operation; - -/** - * @author peng-yongsheng - */ -public class CoverOperation implements Operation { - @Override public String operate(String newValue, String oldValue) { - return newValue; - } - - @Override public Long operate(Long newValue, Long oldValue) { - return newValue; - } - - @Override public Double operate(Double newValue, Double oldValue) { - return newValue; - } - - @Override public Integer operate(Integer newValue, Integer oldValue) { - return newValue; - } - - @Override public Boolean operate(Boolean newValue, Boolean oldValue) { - return newValue; - } - - @Override public byte[] operate(byte[] newValue, byte[] oldValue) { - return newValue; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/NonOperation.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/NonOperation.java deleted file mode 100644 index 6d97c7a50ead..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/data/operator/NonOperation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data.operator; - -import org.skywalking.apm.collector.core.data.Operation; - -/** - * @author peng-yongsheng - */ -public class NonOperation implements Operation { - @Override public String operate(String newValue, String oldValue) { - return oldValue; - } - - @Override public Long operate(Long newValue, Long oldValue) { - return oldValue; - } - - @Override public Double operate(Double newValue, Double oldValue) { - return oldValue; - } - - @Override public Integer operate(Integer newValue, Integer oldValue) { - return oldValue; - } - - @Override public Boolean operate(Boolean newValue, Boolean oldValue) { - return oldValue; - } - - @Override public byte[] operate(byte[] newValue, byte[] oldValue) { - return oldValue; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefineException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefineException.java deleted file mode 100644 index 696dc3308eee..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefineException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.define; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public abstract class DefineException extends CollectorException { - - public DefineException(String message) { - super(message); - } - - public DefineException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionFile.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionFile.java deleted file mode 100644 index b3c6bd8226c5..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/DefinitionFile.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.define; - -/** - * @author peng-yongsheng - */ -public abstract class DefinitionFile { - - private static final String CATALOG = "META-INF/defines/"; - - protected abstract String fileName(); - - public final String get() { - return CATALOG + fileName(); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/Loader.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/Loader.java deleted file mode 100644 index 82ac08c566f0..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/define/Loader.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.define; - -/** - * @author peng-yongsheng - */ -public interface Loader { - T load() throws DefineException; -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/framework/Executor.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/framework/Executor.java deleted file mode 100644 index 3ec8c0bb923f..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/framework/Executor.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.framework; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public interface Executor { - void execute(INPUT input) throws CollectorException; -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/DirectWay.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/DirectWay.java deleted file mode 100644 index 3342b032d27b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/DirectWay.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class DirectWay extends WayToNode { - public DirectWay(NodeProcessor destinationHandler) { - super(destinationHandler); - } - - @Override protected void in(INPUT o) { - out(o); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Graph.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Graph.java deleted file mode 100644 index b3d353d8f406..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Graph.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * @author peng-yongsheng, wu-sheng - */ -public final class Graph { - private int id; - private WayToNode entryWay; - private ConcurrentHashMap nodeIndex = new ConcurrentHashMap<>(); - - Graph(int id) { - this.id = id; - } - - public void start(INPUT input) { - entryWay.in(input); - } - - public Node addNode(NodeProcessor nodeProcessor) { - return addNode(new DirectWay(nodeProcessor)); - } - - public Node addNode(WayToNode entryWay) { - synchronized (this) { - this.entryWay = entryWay; - this.entryWay.buildDestination(this); - return entryWay.getDestination(); - } - } - - void checkForNewNode(Node node) { - int nodeId = node.getHandler().id(); - if (nodeIndex.containsKey(nodeId)) { - throw new PotentialCyclicGraphException("handler=" - + node.getHandler().getClass().getName() - + " already exists in graph[" + id + "]"); - } - nodeIndex.put(nodeId, node); - } - - public GraphNodeFinder toFinder() { - return new GraphNodeFinder(this); - } - - ConcurrentHashMap getNodeIndex() { - return nodeIndex; - } - - int getId() { - return id; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphManager.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphManager.java deleted file mode 100644 index a3431054eb96..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphManager.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author wusheng - */ -public enum GraphManager { - INSTANCE; - - private Map allGraphs = new HashMap<>(); - - /** - * Create a stream process graph. - * - * @param graphId represents a graph, which is used for finding it. - * @return - */ - public synchronized Graph createIfAbsent(int graphId, Class input) { - if (!allGraphs.containsKey(graphId)) { - Graph graph = new Graph(graphId); - allGraphs.put(graphId, graph); - return graph; - } else { - return allGraphs.get(graphId); - } - } - - public Graph findGraph(int graphId) { - Graph graph = allGraphs.get(graphId); - if (graph == null) { - throw new GraphNotFoundException("Graph id=" + graphId + " not found in this GraphManager"); - } - return graph; - } - - public void reset() { - allGraphs.clear(); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNodeFinder.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNodeFinder.java deleted file mode 100644 index e133aa7f2203..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNodeFinder.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * @author wu-sheng - */ -public class GraphNodeFinder { - private Graph graph; - - GraphNodeFinder(Graph graph) { - this.graph = graph; - } - - public Next findNext(int handlerId) { - ConcurrentHashMap graphNodeIndex = graph.getNodeIndex(); - Node node = graphNodeIndex.get(handlerId); - if (node == null) { - throw new NodeNotFoundException("Can't find node with handlerId=" - + handlerId - + " in graph[" + graph.getId() + "]"); - } - return node.getNext(); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNotFoundException.java deleted file mode 100644 index 6667bf69eaa0..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/GraphNotFoundException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class GraphNotFoundException extends RuntimeException { - public GraphNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Next.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Next.java deleted file mode 100644 index 30f9a7021061..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Next.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.collector.core.framework.Executor; - -/** - * The Next is a delegate object for the following {@link Node}. - * - * @author peng-yongsheng, wu-sheng - */ -public class Next implements Executor { - - private final List ways; - - public Next() { - this.ways = new LinkedList<>(); - } - - final void addWay(WayToNode way) { - ways.add(way); - } - - /** - * Drive to the next nodes - * - * @param input - */ - @Override public void execute(INPUT input) { - ways.forEach(way -> way.in(input)); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Node.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Node.java deleted file mode 100644 index b48ab5bd2d6d..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/Node.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * The Node in the graph with explicit INPUT and OUTPUT types. - * - * @author peng-yongsheng, wu-sheng - */ -public final class Node { - private final NodeProcessor nodeProcessor; - private final Next next; - private final Graph graph; - - Node(Graph graph, NodeProcessor nodeProcessor) { - this.graph = graph; - this.nodeProcessor = nodeProcessor; - this.next = new Next<>(); - this.graph.checkForNewNode(this); - } - - public final Node addNext(NodeProcessor nodeProcessor) { - return this.addNext(new DirectWay(nodeProcessor)); - } - - public final Node addNext(WayToNode way) { - synchronized (graph) { - way.buildDestination(graph); - next.addWay(way); - return way.getDestination(); - } - } - - final void execute(INPUT input) { - nodeProcessor.process(input, next); - } - - NodeProcessor getHandler() { - return nodeProcessor; - } - - Next getNext() { - return next; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeNotFoundException.java deleted file mode 100644 index 81b4a7e8fed2..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeNotFoundException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class NodeNotFoundException extends RuntimeException { - public NodeNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeProcessor.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeProcessor.java deleted file mode 100644 index 091335674447..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/NodeProcessor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author peng-yongsheng, wu-sheng - */ -public interface NodeProcessor { - /** - * The unique id in the certain graph. - * - * @return id - */ - int id(); - - void process(input input, Next next); -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java deleted file mode 100644 index 6ef250ebd1d6..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/PotentialCyclicGraphException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class PotentialCyclicGraphException extends RuntimeException { - public PotentialCyclicGraphException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/WayToNode.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/WayToNode.java deleted file mode 100644 index eaed1a85012b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/graph/WayToNode.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public abstract class WayToNode { - private Node destination; - private NodeProcessor destinationHandler; - - public WayToNode(NodeProcessor destinationHandler) { - this.destinationHandler = destinationHandler; - } - - void buildDestination(Graph graph) { - destination = new Node(graph, destinationHandler); - } - - protected abstract void in(INPUT input); - - protected void out(INPUT input) { - destination.execute(input); - } - - Node getDestination() { - return destination; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CycleDependencyException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CycleDependencyException.java deleted file mode 100644 index 6be3c269e59b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CycleDependencyException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class CycleDependencyException extends RuntimeException { - public CycleDependencyException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/DuplicateProviderException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/DuplicateProviderException.java deleted file mode 100644 index fdcb094ef24e..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/DuplicateProviderException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -public class DuplicateProviderException extends Exception { - public DuplicateProviderException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundException.java deleted file mode 100644 index 310298c3b21b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -public class ModuleNotFoundException extends Exception { - - public ModuleNotFoundException(Throwable cause) { - super(cause); - } - - public ModuleNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java deleted file mode 100644 index 57de78e94c65..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleNotFoundRuntimeException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author peng-yongsheng - */ -public class ModuleNotFoundRuntimeException extends RuntimeException { - - public ModuleNotFoundRuntimeException(Throwable cause) { - super(cause); - } - - public ModuleNotFoundRuntimeException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ProviderNotFoundException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ProviderNotFoundException.java deleted file mode 100644 index e56cab43952d..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ProviderNotFoundException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -public class ProviderNotFoundException extends Exception { - public ProviderNotFoundException(String message) { - super(message); - } - - public ProviderNotFoundException(Throwable e) { - super(e); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Service.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Service.java deleted file mode 100644 index 6d531d76b6e6..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/Service.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * The Service implementation is a service provided by its own modules. - * - * And every {@link ModuleProvider} must provide all the given services of the {@link Module}. - * - * @author wu-sheng - */ -public interface Service { -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedException.java deleted file mode 100644 index bb0006d4d1bf..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -public class ServiceNotProvidedException extends Exception { - public ServiceNotProvidedException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java deleted file mode 100644 index b6480988455d..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ServiceNotProvidedRuntimeException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -public class ServiceNotProvidedRuntimeException extends RuntimeException { - public ServiceNotProvidedRuntimeException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ApdexThresholdUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ApdexThresholdUtils.java deleted file mode 100644 index b170e2f265e5..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ApdexThresholdUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -/** - * @author peng-yongsheng - */ -public class ApdexThresholdUtils { - - public static Apdex compute(int threshold, long duration) { - if (duration <= threshold) { - return Apdex.Satisfied; - } else if (duration <= threshold * 4) { - return Apdex.Tolerating; - } else { - return Apdex.Frustrated; - } - } - - public enum Apdex { - Satisfied, Tolerating, Frustrated - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/BytesUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/BytesUtils.java deleted file mode 100644 index deee952bd17b..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/BytesUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -/** - * @author peng-yongsheng - */ -public class BytesUtils { - - public static byte[] long2Bytes(long num) { - byte[] byteNum = new byte[8]; - for (int ix = 0; ix < 8; ++ix) { - int offset = 64 - (ix + 1) * 8; - byteNum[ix] = (byte)((num >> offset) & 0xff); - } - return byteNum; - } - - public static long bytes2Long(byte[] byteNum) { - long num = 0; - for (int ix = 0; ix < 8; ++ix) { - num <<= 8; - num |= byteNum[ix] & 0xff; - } - return num; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/CollectionUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/CollectionUtils.java deleted file mode 100644 index 414642d78d36..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/CollectionUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author peng-yongsheng - */ -public class CollectionUtils { - - public static boolean isEmpty(Map map) { - return map == null || map.size() == 0; - } - - public static boolean isEmpty(List list) { - return list == null || list.size() == 0; - } - - public static boolean isEmpty(Set set) { - return set == null || set.size() == 0; - } - - public static boolean isNotEmpty(List list) { - return !isEmpty(list); - } - - public static boolean isNotEmpty(Set set) { - return !isEmpty(set); - } - - public static boolean isNotEmpty(Map map) { - return !isEmpty(map); - } - - public static boolean isNotEmpty(T[] array) { - return array != null && array.length > 0; - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ColumnNameUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ColumnNameUtils.java deleted file mode 100644 index 93517371d2b2..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ColumnNameUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -/** - * @author peng-yongsheng - */ -public enum ColumnNameUtils { - INSTANCE; - - public String rename(String columnName) { - StringBuilder renamedColumnName = new StringBuilder(); - char[] chars = columnName.toLowerCase().toCharArray(); - - boolean findUnderline = false; - for (char character : chars) { - if (character == '_') { - findUnderline = true; - } else if (findUnderline) { - renamedColumnName.append(String.valueOf(character).toUpperCase()); - findUnderline = false; - } else { - renamedColumnName.append(character); - } - } - return renamedColumnName.toString(); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java deleted file mode 100644 index 69bfd8b50e1f..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -/** - * @author peng-yongsheng - */ -public class Const { - public static final String ID_SPLIT = "_"; - public static final int USER_ID = 1; - public static final int NONE_SERVICE_ID = 1; - public static final int NONE_INSTANCE_ID = 1; - public static final String NONE_SERVICE_NAME = "None"; - public static final String USER_CODE = "User"; - public static final String SEGMENT_SPAN_SPLIT = "S"; - public static final String UNKNOWN = "Unknown"; - public static final String EXCEPTION = "Exception"; - public static final String EMPTY_STRING = ""; - public static final String FILE_SUFFIX = "sw"; -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ObjectUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ObjectUtils.java deleted file mode 100644 index 5726c07ee660..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ObjectUtils.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -/** - * @author peng-yongsheng - */ -public class ObjectUtils { - public static boolean isEmpty(Object obj) { - return obj == null; - } - - public static boolean isNotEmpty(Object obj) { - return !isEmpty(obj); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java deleted file mode 100644 index 9af6030ee3e4..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/ResourceUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; - -/** - * @author peng-yongsheng - */ -public class ResourceUtils { - - public static Reader read(String fileName) throws FileNotFoundException { - URL url = ResourceUtils.class.getClassLoader().getResource(fileName); - if (url == null) { - throw new FileNotFoundException("file not found: " + fileName); - } - InputStream inputStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName); - return new InputStreamReader(inputStream); - } -} diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/StringUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/StringUtils.java deleted file mode 100644 index a5961f5d76e3..000000000000 --- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/StringUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -/** - * @author peng-yongsheng - */ -public class StringUtils { - - public static final String EMPTY_STRING = ""; - - public static boolean isEmpty(Object str) { - return str == null || EMPTY_STRING.equals(str); - } - - public static boolean isNotEmpty(Object str) { - return !isEmpty(str); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessageTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessageTest.java new file mode 100644 index 000000000000..34089f839ffd --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/data/AbstractHashMessageTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.data; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class AbstractHashMessageTest { + public class NewMessage extends AbstractHashMessage { + public NewMessage() { + super("key"); + } + } + + @Test + public void testHash() { + NewMessage message = new NewMessage(); + Assert.assertEquals("key".hashCode(), message.getHashCode()); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/DefinitionLoaderTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/DefinitionLoaderTest.java similarity index 96% rename from apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/DefinitionLoaderTest.java rename to apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/DefinitionLoaderTest.java index 4df2a991dd7a..f666ac31e553 100644 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/DefinitionLoaderTest.java +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/DefinitionLoaderTest.java @@ -16,7 +16,7 @@ * */ -package org.skywalking.apm.collector.core.define; +package org.apache.skywalking.apm.collector.core.define; import java.util.Iterator; import org.junit.Assert; diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceImpl.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceImpl.java new file mode 100644 index 000000000000..c159fff616a8 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceImpl.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; + +/** + * @author wu-sheng + */ +public class ServiceImpl implements ServiceInterface { +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceInterface.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceInterface.java new file mode 100644 index 000000000000..192092626b2d --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/ServiceInterface.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; + +/** + * @author wu-sheng + */ +public interface ServiceInterface { +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/TestDefineFile.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/TestDefineFile.java new file mode 100644 index 000000000000..d02db099ab4d --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/define/TestDefineFile.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.define; + +/** + * @author wu-sheng + */ +public class TestDefineFile extends DefinitionFile { + @Override protected String fileName() { + return "test_define.define"; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/GraphManagerTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/GraphManagerTest.java similarity index 85% rename from apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/GraphManagerTest.java rename to apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/GraphManagerTest.java index 98872b496c5a..32883271c090 100644 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/GraphManagerTest.java +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/GraphManagerTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.core.graph; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; import java.io.ByteArrayOutputStream; import java.io.PrintStream; diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node1Processor.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node1Processor.java new file mode 100644 index 000000000000..e813c0d74d56 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node1Processor.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class Node1Processor extends OutputProcessor implements NodeProcessor { + @Override public int id() { + return 1; + } + + @Override public void process(String s, Next next) { + outstream().println("Node1 process: s=" + s); + next.execute(s); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node2Processor.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node2Processor.java new file mode 100644 index 000000000000..afc00beec534 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node2Processor.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class Node2Processor extends OutputProcessor implements NodeProcessor { + @Override public int id() { + return 2; + } + + @Override public void process(String s, Next next) { + outstream().println("Node2 process: s=" + s); + next.execute(123); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node3Processor.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node3Processor.java new file mode 100644 index 000000000000..c693a4af8ef5 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node3Processor.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class Node3Processor extends OutputProcessor implements NodeProcessor { + @Override public int id() { + return 3; + } + + @Override + public void process(Long aLong, Next next) { + outstream().println("Node3 process: long=" + aLong); + next.execute(aLong); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node4Processor.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node4Processor.java new file mode 100644 index 000000000000..0fde2e29b94a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/Node4Processor.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +/** + * @author wusheng + */ +public class Node4Processor extends OutputProcessor implements NodeProcessor { + @Override public int id() { + return 4; + } + + @Override + public void process(Integer in, Next next) { + outstream().println("Node4 process: int=" + in); + next.execute(new Long(in.intValue())); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/OutputProcessor.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/OutputProcessor.java new file mode 100644 index 000000000000..6d083280ffe5 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/graph/OutputProcessor.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.graph; + +import java.io.PrintStream; + +/** + * @author wu-sheng + */ +public class OutputProcessor { + protected PrintStream outstream() { + return System.out; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java new file mode 100644 index 000000000000..126b87fa701c --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +import java.util.Properties; +import org.junit.Assert; +import org.junit.Test; + +public class ApplicationConfigurationTest { + @Test + public void testBuildConfig() { + ApplicationConfiguration configuration = new ApplicationConfiguration(); + Properties p1 = new Properties(); + p1.setProperty("p1", "value1"); + p1.setProperty("p2", "value2"); + Properties p2 = new Properties(); + p2.setProperty("prop1", "value1-prop"); + p2.setProperty("prop2", "value2-prop"); + configuration.addModule("MO-1").addProviderConfiguration("MO-1-P1", p1).addProviderConfiguration("MO-1-P2", p2); + + Assert.assertArrayEquals(new String[] {"MO-1"}, configuration.moduleList()); + Assert.assertEquals("value2-prop", configuration.getModuleConfiguration("MO-1").getProviderConfiguration("MO-1-P2").getProperty("prop2")); + Assert.assertEquals(p1, configuration.getModuleConfiguration("MO-1").getProviderConfiguration("MO-1-P1")); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleA.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleA.java new file mode 100644 index 000000000000..24469d76ff84 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleA.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class BaseModuleA extends Module { + @Override public String name() { + return "BaseA"; + } + + @Override public Class[] services() { + return new Class[] {ServiceABusiness1.class, ServiceABusiness2.class}; + } + + public interface ServiceABusiness1 extends Service { + void print(); + } + + public interface ServiceABusiness2 extends Service { + + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleB.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleB.java new file mode 100644 index 000000000000..7b63e624628a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/BaseModuleB.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class BaseModuleB extends Module { + @Override public String name() { + return "BaseB"; + } + + @Override public Class[] services() { + return new Class[] {BaseModuleB.ServiceBBusiness1.class, BaseModuleB.ServiceBBusiness2.class}; + } + + public interface ServiceBBusiness1 extends Service { + + } + + public interface ServiceBBusiness2 extends Service { + + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java new file mode 100644 index 000000000000..ffb414290f49 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class ModuleABusiness1Impl implements BaseModuleA.ServiceABusiness1 { + + @Override public void print() { + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java new file mode 100644 index 000000000000..ad1d2f876a1a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class ModuleABusiness2Impl implements BaseModuleA.ServiceABusiness2 { + +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleAProvider.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleAProvider.java new file mode 100644 index 000000000000..beea177bcedb --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleAProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +import java.util.Properties; + +/** + * @author wu-sheng + */ +public class ModuleAProvider extends ModuleProvider { + @Override public String name() { + return "P-A"; + } + + @Override public Class module() { + return BaseModuleA.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(BaseModuleA.ServiceABusiness1.class, new ModuleABusiness1Impl()); + this.registerServiceImplementation(BaseModuleA.ServiceABusiness2.class, new ModuleABusiness2Impl()); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java new file mode 100644 index 000000000000..d11885ab33fc --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class ModuleBBusiness1Impl implements BaseModuleB.ServiceBBusiness1 { +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java new file mode 100644 index 000000000000..bc3a3099d71a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class ModuleBBusiness2Impl implements BaseModuleB.ServiceBBusiness2 { +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBProvider.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBProvider.java new file mode 100644 index 000000000000..c5d1af5a08ac --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleBProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +import java.util.Properties; + +/** + * @author wu-sheng + */ +public class ModuleBProvider extends ModuleProvider { + @Override public String name() { + return "P-B"; + } + + @Override public Class module() { + return BaseModuleB.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(BaseModuleB.ServiceBBusiness1.class, new ModuleBBusiness1Impl()); + this.registerServiceImplementation(BaseModuleB.ServiceBBusiness2.class, new ModuleBBusiness2Impl()); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleManagerTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleManagerTest.java new file mode 100644 index 000000000000..856e8e8c4a28 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/ModuleManagerTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ModuleManagerTest { + @Test + public void testInit() throws ServiceNotProvidedException, ModuleNotFoundException, ProviderNotFoundException, DuplicateProviderException { + ApplicationConfiguration configuration = new ApplicationConfiguration(); + configuration.addModule("Test").addProviderConfiguration("TestModule-Provider", null); + configuration.addModule("BaseA").addProviderConfiguration("P-A", null); + configuration.addModule("BaseB").addProviderConfiguration("P-B", null); + + ModuleManager manager = new ModuleManager(); + manager.init(configuration); + + BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find("BaseA").provider().getService(BaseModuleA.ServiceABusiness1.class); + Assert.assertTrue(serviceABusiness1 != null); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModule.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModule.java new file mode 100644 index 000000000000..3fe491b01f97 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModule.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +/** + * @author wu-sheng + */ +public class TestModule extends Module { + @Override public String name() { + return "Test"; + } + + @Override public Class[] services() { + return new Class[0]; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModuleProvider.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModuleProvider.java new file mode 100644 index 000000000000..73da6b311a9d --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/module/TestModuleProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.module; + +import java.util.Properties; + +/** + * @author wu-sheng + */ +public class TestModuleProvider extends ModuleProvider { + @Override public String name() { + return "TestModule-Provider"; + } + + @Override public Class module() { + return TestModule.class; + } + + @Override public void prepare(Properties config) { + + } + + @Override public void start(Properties config) { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {"BaseA", "BaseB"}; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/BytesUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/BytesUtilsTest.java new file mode 100644 index 000000000000..d3bd8a425cb4 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/BytesUtilsTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class BytesUtilsTest { + @Test + public void testLong2Bytes() { + Assert.assertEquals(655390L, BytesUtils.bytes2Long(BytesUtils.long2Bytes(655390L))); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/CollectionUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/CollectionUtilsTest.java new file mode 100644 index 000000000000..b7a3f6b8d17a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/CollectionUtilsTest.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class CollectionUtilsTest { + @Test + public void testList() { + List list = new LinkedList<>(); + Assert.assertTrue(CollectionUtils.isEmpty(list)); + Assert.assertFalse(CollectionUtils.isNotEmpty(list)); + } + + @Test + public void testMap() { + Map map = new HashMap<>(); + Assert.assertTrue(CollectionUtils.isEmpty(map)); + Assert.assertFalse(CollectionUtils.isNotEmpty(map)); + } + + @Test + public void testArray() { + String[] array = new String[] {"abc"}; + Assert.assertTrue(CollectionUtils.isNotEmpty(array)); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java new file mode 100644 index 000000000000..05304ae7f90f --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ColumnNameUtilsTest { + @Test + public void testRename() { + Assert.assertEquals("newAttributeNameFromColumnName", + ColumnNameUtils.INSTANCE.rename("new_attribute_name_from_column_name")); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ObjectUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ObjectUtilsTest.java new file mode 100644 index 000000000000..764ee5ff1745 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ObjectUtilsTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ObjectUtilsTest { + @Test + public void testNullObject() { + Object o = new Object(); + Assert.assertTrue(ObjectUtils.isNotEmpty(o)); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ResourceUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ResourceUtilsTest.java new file mode 100644 index 000000000000..005f14ddfde4 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/ResourceUtilsTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ResourceUtilsTest { + @Test + public void testGetResource() throws IOException { + Reader read = ResourceUtils.read("TestResourceFile.txt"); + try { + BufferedReader reader = new BufferedReader(read); + String line1 = reader.readLine(); + Assert.assertEquals("skywalking", line1); + } finally { + read.close(); + } + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/StringUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/StringUtilsTest.java new file mode 100644 index 000000000000..f47fcd5fdb5b --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/StringUtilsTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class StringUtilsTest { + @Test + public void testEmptyString() { + Assert.assertTrue(StringUtils.isEmpty(null)); + Assert.assertTrue(StringUtils.isEmpty("")); + + Assert.assertTrue(StringUtils.isNotEmpty("abc")); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java new file mode 100644 index 000000000000..56479f2d2108 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.core.util; + +import java.util.TimeZone; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class TimeBucketUtilsTest { + @Before + public void setup() { + TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); + } + + @After + public void teardown() { + + } + + @Test + public void testGetInfoFromATimestamp() { + long timeMillis = 1509521745220L; + Assert.assertArrayEquals(new long[] { + 20171101153545L, + 20171101153544L, + 20171101153543L, + 20171101153542L, + 20171101153541L + }, TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis))); + Assert.assertEquals(20171101153545L, TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis)); + Assert.assertEquals(201711011535L, TimeBucketUtils.INSTANCE.getMinuteTimeBucket(timeMillis)); + Assert.assertEquals(201711011500L, TimeBucketUtils.INSTANCE.getHourTimeBucket(timeMillis)); + Assert.assertEquals(201711010000L, TimeBucketUtils.INSTANCE.getDayTimeBucket(timeMillis)); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java deleted file mode 100644 index 73b08c54b28a..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.data; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class AbstractHashMessageTest { - public class NewMessage extends AbstractHashMessage { - public NewMessage() { - super("key"); - } - } - - @Test - public void testHash() { - NewMessage message = new NewMessage(); - Assert.assertEquals("key".hashCode(), message.getHashCode()); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java deleted file mode 100644 index 0f7127b706a8..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.define; - -/** - * @author wu-sheng - */ -public class ServiceImpl implements ServiceInterface { -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java deleted file mode 100644 index eddcd3a719d6..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.define; - -/** - * @author wu-sheng - */ -public interface ServiceInterface { -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java deleted file mode 100644 index 33409931fa83..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.define; - -/** - * @author wu-sheng - */ -public class TestDefineFile extends DefinitionFile { - @Override protected String fileName() { - return "test_define.define"; - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node1Processor.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node1Processor.java deleted file mode 100644 index f35b1997349a..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node1Processor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class Node1Processor extends OutputProcessor implements NodeProcessor { - @Override public int id() { - return 1; - } - - @Override public void process(String s, Next next) { - outstream().println("Node1 process: s=" + s); - next.execute(s); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node2Processor.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node2Processor.java deleted file mode 100644 index f9173ad23ed5..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node2Processor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class Node2Processor extends OutputProcessor implements NodeProcessor { - @Override public int id() { - return 2; - } - - @Override public void process(String s, Next next) { - outstream().println("Node2 process: s=" + s); - next.execute(123); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node3Processor.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node3Processor.java deleted file mode 100644 index 6d49e65c1918..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node3Processor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class Node3Processor extends OutputProcessor implements NodeProcessor { - @Override public int id() { - return 3; - } - - @Override - public void process(Long aLong, Next next) { - outstream().println("Node3 process: long=" + aLong); - next.execute(aLong); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node4Processor.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node4Processor.java deleted file mode 100644 index e85a8d26678c..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/Node4Processor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -/** - * @author wusheng - */ -public class Node4Processor extends OutputProcessor implements NodeProcessor { - @Override public int id() { - return 4; - } - - @Override - public void process(Integer in, Next next) { - outstream().println("Node4 process: int=" + in); - next.execute(new Long(in.intValue())); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/OutputProcessor.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/OutputProcessor.java deleted file mode 100644 index bf43bc4fc1e3..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/graph/OutputProcessor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.graph; - -import java.io.PrintStream; - -/** - * @author wu-sheng - */ -public class OutputProcessor { - protected PrintStream outstream() { - return System.out; - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java deleted file mode 100644 index 9a8b24a2e93e..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ApplicationConfigurationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -import java.util.Properties; -import org.junit.Assert; -import org.junit.Test; - -public class ApplicationConfigurationTest { - @Test - public void testBuildConfig() { - ApplicationConfiguration configuration = new ApplicationConfiguration(); - Properties p1 = new Properties(); - p1.setProperty("p1", "value1"); - p1.setProperty("p2", "value2"); - Properties p2 = new Properties(); - p2.setProperty("prop1", "value1-prop"); - p2.setProperty("prop2", "value2-prop"); - configuration.addModule("MO-1").addProviderConfiguration("MO-1-P1", p1).addProviderConfiguration("MO-1-P2", p2); - - Assert.assertArrayEquals(new String[] {"MO-1"}, configuration.moduleList()); - Assert.assertEquals("value2-prop", configuration.getModuleConfiguration("MO-1").getProviderConfiguration("MO-1-P2").getProperty("prop2")); - Assert.assertEquals(p1, configuration.getModuleConfiguration("MO-1").getProviderConfiguration("MO-1-P1")); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleA.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleA.java deleted file mode 100644 index 7b67526436e5..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleA.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class BaseModuleA extends Module { - @Override public String name() { - return "BaseA"; - } - - @Override public Class[] services() { - return new Class[] {ServiceABusiness1.class, ServiceABusiness2.class}; - } - - public interface ServiceABusiness1 extends Service { - void print(); - } - - public interface ServiceABusiness2 extends Service { - - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleB.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleB.java deleted file mode 100644 index 7d9436ca384c..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/BaseModuleB.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class BaseModuleB extends Module { - @Override public String name() { - return "BaseB"; - } - - @Override public Class[] services() { - return new Class[] {BaseModuleB.ServiceBBusiness1.class, BaseModuleB.ServiceBBusiness2.class}; - } - - public interface ServiceBBusiness1 extends Service { - - } - - public interface ServiceBBusiness2 extends Service { - - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java deleted file mode 100644 index 8cbc554fc7ce..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness1Impl.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class ModuleABusiness1Impl implements BaseModuleA.ServiceABusiness1 { - - @Override public void print() { - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java deleted file mode 100644 index 64efc3db4676..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleABusiness2Impl.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class ModuleABusiness2Impl implements BaseModuleA.ServiceABusiness2 { - -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleAProvider.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleAProvider.java deleted file mode 100644 index bd5c7cf8a5c5..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleAProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -import java.util.Properties; - -/** - * @author wu-sheng - */ -public class ModuleAProvider extends ModuleProvider { - @Override public String name() { - return "P-A"; - } - - @Override public Class module() { - return BaseModuleA.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(BaseModuleA.ServiceABusiness1.class, new ModuleABusiness1Impl()); - this.registerServiceImplementation(BaseModuleA.ServiceABusiness2.class, new ModuleABusiness2Impl()); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java deleted file mode 100644 index c911ded3486e..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness1Impl.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class ModuleBBusiness1Impl implements BaseModuleB.ServiceBBusiness1 { -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java deleted file mode 100644 index a919fb302cd6..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBBusiness2Impl.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class ModuleBBusiness2Impl implements BaseModuleB.ServiceBBusiness2 { -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBProvider.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBProvider.java deleted file mode 100644 index bff2504e7d8e..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleBProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -import java.util.Properties; - -/** - * @author wu-sheng - */ -public class ModuleBProvider extends ModuleProvider { - @Override public String name() { - return "P-B"; - } - - @Override public Class module() { - return BaseModuleB.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(BaseModuleB.ServiceBBusiness1.class, new ModuleBBusiness1Impl()); - this.registerServiceImplementation(BaseModuleB.ServiceBBusiness2.class, new ModuleBBusiness2Impl()); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleManagerTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleManagerTest.java deleted file mode 100644 index 17b62949b9cf..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/ModuleManagerTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class ModuleManagerTest { - @Test - public void testInit() throws ServiceNotProvidedException, ModuleNotFoundException, ProviderNotFoundException, DuplicateProviderException { - ApplicationConfiguration configuration = new ApplicationConfiguration(); - configuration.addModule("Test").addProviderConfiguration("TestModule-Provider", null); - configuration.addModule("BaseA").addProviderConfiguration("P-A", null); - configuration.addModule("BaseB").addProviderConfiguration("P-B", null); - - ModuleManager manager = new ModuleManager(); - manager.init(configuration); - - BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find("BaseA").provider().getService(BaseModuleA.ServiceABusiness1.class); - Assert.assertTrue(serviceABusiness1 != null); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModule.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModule.java deleted file mode 100644 index 1b00e06e8064..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModule.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -/** - * @author wu-sheng - */ -public class TestModule extends Module { - @Override public String name() { - return "Test"; - } - - @Override public Class[] services() { - return new Class[0]; - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModuleProvider.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModuleProvider.java deleted file mode 100644 index 2ecf30d9b779..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/module/TestModuleProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.module; - -import java.util.Properties; - -/** - * @author wu-sheng - */ -public class TestModuleProvider extends ModuleProvider { - @Override public String name() { - return "TestModule-Provider"; - } - - @Override public Class module() { - return TestModule.class; - } - - @Override public void prepare(Properties config) { - - } - - @Override public void start(Properties config) { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {"BaseA", "BaseB"}; - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java deleted file mode 100644 index 2e703af2eb27..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class BytesUtilsTest { - @Test - public void testLong2Bytes() { - Assert.assertEquals(655390L, BytesUtils.bytes2Long(BytesUtils.long2Bytes(655390L))); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java deleted file mode 100644 index 5481919279c2..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class CollectionUtilsTest { - @Test - public void testList() { - List list = new LinkedList<>(); - Assert.assertTrue(CollectionUtils.isEmpty(list)); - Assert.assertFalse(CollectionUtils.isNotEmpty(list)); - } - - @Test - public void testMap() { - Map map = new HashMap<>(); - Assert.assertTrue(CollectionUtils.isEmpty(map)); - Assert.assertFalse(CollectionUtils.isNotEmpty(map)); - } - - @Test - public void testArray() { - String[] array = new String[] {"abc"}; - Assert.assertTrue(CollectionUtils.isNotEmpty(array)); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java deleted file mode 100644 index 4310f6e74102..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class ColumnNameUtilsTest { - @Test - public void testRename() { - Assert.assertEquals("newAttributeNameFromColumnName", - ColumnNameUtils.INSTANCE.rename("new_attribute_name_from_column_name")); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java deleted file mode 100644 index 710e74d11a45..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class ObjectUtilsTest { - @Test - public void testNullObject() { - Object o = new Object(); - Assert.assertTrue(ObjectUtils.isNotEmpty(o)); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java deleted file mode 100644 index f017a91d181a..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class ResourceUtilsTest { - @Test - public void testGetResource() throws IOException { - Reader read = ResourceUtils.read("TestResourceFile.txt"); - try { - BufferedReader reader = new BufferedReader(read); - String line1 = reader.readLine(); - Assert.assertEquals("skywalking", line1); - } finally { - read.close(); - } - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java deleted file mode 100644 index 35e9411aede1..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class StringUtilsTest { - @Test - public void testEmptyString() { - Assert.assertTrue(StringUtils.isEmpty(null)); - Assert.assertTrue(StringUtils.isEmpty("")); - - Assert.assertTrue(StringUtils.isNotEmpty("abc")); - } -} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java deleted file mode 100644 index a6e34d146832..000000000000 --- a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.core.util; - -import java.util.TimeZone; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * @author wu-sheng - */ -public class TimeBucketUtilsTest { - @Before - public void setup() { - TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); - } - - @After - public void teardown() { - - } - - @Test - public void testGetInfoFromATimestamp() { - long timeMillis = 1509521745220L; - Assert.assertArrayEquals(new long[] { - 20171101153545L, - 20171101153544L, - 20171101153543L, - 20171101153542L, - 20171101153541L - }, TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis))); - Assert.assertEquals(20171101153545L, TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis)); - Assert.assertEquals(201711011535L, TimeBucketUtils.INSTANCE.getMinuteTimeBucket(timeMillis)); - Assert.assertEquals(201711011500L, TimeBucketUtils.INSTANCE.getHourTimeBucket(timeMillis)); - Assert.assertEquals(201711010000L, TimeBucketUtils.INSTANCE.getDayTimeBucket(timeMillis)); - } -} diff --git a/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define b/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define index d44e660dd3b6..f43c533bd464 100644 --- a/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define +++ b/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define @@ -1 +1 @@ -org.skywalking.apm.collector.core.define.ServiceImpl \ No newline at end of file +org.apache.skywalking.apm.collector.core.define.ServiceImpl diff --git a/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..a3740c792a74 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.core.module.TestModule +org.apache.skywalking.apm.collector.core.module.BaseModuleA +org.apache.skywalking.apm.collector.core.module.BaseModuleB diff --git a/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..cc940cebb038 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.core.module.TestModuleProvider +org.apache.skywalking.apm.collector.core.module.ModuleAProvider +org.apache.skywalking.apm.collector.core.module.ModuleBProvider diff --git a/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 0cc4eb6eaa5d..000000000000 --- a/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,39 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.core.module.TestModule -org.skywalking.apm.collector.core.module.BaseModuleA -org.skywalking.apm.collector.core.module.BaseModuleB diff --git a/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 361cc0c05a65..000000000000 --- a/apm-collector/apm-collector-core/src/test/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,39 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.core.module.TestModuleProvider -org.skywalking.apm.collector.core.module.ModuleAProvider -org.skywalking.apm.collector.core.module.ModuleBProvider diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java new file mode 100644 index 000000000000..22385610f039 --- /dev/null +++ b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.grpc.manager; + +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; + +/** + * @author peng-yongsheng + */ +public class GRPCManagerModule extends Module { + + public static final String NAME = "gRPC_manager"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {GRPCManagerService.class}; + } +} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java new file mode 100644 index 000000000000..a5d72f953fbe --- /dev/null +++ b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.grpc.manager.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.server.Server; + +/** + * @author peng-yongsheng + */ +public interface GRPCManagerService extends Service { + Server createIfAbsent(String host, int port); +} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java deleted file mode 100644 index 2fe8a349b70d..000000000000 --- a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.grpc.manager; - -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; - -/** - * @author peng-yongsheng - */ -public class GRPCManagerModule extends Module { - - public static final String NAME = "gRPC_manager"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {GRPCManagerService.class}; - } -} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java deleted file mode 100644 index 24bef633a467..000000000000 --- a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.grpc.manager.service; - -import org.skywalking.apm.collector.core.module.Service; -import org.skywalking.apm.collector.server.Server; - -/** - * @author peng-yongsheng - */ -public interface GRPCManagerService extends Service { - Server createIfAbsent(String host, int port); -} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..f874d0c0e677 --- /dev/null +++ b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.grpc.manager.GRPCManagerModule diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 4ad8dd768720..000000000000 --- a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.grpc.manager.GRPCManagerModule diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java new file mode 100644 index 000000000000..ad4566fb4388 --- /dev/null +++ b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.grpc.manager; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.server.grpc.GRPCServer; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; +import org.apache.skywalking.apm.collector.grpc.manager.service.GRPCManagerServiceImpl; +import org.apache.skywalking.apm.collector.server.ServerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GRPCManagerProvider extends ModuleProvider { + + private final Logger logger = LoggerFactory.getLogger(GRPCManagerProvider.class); + + private Map servers = new HashMap<>(); + + @Override public String name() { + return "gRPC"; + } + + @Override public Class module() { + return GRPCManagerModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(GRPCManagerService.class, new GRPCManagerServiceImpl(servers)); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + servers.values().forEach(server -> { + try { + server.start(); + } catch (ServerException e) { + logger.error(e.getMessage(), e); + } + }); + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java new file mode 100644 index 000000000000..6bcce5abac12 --- /dev/null +++ b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/apache/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.grpc.manager.service; + +import java.util.Map; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.server.ServerException; +import org.apache.skywalking.apm.collector.server.grpc.GRPCServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GRPCManagerServiceImpl implements GRPCManagerService { + + private final Logger logger = LoggerFactory.getLogger(GRPCManagerServiceImpl.class); + + private final Map servers; + + public GRPCManagerServiceImpl(Map servers) { + this.servers = servers; + } + + @Override public Server createIfAbsent(String host, int port) { + String id = host + String.valueOf(port); + if (servers.containsKey(id)) { + return servers.get(id); + } else { + GRPCServer server = new GRPCServer(host, port); + try { + server.initialize(); + } catch (ServerException e) { + logger.error(e.getMessage(), e); + } + servers.put(id, server); + return server; + } + } +} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java deleted file mode 100644 index 852b0ed39395..000000000000 --- a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/GRPCManagerProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.grpc.manager; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; -import org.skywalking.apm.collector.grpc.manager.service.GRPCManagerServiceImpl; -import org.skywalking.apm.collector.server.ServerException; -import org.skywalking.apm.collector.server.grpc.GRPCServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GRPCManagerProvider extends ModuleProvider { - - private final Logger logger = LoggerFactory.getLogger(GRPCManagerProvider.class); - - private Map servers = new HashMap<>(); - - @Override public String name() { - return "gRPC"; - } - - @Override public Class module() { - return GRPCManagerModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(GRPCManagerService.class, new GRPCManagerServiceImpl(servers)); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - servers.values().forEach(server -> { - try { - server.start(); - } catch (ServerException e) { - logger.error(e.getMessage(), e); - } - }); - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java deleted file mode 100644 index 4d45df1bb03b..000000000000 --- a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/java/org/skywalking/apm/collector/grpc/manager/service/GRPCManagerServiceImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.grpc.manager.service; - -import java.util.Map; -import org.skywalking.apm.collector.server.Server; -import org.skywalking.apm.collector.server.ServerException; -import org.skywalking.apm.collector.server.grpc.GRPCServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GRPCManagerServiceImpl implements GRPCManagerService { - - private final Logger logger = LoggerFactory.getLogger(GRPCManagerServiceImpl.class); - - private final Map servers; - - public GRPCManagerServiceImpl(Map servers) { - this.servers = servers; - } - - @Override public Server createIfAbsent(String host, int port) { - String id = host + String.valueOf(port); - if (servers.containsKey(id)) { - return servers.get(id); - } else { - GRPCServer server = new GRPCServer(host, port); - try { - server.initialize(); - } catch (ServerException e) { - logger.error(e.getMessage(), e); - } - servers.put(id, server); - return server; - } - } -} diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..54388e5e50bf --- /dev/null +++ b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.grpc.manager.GRPCManagerProvider diff --git a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 271018d633aa..000000000000 --- a/apm-collector/apm-collector-grpc-manager/collector-grpc-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.grpc.manager.GRPCManagerProvider diff --git a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/MetricCollector.java b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricCollector.java similarity index 88% rename from apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/MetricCollector.java rename to apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricCollector.java index 627a30a305dd..0b46a079653c 100644 --- a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/MetricCollector.java +++ b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricCollector.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.instrument; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.instrument; import java.lang.reflect.Method; import java.util.HashMap; diff --git a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceInstrumentation.java b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceInstrumentation.java similarity index 77% rename from apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceInstrumentation.java rename to apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceInstrumentation.java index 7494202bdfec..ccc594024788 100644 --- a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceInstrumentation.java +++ b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceInstrumentation.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.collector.instrument; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.instrument; import net.bytebuddy.ByteBuddy; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.implementation.MethodDelegation; import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.core.module.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java new file mode 100644 index 000000000000..1c08a96bffa8 --- /dev/null +++ b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.instrument; + +import java.lang.reflect.Method; +import java.util.concurrent.Callable; +import net.bytebuddy.implementation.bind.annotation.AllArguments; +import net.bytebuddy.implementation.bind.annotation.Origin; +import net.bytebuddy.implementation.bind.annotation.RuntimeType; +import net.bytebuddy.implementation.bind.annotation.SuperCall; +import net.bytebuddy.implementation.bind.annotation.This; + +/** + * @author wu-sheng + */ +public class ServiceMetricTracing { + private MetricCollector.ServiceMetric serviceMetric; + + public ServiceMetricTracing(String module, String provider, String service) { + serviceMetric = MetricCollector.INSTANCE.registerService(module, provider, service); + } + + @RuntimeType + public Object intercept(@This Object obj, + @AllArguments Object[] allArguments, + @SuperCall Callable zuper, + @Origin Method method + ) throws Throwable { + boolean occurError = false; + long startNano = System.nanoTime(); + long endNano; + try { + return zuper.call(); + } catch (Throwable t) { + occurError = true; + throw t; + } finally { + endNano = System.nanoTime(); + serviceMetric.trace(method, endNano - startNano, occurError); + } + } +} diff --git a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/TracedService.java b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/TracedService.java new file mode 100644 index 000000000000..36bf36ee9cb4 --- /dev/null +++ b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/TracedService.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.instrument; + +/** + * The TracedService implementation are dynamic class, generated by {@link ServiceInstrumentation}. + * + * By that, all the services metrics are collected, and report in the certain cycle through console. + * + * @author wu-sheng + */ +public interface TracedService { +} diff --git a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceMetricTracing.java b/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceMetricTracing.java deleted file mode 100644 index 320a00d1f7ad..000000000000 --- a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/ServiceMetricTracing.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.instrument; - -import java.lang.reflect.Method; -import java.util.concurrent.Callable; -import net.bytebuddy.implementation.bind.annotation.AllArguments; -import net.bytebuddy.implementation.bind.annotation.Origin; -import net.bytebuddy.implementation.bind.annotation.RuntimeType; -import net.bytebuddy.implementation.bind.annotation.SuperCall; -import net.bytebuddy.implementation.bind.annotation.This; - -/** - * @author wu-sheng - */ -public class ServiceMetricTracing { - private MetricCollector.ServiceMetric serviceMetric; - - public ServiceMetricTracing(String module, String provider, String service) { - serviceMetric = MetricCollector.INSTANCE.registerService(module, provider, service); - } - - @RuntimeType - public Object intercept(@This Object obj, - @AllArguments Object[] allArguments, - @SuperCall Callable zuper, - @Origin Method method - ) throws Throwable { - boolean occurError = false; - long startNano = System.nanoTime(); - long endNano; - try { - return zuper.call(); - } catch (Throwable t) { - occurError = true; - throw t; - } finally { - endNano = System.nanoTime(); - serviceMetric.trace(method, endNano - startNano, occurError); - } - } -} diff --git a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/TracedService.java b/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/TracedService.java deleted file mode 100644 index 8e8659b08f0e..000000000000 --- a/apm-collector/apm-collector-instrument/src/main/java/org/skywalking/apm/collector/instrument/TracedService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.instrument; - -/** - * The TracedService implementation are dynamic class, generated by {@link ServiceInstrumentation}. - * - * By that, all the services metrics are collected, and report in the certain cycle through console. - * - * @author wu-sheng - */ -public interface TracedService { -} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerModule.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerModule.java new file mode 100644 index 000000000000..a4f8b1f83d04 --- /dev/null +++ b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerModule.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.jetty.manager; + +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerService; + +/** + * @author peng-yongsheng + */ +public class JettyManagerModule extends Module { + + public static final String NAME = "jetty_manager"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {JettyManagerService.class}; + } +} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java new file mode 100644 index 000000000000..cc38fcc4e352 --- /dev/null +++ b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.jetty.manager.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.server.ServerHandler; + +/** + * @author peng-yongsheng + */ +public interface JettyManagerService extends Service { + Server createIfAbsent(String host, int port, String contextPath); + + void addHandler(String host, int port, ServerHandler serverHandler); +} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerModule.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerModule.java deleted file mode 100644 index f25d88e83c5a..000000000000 --- a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.jetty.manager; - -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService; - -/** - * @author peng-yongsheng - */ -public class JettyManagerModule extends Module { - - public static final String NAME = "jetty_manager"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {JettyManagerService.class}; - } -} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java deleted file mode 100644 index c99bf3cf606e..000000000000 --- a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.jetty.manager.service; - -import org.skywalking.apm.collector.core.module.Service; -import org.skywalking.apm.collector.server.Server; -import org.skywalking.apm.collector.server.ServerHandler; - -/** - * @author peng-yongsheng - */ -public interface JettyManagerService extends Service { - Server createIfAbsent(String host, int port, String contextPath); - - void addHandler(String host, int port, ServerHandler serverHandler); -} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..8faa4a31fa7e --- /dev/null +++ b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.jetty.manager.JettyManagerModule diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index d13bb1576737..000000000000 --- a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.jetty.manager.JettyManagerModule diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java new file mode 100644 index 000000000000..6b5d0f61f7c6 --- /dev/null +++ b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.jetty.manager; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.apache.skywalking.apm.collector.server.jetty.JettyServer; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerService; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerServiceImpl; +import org.apache.skywalking.apm.collector.server.ServerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class JettyManagerProvider extends ModuleProvider { + + private final Logger logger = LoggerFactory.getLogger(JettyManagerProvider.class); + + private Map servers = new HashMap<>(); + + @Override public String name() { + return "jetty"; + } + + @Override public Class module() { + return JettyManagerModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(JettyManagerService.class, new JettyManagerServiceImpl(servers)); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + servers.values().forEach(server -> { + try { + server.start(); + } catch (ServerException e) { + logger.error(e.getMessage(), e); + } + }); + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java new file mode 100644 index 000000000000..81ebabb1f0f3 --- /dev/null +++ b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/apache/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.jetty.manager.service; + +import java.util.Map; +import org.apache.skywalking.apm.collector.server.jetty.JettyServer; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.server.ServerException; +import org.apache.skywalking.apm.collector.server.ServerHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class JettyManagerServiceImpl implements JettyManagerService { + + private final Logger logger = LoggerFactory.getLogger(JettyManagerServiceImpl.class); + + private final Map servers; + + public JettyManagerServiceImpl(Map servers) { + this.servers = servers; + } + + @Override public Server createIfAbsent(String host, int port, String contextPath) { + String id = host + String.valueOf(port); + if (servers.containsKey(id)) { + return servers.get(id); + } else { + JettyServer server = new JettyServer(host, port, contextPath); + try { + server.initialize(); + } catch (ServerException e) { + logger.error(e.getMessage(), e); + } + servers.put(id, server); + return server; + } + } + + @Override public void addHandler(String host, int port, ServerHandler serverHandler) { + String id = host + String.valueOf(port); + if (servers.containsKey(id)) { + servers.get(id).addHandler(serverHandler); + } else { + throw new UnexpectedException("Please create server before add server handler."); + } + } +} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java deleted file mode 100644 index 774d56203421..000000000000 --- a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/JettyManagerProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.jetty.manager; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerServiceImpl; -import org.skywalking.apm.collector.server.ServerException; -import org.skywalking.apm.collector.server.jetty.JettyServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class JettyManagerProvider extends ModuleProvider { - - private final Logger logger = LoggerFactory.getLogger(JettyManagerProvider.class); - - private Map servers = new HashMap<>(); - - @Override public String name() { - return "jetty"; - } - - @Override public Class module() { - return JettyManagerModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(JettyManagerService.class, new JettyManagerServiceImpl(servers)); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - servers.values().forEach(server -> { - try { - server.start(); - } catch (ServerException e) { - logger.error(e.getMessage(), e); - } - }); - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java deleted file mode 100644 index 99ba37e0ccb9..000000000000 --- a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/java/org/skywalking/apm/collector/jetty/manager/service/JettyManagerServiceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.jetty.manager.service; - -import java.util.Map; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.server.Server; -import org.skywalking.apm.collector.server.ServerException; -import org.skywalking.apm.collector.server.ServerHandler; -import org.skywalking.apm.collector.server.jetty.JettyServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class JettyManagerServiceImpl implements JettyManagerService { - - private final Logger logger = LoggerFactory.getLogger(JettyManagerServiceImpl.class); - - private final Map servers; - - public JettyManagerServiceImpl(Map servers) { - this.servers = servers; - } - - @Override public Server createIfAbsent(String host, int port, String contextPath) { - String id = host + String.valueOf(port); - if (servers.containsKey(id)) { - return servers.get(id); - } else { - JettyServer server = new JettyServer(host, port, contextPath); - try { - server.initialize(); - } catch (ServerException e) { - logger.error(e.getMessage(), e); - } - servers.put(id, server); - return server; - } - } - - @Override public void addHandler(String host, int port, ServerHandler serverHandler) { - String id = host + String.valueOf(port); - if (servers.containsKey(id)) { - servers.get(id).addHandler(serverHandler); - } else { - throw new UnexpectedException("Please create server before add server handler."); - } - } -} diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..077444150f9f --- /dev/null +++ b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.jetty.manager.JettyManagerProvider diff --git a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index a2fff85b143e..000000000000 --- a/apm-collector/apm-collector-jetty-manager/collector-jetty-manager-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.jetty.manager.JettyManagerProvider diff --git a/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/NamingModule.java b/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/NamingModule.java new file mode 100644 index 000000000000..c953f3bcaf5b --- /dev/null +++ b/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/NamingModule.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.naming; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class NamingModule extends Module { + + public static final String NAME = "naming"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {NamingHandlerRegisterService.class}; + } +} diff --git a/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java b/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java new file mode 100644 index 000000000000..486fed899ee7 --- /dev/null +++ b/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/apache/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.naming.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.server.ServerHandler; + +/** + * @author peng-yongsheng + */ +public interface NamingHandlerRegisterService extends Service { + void register(ServerHandler namingHandler); +} diff --git a/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/NamingModule.java b/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/NamingModule.java deleted file mode 100644 index 6880857076ac..000000000000 --- a/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/NamingModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.naming; - -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.Service; -import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; - -/** - * @author peng-yongsheng - */ -public class NamingModule extends Module { - - public static final String NAME = "naming"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {NamingHandlerRegisterService.class}; - } -} diff --git a/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java b/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java deleted file mode 100644 index 72b7e892879d..000000000000 --- a/apm-collector/apm-collector-naming/collector-naming-define/src/main/java/org/skywalking/apm/collector/naming/service/NamingHandlerRegisterService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.naming.service; - -import org.skywalking.apm.collector.core.module.Service; -import org.skywalking.apm.collector.server.ServerHandler; - -/** - * @author peng-yongsheng - */ -public interface NamingHandlerRegisterService extends Service { - void register(ServerHandler namingHandler); -} diff --git a/apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..71c245ff3569 --- /dev/null +++ b/apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.naming.NamingModule diff --git a/apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 1163cba09404..000000000000 --- a/apm-collector/apm-collector-naming/collector-naming-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.naming.NamingModule diff --git a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java new file mode 100644 index 000000000000..3f7149472143 --- /dev/null +++ b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.naming.jetty; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.naming.NamingModule; +import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.jetty.manager.JettyManagerModule; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerService; +import org.apache.skywalking.apm.collector.naming.jetty.service.NamingJettyHandlerRegisterService; + +/** + * @author peng-yongsheng + */ +public class NamingModuleJettyProvider extends ModuleProvider { + + private static final String HOST = "host"; + private static final String PORT = "port"; + private static final String CONTEXT_PATH = "context_path"; + + @Override public String name() { + return "jetty"; + } + + @Override public Class module() { + return NamingModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + final String host = config.getProperty(HOST); + final Integer port = (Integer)config.get(PORT); + this.registerServiceImplementation(NamingHandlerRegisterService.class, new NamingJettyHandlerRegisterService(host, port, getManager())); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + String host = config.getProperty(HOST); + Integer port = (Integer)config.get(PORT); + String contextPath = config.getProperty(CONTEXT_PATH); + + JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class); + managerService.createIfAbsent(host, port, contextPath); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + } + + @Override public String[] requiredModules() { + return new String[] {ClusterModule.NAME, JettyManagerModule.NAME}; + } +} diff --git a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java new file mode 100644 index 000000000000..4a4f5737ebd6 --- /dev/null +++ b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.naming.jetty.service; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerService; +import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; +import org.apache.skywalking.apm.collector.jetty.manager.JettyManagerModule; +import org.apache.skywalking.apm.collector.server.ServerHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class NamingJettyHandlerRegisterService implements NamingHandlerRegisterService { + + private final Logger logger = LoggerFactory.getLogger(NamingJettyHandlerRegisterService.class); + + private final ModuleManager moduleManager; + private final String host; + private final int port; + + public NamingJettyHandlerRegisterService(String host, int port, ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.host = host; + this.port = port; + } + + @Override public void register(ServerHandler namingHandler) { + JettyManagerService managerService = moduleManager.find(JettyManagerModule.NAME).getService(JettyManagerService.class); + managerService.addHandler(this.host, this.port, namingHandler); + } +} diff --git a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java deleted file mode 100644 index 7db728b2c152..000000000000 --- a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/NamingModuleJettyProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.naming.jetty; - -import java.util.Properties; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.jetty.manager.JettyManagerModule; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService; -import org.skywalking.apm.collector.naming.NamingModule; -import org.skywalking.apm.collector.naming.jetty.service.NamingJettyHandlerRegisterService; -import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; - -/** - * @author peng-yongsheng - */ -public class NamingModuleJettyProvider extends ModuleProvider { - - private static final String HOST = "host"; - private static final String PORT = "port"; - private static final String CONTEXT_PATH = "context_path"; - - @Override public String name() { - return "jetty"; - } - - @Override public Class module() { - return NamingModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - final String host = config.getProperty(HOST); - final Integer port = (Integer)config.get(PORT); - this.registerServiceImplementation(NamingHandlerRegisterService.class, new NamingJettyHandlerRegisterService(host, port, getManager())); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - String host = config.getProperty(HOST); - Integer port = (Integer)config.get(PORT); - String contextPath = config.getProperty(CONTEXT_PATH); - - JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class); - managerService.createIfAbsent(host, port, contextPath); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - } - - @Override public String[] requiredModules() { - return new String[] {ClusterModule.NAME, JettyManagerModule.NAME}; - } -} diff --git a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java deleted file mode 100644 index fb42903f5378..000000000000 --- a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/java/org/skywalking/apm/collector/naming/jetty/service/NamingJettyHandlerRegisterService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.naming.jetty.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.jetty.manager.JettyManagerModule; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService; -import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; -import org.skywalking.apm.collector.server.ServerHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class NamingJettyHandlerRegisterService implements NamingHandlerRegisterService { - - private final Logger logger = LoggerFactory.getLogger(NamingJettyHandlerRegisterService.class); - - private final ModuleManager moduleManager; - private final String host; - private final int port; - - public NamingJettyHandlerRegisterService(String host, int port, ModuleManager moduleManager) { - this.moduleManager = moduleManager; - this.host = host; - this.port = port; - } - - @Override public void register(ServerHandler namingHandler) { - JettyManagerService managerService = moduleManager.find(JettyManagerModule.NAME).getService(JettyManagerService.class); - managerService.addHandler(this.host, this.port, namingHandler); - } -} diff --git a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..cf1d59997284 --- /dev/null +++ b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.naming.jetty.NamingModuleJettyProvider diff --git a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index d560440907df..000000000000 --- a/apm-collector/apm-collector-naming/collector-naming-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.naming.jetty.NamingModuleJettyProvider diff --git a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java new file mode 100644 index 000000000000..09e89aca6575 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.datacarrier; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.queue.QueueModule; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.queue.datacarrier.service.DataCarrierQueueCreatorService; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; + +/** + * @author peng-yongsheng + */ +public class QueueModuleDataCarrierProvider extends ModuleProvider { + + @Override public String name() { + return "datacarrier"; + } + + @Override public Class module() { + return QueueModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(QueueCreatorService.class, new DataCarrierQueueCreatorService()); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java new file mode 100644 index 000000000000..0ab928b3ffc3 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/apache/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.datacarrier.service; + +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.apache.skywalking.apm.collector.queue.base.QueueExecutor; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; + +/** + * @author peng-yongsheng + */ +public class DataCarrierQueueCreatorService implements QueueCreatorService { + + @Override public QueueEventHandler create(int queueSize, QueueExecutor executor) { + return null; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java deleted file mode 100644 index 87ebabb0fcdb..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/QueueModuleDataCarrierProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.datacarrier; - -import java.util.Properties; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.queue.QueueModule; -import org.skywalking.apm.collector.queue.datacarrier.service.DataCarrierQueueCreatorService; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; - -/** - * @author peng-yongsheng - */ -public class QueueModuleDataCarrierProvider extends ModuleProvider { - - @Override public String name() { - return "datacarrier"; - } - - @Override public Class module() { - return QueueModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(QueueCreatorService.class, new DataCarrierQueueCreatorService()); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java deleted file mode 100644 index 75ddba52acb0..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/java/org/skywalking/apm/collector/queue/datacarrier/service/DataCarrierQueueCreatorService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.datacarrier.service; - -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.base.QueueExecutor; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; - -/** - * @author peng-yongsheng - */ -public class DataCarrierQueueCreatorService implements QueueCreatorService { - - @Override public QueueEventHandler create(int queueSize, QueueExecutor executor) { - return null; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..1e1786937533 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.queue.datacarrier.QueueModuleDataCarrierProvider diff --git a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 872cf566d457..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-datacarrier-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.queue.datacarrier.QueueModuleDataCarrierProvider diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/QueueModule.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/QueueModule.java new file mode 100644 index 000000000000..ee6e0bbe5e6b --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/QueueModule.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue; + +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; + +/** + * @author peng-yongsheng + */ +public class QueueModule extends Module { + + public static final String NAME = "queue"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {QueueCreatorService.class}; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/DaemonThreadFactory.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/DaemonThreadFactory.java new file mode 100644 index 000000000000..3047c647230f --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/DaemonThreadFactory.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.base; + +import java.util.concurrent.ThreadFactory; + +/** + * @author peng-yongsheng + */ +public enum DaemonThreadFactory implements ThreadFactory { + INSTANCE; + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/MessageHolder.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/MessageHolder.java new file mode 100644 index 000000000000..1fb2b7e2ff31 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/MessageHolder.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.base; + +import org.apache.skywalking.apm.collector.core.data.EndOfBatchQueueMessage; + +/** + * @author peng-yongsheng + */ +public class MessageHolder { + private MESSAGE message; + + public MESSAGE getMessage() { + return message; + } + + public void setMessage(MESSAGE message) { + this.message = message; + } + + public void reset() { + message = null; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueCreator.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueCreator.java new file mode 100644 index 000000000000..058c4177febc --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueCreator.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.base; + +/** + * @author peng-yongsheng + */ +public interface QueueCreator { + QueueEventHandler create(int queueSize, QueueExecutor executor); +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueEventHandler.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueEventHandler.java new file mode 100644 index 000000000000..292a7d655a14 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueEventHandler.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.base; + +/** + * @author peng-yongsheng + */ +public interface QueueEventHandler { + void tell(MESSAGE message); +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueExecutor.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueExecutor.java new file mode 100644 index 000000000000..717aa71629a3 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/base/QueueExecutor.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.base; + +import org.apache.skywalking.apm.collector.core.framework.Executor; + +/** + * @author peng-yongsheng + */ +public interface QueueExecutor extends Executor { +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/service/QueueCreatorService.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/service/QueueCreatorService.java new file mode 100644 index 000000000000..4f7ee8ea8262 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/apache/skywalking/apm/collector/queue/service/QueueCreatorService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.apache.skywalking.apm.collector.queue.base.QueueExecutor; + +/** + * @author peng-yongsheng + */ +public interface QueueCreatorService extends Service { + QueueEventHandler create(int queueSize, QueueExecutor executor); +} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/QueueModule.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/QueueModule.java deleted file mode 100644 index 1f54c18e6d98..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/QueueModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue; - -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; - -/** - * @author peng-yongsheng - */ -public class QueueModule extends Module { - - public static final String NAME = "queue"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {QueueCreatorService.class}; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/DaemonThreadFactory.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/DaemonThreadFactory.java deleted file mode 100644 index 8acbe3d1daa5..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/DaemonThreadFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.base; - -import java.util.concurrent.ThreadFactory; - -/** - * @author peng-yongsheng - */ -public enum DaemonThreadFactory implements ThreadFactory { - INSTANCE; - - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/MessageHolder.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/MessageHolder.java deleted file mode 100644 index e52cf2d6aa7c..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/MessageHolder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.base; - -import org.skywalking.apm.collector.core.data.EndOfBatchQueueMessage; - -/** - * @author peng-yongsheng - */ -public class MessageHolder { - private MESSAGE message; - - public MESSAGE getMessage() { - return message; - } - - public void setMessage(MESSAGE message) { - this.message = message; - } - - public void reset() { - message = null; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueCreator.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueCreator.java deleted file mode 100644 index f36fb10adcb5..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueCreator.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.base; - -/** - * @author peng-yongsheng - */ -public interface QueueCreator { - QueueEventHandler create(int queueSize, QueueExecutor executor); -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueEventHandler.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueEventHandler.java deleted file mode 100644 index d37d498d7ba9..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueEventHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.base; - -/** - * @author peng-yongsheng - */ -public interface QueueEventHandler { - void tell(MESSAGE message); -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueExecutor.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueExecutor.java deleted file mode 100644 index 6c9a71db4a8f..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/base/QueueExecutor.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.base; - -import org.skywalking.apm.collector.core.framework.Executor; - -/** - * @author peng-yongsheng - */ -public interface QueueExecutor extends Executor { -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/service/QueueCreatorService.java b/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/service/QueueCreatorService.java deleted file mode 100644 index aeb4a4d7cd9d..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/java/org/skywalking/apm/collector/queue/service/QueueCreatorService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.service; - -import org.skywalking.apm.collector.core.module.Service; -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.base.QueueExecutor; - -/** - * @author peng-yongsheng - */ -public interface QueueCreatorService extends Service { - QueueEventHandler create(int queueSize, QueueExecutor executor); -} diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..4d9205c38a86 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.queue.QueueModule diff --git a/apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 0989a280f27b..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.queue.QueueModule diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java new file mode 100644 index 000000000000..cb0ddf5a292b --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.disruptor; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.queue.disruptor.service.DisruptorQueueCreatorService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.queue.QueueModule; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; + +/** + * @author peng-yongsheng + */ +public class QueueModuleDisruptorProvider extends ModuleProvider { + + @Override public String name() { + return "disruptor"; + } + + @Override public Class module() { + return QueueModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + this.registerServiceImplementation(QueueCreatorService.class, new DisruptorQueueCreatorService()); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java new file mode 100644 index 000000000000..82b11cecc779 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.disruptor.base; + +import com.lmax.disruptor.EventHandler; +import com.lmax.disruptor.RingBuffer; +import org.apache.skywalking.apm.collector.core.CollectorException; +import org.apache.skywalking.apm.collector.core.data.EndOfBatchQueueMessage; +import org.apache.skywalking.apm.collector.queue.base.QueueExecutor; +import org.apache.skywalking.apm.collector.queue.base.MessageHolder; +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class DisruptorEventHandler implements EventHandler>, QueueEventHandler { + + private final Logger logger = LoggerFactory.getLogger(DisruptorEventHandler.class); + + private RingBuffer> ringBuffer; + private QueueExecutor executor; + + DisruptorEventHandler(RingBuffer> ringBuffer, QueueExecutor executor) { + this.ringBuffer = ringBuffer; + this.executor = executor; + } + + /** + * Receive the message from disruptor, when message in disruptor is empty, then send the cached data + * to the next workers. + * + * @param event published to the {@link RingBuffer} + * @param sequence of the event being processed + * @param endOfBatch flag to indicate if this is the last event in a batch from the {@link RingBuffer} + */ + public void onEvent(MessageHolder event, long sequence, boolean endOfBatch) throws CollectorException { + MESSAGE message = event.getMessage(); + event.reset(); + + message.setEndOfBatch(endOfBatch); + executor.execute(message); + } + + /** + * Push the message into disruptor ring buffer. + * + * @param message of the data to process. + */ + public void tell(MESSAGE message) { + long sequence = ringBuffer.next(); + try { + ringBuffer.get(sequence).setMessage(message); + } finally { + ringBuffer.publish(sequence); + } + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java new file mode 100644 index 000000000000..1f930300e516 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.disruptor.base; + +import com.lmax.disruptor.ExceptionHandler; +import com.lmax.disruptor.RingBuffer; +import com.lmax.disruptor.dsl.Disruptor; +import org.apache.skywalking.apm.collector.queue.base.DaemonThreadFactory; +import org.apache.skywalking.apm.collector.queue.base.MessageHolder; +import org.apache.skywalking.apm.collector.queue.base.QueueCreator; +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.apache.skywalking.apm.collector.queue.base.QueueExecutor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class DisruptorQueueCreator implements QueueCreator { + + private final Logger logger = LoggerFactory.getLogger(DisruptorQueueCreator.class); + + @Override public QueueEventHandler create(int queueSize, QueueExecutor executor) { + // Specify the size of the ring buffer, must be power of 2. + if (!((((queueSize - 1) & queueSize) == 0) && queueSize != 0)) { + throw new IllegalArgumentException("queue size must be power of 2"); + } + + // Construct the Disruptor + Disruptor disruptor = new Disruptor<>(MessageHolderFactory.INSTANCE, queueSize, DaemonThreadFactory.INSTANCE); + disruptor.setDefaultExceptionHandler(new ExceptionHandler() { + @Override public void handleEventException(Throwable ex, long sequence, MessageHolder event) { + logger.error("Handle disruptor error event! message: {}.", event.getMessage(), ex); + } + + @Override public void handleOnStartException(Throwable ex) { + logger.error("create disruptor queue failed!", ex); + } + + @Override public void handleOnShutdownException(Throwable ex) { + logger.error("shutdown disruptor queue failed!", ex); + } + }); + + RingBuffer ringBuffer = disruptor.getRingBuffer(); + DisruptorEventHandler eventHandler = new DisruptorEventHandler(ringBuffer, executor); + + // Connect the handler + disruptor.handleEventsWith(eventHandler); + + // Start the Disruptor, starts all threads running + disruptor.start(); + return eventHandler; + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java new file mode 100644 index 000000000000..fe25807891d4 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.disruptor.base; + +import com.lmax.disruptor.EventFactory; +import org.apache.skywalking.apm.collector.queue.base.MessageHolder; + +/** + * @author peng-yongsheng + */ +public class MessageHolderFactory implements EventFactory { + + public static MessageHolderFactory INSTANCE = new MessageHolderFactory(); + + public MessageHolder newInstance() { + return new MessageHolder(); + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java new file mode 100644 index 000000000000..69db58542c15 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/apache/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.queue.disruptor.service; + +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.apache.skywalking.apm.collector.queue.base.QueueExecutor; +import org.apache.skywalking.apm.collector.queue.disruptor.base.DisruptorQueueCreator; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; + +/** + * @author peng-yongsheng + */ +public class DisruptorQueueCreatorService implements QueueCreatorService { + + private final DisruptorQueueCreator creator; + + public DisruptorQueueCreatorService() { + this.creator = new DisruptorQueueCreator(); + } + + @Override public QueueEventHandler create(int queueSize, QueueExecutor executor) { + return creator.create(queueSize, executor); + } +} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java deleted file mode 100644 index fb263c6d7ba8..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/QueueModuleDisruptorProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.disruptor; - -import java.util.Properties; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.queue.QueueModule; -import org.skywalking.apm.collector.queue.disruptor.service.DisruptorQueueCreatorService; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; - -/** - * @author peng-yongsheng - */ -public class QueueModuleDisruptorProvider extends ModuleProvider { - - @Override public String name() { - return "disruptor"; - } - - @Override public Class module() { - return QueueModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - this.registerServiceImplementation(QueueCreatorService.class, new DisruptorQueueCreatorService()); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java deleted file mode 100644 index 04ca0925a9c3..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorEventHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.disruptor.base; - -import com.lmax.disruptor.EventHandler; -import com.lmax.disruptor.RingBuffer; -import org.skywalking.apm.collector.core.CollectorException; -import org.skywalking.apm.collector.core.data.EndOfBatchQueueMessage; -import org.skywalking.apm.collector.queue.base.MessageHolder; -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.base.QueueExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class DisruptorEventHandler implements EventHandler>, QueueEventHandler { - - private final Logger logger = LoggerFactory.getLogger(DisruptorEventHandler.class); - - private RingBuffer> ringBuffer; - private QueueExecutor executor; - - DisruptorEventHandler(RingBuffer> ringBuffer, QueueExecutor executor) { - this.ringBuffer = ringBuffer; - this.executor = executor; - } - - /** - * Receive the message from disruptor, when message in disruptor is empty, then send the cached data - * to the next workers. - * - * @param event published to the {@link RingBuffer} - * @param sequence of the event being processed - * @param endOfBatch flag to indicate if this is the last event in a batch from the {@link RingBuffer} - */ - public void onEvent(MessageHolder event, long sequence, boolean endOfBatch) throws CollectorException { - MESSAGE message = event.getMessage(); - event.reset(); - - message.setEndOfBatch(endOfBatch); - executor.execute(message); - } - - /** - * Push the message into disruptor ring buffer. - * - * @param message of the data to process. - */ - public void tell(MESSAGE message) { - long sequence = ringBuffer.next(); - try { - ringBuffer.get(sequence).setMessage(message); - } finally { - ringBuffer.publish(sequence); - } - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java deleted file mode 100644 index 25c15bcb042e..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/DisruptorQueueCreator.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.disruptor.base; - -import com.lmax.disruptor.ExceptionHandler; -import com.lmax.disruptor.RingBuffer; -import com.lmax.disruptor.dsl.Disruptor; -import org.skywalking.apm.collector.queue.base.DaemonThreadFactory; -import org.skywalking.apm.collector.queue.base.MessageHolder; -import org.skywalking.apm.collector.queue.base.QueueCreator; -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.base.QueueExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class DisruptorQueueCreator implements QueueCreator { - - private final Logger logger = LoggerFactory.getLogger(DisruptorQueueCreator.class); - - @Override public QueueEventHandler create(int queueSize, QueueExecutor executor) { - // Specify the size of the ring buffer, must be power of 2. - if (!((((queueSize - 1) & queueSize) == 0) && queueSize != 0)) { - throw new IllegalArgumentException("queue size must be power of 2"); - } - - // Construct the Disruptor - Disruptor disruptor = new Disruptor<>(MessageHolderFactory.INSTANCE, queueSize, DaemonThreadFactory.INSTANCE); - disruptor.setDefaultExceptionHandler(new ExceptionHandler() { - @Override public void handleEventException(Throwable ex, long sequence, MessageHolder event) { - logger.error("Handle disruptor error event! message: {}.", event.getMessage(), ex); - } - - @Override public void handleOnStartException(Throwable ex) { - logger.error("create disruptor queue failed!", ex); - } - - @Override public void handleOnShutdownException(Throwable ex) { - logger.error("shutdown disruptor queue failed!", ex); - } - }); - - RingBuffer ringBuffer = disruptor.getRingBuffer(); - DisruptorEventHandler eventHandler = new DisruptorEventHandler(ringBuffer, executor); - - // Connect the handler - disruptor.handleEventsWith(eventHandler); - - // Start the Disruptor, starts all threads running - disruptor.start(); - return eventHandler; - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java deleted file mode 100644 index 9ce91c26082b..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/base/MessageHolderFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.disruptor.base; - -import com.lmax.disruptor.EventFactory; -import org.skywalking.apm.collector.queue.base.MessageHolder; - -/** - * @author peng-yongsheng - */ -public class MessageHolderFactory implements EventFactory { - - public static MessageHolderFactory INSTANCE = new MessageHolderFactory(); - - public MessageHolder newInstance() { - return new MessageHolder(); - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java deleted file mode 100644 index 32e1c033e28a..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/java/org/skywalking/apm/collector/queue/disruptor/service/DisruptorQueueCreatorService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.queue.disruptor.service; - -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.base.QueueExecutor; -import org.skywalking.apm.collector.queue.disruptor.base.DisruptorQueueCreator; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; - -/** - * @author peng-yongsheng - */ -public class DisruptorQueueCreatorService implements QueueCreatorService { - - private final DisruptorQueueCreator creator; - - public DisruptorQueueCreatorService() { - this.creator = new DisruptorQueueCreator(); - } - - @Override public QueueEventHandler create(int queueSize, QueueExecutor executor) { - return creator.create(queueSize, executor); - } -} diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..1fe4381fef82 --- /dev/null +++ b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.queue.disruptor.QueueModuleDisruptorProvider diff --git a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 1110733f90de..000000000000 --- a/apm-collector/apm-collector-queue/collector-queue-disruptor-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.queue.disruptor.QueueModuleDisruptorProvider diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteException.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteException.java new file mode 100644 index 000000000000..ab60c8695e3e --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public abstract class RemoteException extends CollectorException { + + public RemoteException(String message) { + super(message); + } + + public RemoteException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteModule.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteModule.java new file mode 100644 index 000000000000..29a78b66c7f0 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RemoteModule.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote; + +import org.apache.skywalking.apm.collector.remote.service.RemoteDataRegisterService; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class RemoteModule extends Module { + + public static final String NAME = "remote"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {RemoteSenderService.class, RemoteDataRegisterService.class}; + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RoutingRule.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RoutingRule.java new file mode 100644 index 000000000000..f03e3dc35a4b --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/RoutingRule.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote; + +/** + * @author peng-yongsheng + */ +public enum RoutingRule { + HashCode, ForeverFirst +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java similarity index 75% rename from apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java rename to apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java index d4465f1c2ce6..67ea53d80b18 100644 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/CommonRemoteDataRegisterService.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.remote.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; import java.util.HashMap; import java.util.Map; -import org.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClient.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClient.java new file mode 100644 index 000000000000..62f4a930aa49 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClient.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface RemoteClient extends Comparable { + String getAddress(); + + void push(int graphId, int nodeId, Data data); + + boolean equals(String address); +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClientService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClientService.java new file mode 100644 index 000000000000..d9e4b7249b5d --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteClientService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface RemoteClientService extends Service { + RemoteClient create(String host, int port, int channelSize, int bufferSize); +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java new file mode 100644 index 000000000000..462fb645cf97 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface RemoteDataIDGetter { + Integer getRemoteDataId(Class dataClass) throws RemoteDataMappingIdNotFoundException; +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java new file mode 100644 index 000000000000..b33c21387159 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +/** + * @author peng-yongsheng + */ +public interface RemoteDataInstanceCreatorGetter { + RemoteDataRegisterService.RemoteDataInstanceCreator getInstanceCreator( + Integer remoteDataId) throws RemoteDataInstanceCreatorNotFoundException; +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java new file mode 100644 index 000000000000..28a735b59cd6 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.remote.RemoteException; + +/** + * @author peng-yongsheng + */ +public class RemoteDataInstanceCreatorNotFoundException extends RemoteException { + public RemoteDataInstanceCreatorNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java new file mode 100644 index 000000000000..9191623fb34e --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.remote.RemoteException; + +/** + * @author peng-yongsheng + */ +public class RemoteDataMappingIdNotFoundException extends RemoteException { + public RemoteDataMappingIdNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java new file mode 100644 index 000000000000..71dcc2324695 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface RemoteDataRegisterService extends Service { + void register(Class dataClass, RemoteDataInstanceCreator instanceCreator); + + interface RemoteDataInstanceCreator { + RemoteData createInstance(String id); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDeserializeService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDeserializeService.java new file mode 100644 index 000000000000..ddf073a7a30e --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteDeserializeService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface RemoteDeserializeService { + void deserialize(RemoteData remoteData, Data data); +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSenderService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSenderService.java new file mode 100644 index 000000000000..49d1752869a7 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSenderService.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface RemoteSenderService extends Service { + Mode send(int graphId, int nodeId, Data data, Selector selector); + + enum Mode { + Remote, Local + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSerializeService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSerializeService.java new file mode 100644 index 000000000000..e3f9a3c07858 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/RemoteSerializeService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface RemoteSerializeService { + Builder serialize(Data data); +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/Selector.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/Selector.java new file mode 100644 index 000000000000..2e7ca452d487 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/apache/skywalking/apm/collector/remote/service/Selector.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.service; + +/** + * @author peng-yongsheng + */ +public enum Selector { + HashCode, Rolling, ForeverFirst +} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteException.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteException.java deleted file mode 100644 index 879dedfdafab..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public abstract class RemoteException extends CollectorException { - - public RemoteException(String message) { - super(message); - } - - public RemoteException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteModule.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteModule.java deleted file mode 100644 index 85bda6ba8f99..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RemoteModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote; - -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.remote.service.RemoteDataRegisterService; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; - -/** - * @author peng-yongsheng - */ -public class RemoteModule extends Module { - - public static final String NAME = "remote"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[] {RemoteSenderService.class, RemoteDataRegisterService.class}; - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RoutingRule.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RoutingRule.java deleted file mode 100644 index d647e4ef848b..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/RoutingRule.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote; - -/** - * @author peng-yongsheng - */ -public enum RoutingRule { - HashCode, ForeverFirst -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClient.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClient.java deleted file mode 100644 index beb329979f27..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClient.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public interface RemoteClient extends Comparable { - String getAddress(); - - void push(int graphId, int nodeId, Data data); - - boolean equals(String address); -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClientService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClientService.java deleted file mode 100644 index 7d96ec800bf9..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteClientService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface RemoteClientService extends Service { - RemoteClient create(String host, int port, int channelSize, int bufferSize); -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java deleted file mode 100644 index 1f00e36d755a..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataIDGetter.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public interface RemoteDataIDGetter { - Integer getRemoteDataId(Class dataClass) throws RemoteDataMappingIdNotFoundException; -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java deleted file mode 100644 index 9c9d27728447..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorGetter.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -/** - * @author peng-yongsheng - */ -public interface RemoteDataInstanceCreatorGetter { - RemoteDataRegisterService.RemoteDataInstanceCreator getInstanceCreator( - Integer remoteDataId) throws RemoteDataInstanceCreatorNotFoundException; -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java deleted file mode 100644 index e51fd41f8ee3..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataInstanceCreatorNotFoundException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.remote.RemoteException; - -/** - * @author peng-yongsheng - */ -public class RemoteDataInstanceCreatorNotFoundException extends RemoteException { - public RemoteDataInstanceCreatorNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java deleted file mode 100644 index 20ee5362004b..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataMappingIdNotFoundException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.remote.RemoteException; - -/** - * @author peng-yongsheng - */ -public class RemoteDataMappingIdNotFoundException extends RemoteException { - public RemoteDataMappingIdNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java deleted file mode 100644 index a511cd240768..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDataRegisterService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface RemoteDataRegisterService extends Service { - void register(Class dataClass, RemoteDataInstanceCreator instanceCreator); - - interface RemoteDataInstanceCreator { - RemoteData createInstance(String id); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDeserializeService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDeserializeService.java deleted file mode 100644 index 7013a56f8296..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteDeserializeService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public interface RemoteDeserializeService { - void deserialize(RemoteData remoteData, Data data); -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSenderService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSenderService.java deleted file mode 100644 index a46e3d27d91f..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSenderService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface RemoteSenderService extends Service { - Mode send(int graphId, int nodeId, Data data, Selector selector); - - enum Mode { - Remote, Local - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSerializeService.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSerializeService.java deleted file mode 100644 index 5affcaba994e..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/RemoteSerializeService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public interface RemoteSerializeService { - Builder serialize(Data data); -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/Selector.java b/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/Selector.java deleted file mode 100644 index c1c798f6d5c8..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/java/org/skywalking/apm/collector/remote/service/Selector.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.service; - -/** - * @author peng-yongsheng - */ -public enum Selector { - HashCode, Rolling, ForeverFirst -} diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..d28444c22864 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.remote.RemoteModule diff --git a/apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 114b3e2314f1..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.remote.RemoteModule diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java new file mode 100644 index 000000000000..a7b86d3adfc5 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.grpc.manager.GRPCManagerModule; +import org.apache.skywalking.apm.collector.remote.RemoteModule; +import org.apache.skywalking.apm.collector.remote.grpc.handler.RemoteCommonServiceHandler; +import org.apache.skywalking.apm.collector.remote.service.CommonRemoteDataRegisterService; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataRegisterService; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; +import org.apache.skywalking.apm.collector.remote.grpc.service.GRPCRemoteSenderService; + +/** + * @author peng-yongsheng + */ +public class RemoteModuleGRPCProvider extends ModuleProvider { + + public static final String NAME = "gRPC"; + + private static final String HOST = "host"; + private static final String PORT = "port"; + private static final String CHANNEL_SIZE = "channel_size"; + private static final String BUFFER_SIZE = "buffer_size"; + + private GRPCRemoteSenderService remoteSenderService; + private CommonRemoteDataRegisterService remoteDataRegisterService; + + @Override public String name() { + return NAME; + } + + @Override public Class module() { + return RemoteModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + String host = config.getProperty(HOST); + Integer port = (Integer)config.get(PORT); + Integer channelSize = (Integer)config.getOrDefault(CHANNEL_SIZE, 5); + Integer bufferSize = (Integer)config.getOrDefault(BUFFER_SIZE, 1000); + + remoteDataRegisterService = new CommonRemoteDataRegisterService(); + remoteSenderService = new GRPCRemoteSenderService(host, port, channelSize, bufferSize, remoteDataRegisterService); + this.registerServiceImplementation(RemoteSenderService.class, remoteSenderService); + this.registerServiceImplementation(RemoteDataRegisterService.class, remoteDataRegisterService); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + String host = config.getProperty(HOST); + Integer port = (Integer)config.get(PORT); + + GRPCManagerService managerService = getManager().find(GRPCManagerModule.NAME).getService(GRPCManagerService.class); + Server gRPCServer = managerService.createIfAbsent(host, port); + gRPCServer.addHandler(new RemoteCommonServiceHandler(remoteDataRegisterService)); + + ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); + moduleRegisterService.register(RemoteModule.NAME, this.name(), new RemoteModuleGRPCRegistration(host, port)); + + ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); + moduleListenerService.addListener(remoteSenderService); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {ClusterModule.NAME, GRPCManagerModule.NAME}; + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java new file mode 100644 index 000000000000..198e432fe464 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc; + +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; +import org.apache.skywalking.apm.collector.core.util.Const; + +/** + * @author peng-yongsheng + */ +public class RemoteModuleGRPCRegistration extends ModuleRegistration { + + private final String host; + private final int port; + + public RemoteModuleGRPCRegistration(String host, int port) { + this.host = host; + this.port = port; + } + + @Override public Value buildValue() { + return new Value(host, port, Const.EMPTY_STRING); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java new file mode 100644 index 000000000000..9aa3ed520abe --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.handler; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.graph.GraphManager; +import org.apache.skywalking.apm.collector.core.graph.Next; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.remote.grpc.service.GRPCRemoteDeserializeService; +import org.apache.skywalking.apm.collector.remote.grpc.proto.Empty; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteCommonServiceGrpc; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteData; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteMessage; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataInstanceCreatorGetter; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataInstanceCreatorNotFoundException; +import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class RemoteCommonServiceHandler extends RemoteCommonServiceGrpc.RemoteCommonServiceImplBase implements GRPCHandler { + + private final Logger logger = LoggerFactory.getLogger(RemoteCommonServiceHandler.class); + + private final RemoteDataInstanceCreatorGetter instanceCreatorGetter; + private final GRPCRemoteDeserializeService service; + + public RemoteCommonServiceHandler(RemoteDataInstanceCreatorGetter instanceCreatorGetter) { + this.instanceCreatorGetter = instanceCreatorGetter; + this.service = new GRPCRemoteDeserializeService(); + } + + @SuppressWarnings("unchecked") + @Override public StreamObserver call(StreamObserver responseObserver) { + return new StreamObserver() { + @Override public void onNext(RemoteMessage message) { + int graphId = message.getGraphId(); + int nodeId = message.getNodeId(); + int remoteDataId = message.getRemoteDataId(); + RemoteData remoteData = message.getRemoteData(); + + try { + Data output = instanceCreatorGetter.getInstanceCreator(remoteDataId).createInstance(Const.EMPTY_STRING); + service.deserialize(remoteData, output); + Next next = GraphManager.INSTANCE.findGraph(graphId).toFinder().findNext(nodeId); + next.execute(output); + } catch (RemoteDataInstanceCreatorNotFoundException e) { + logger.error(e.getMessage(), e); + } + } + + @Override public void onError(Throwable throwable) { + logger.error(throwable.getMessage(), throwable); + } + + @Override public void onCompleted() { + responseObserver.onNext(Empty.newBuilder().build()); + responseObserver.onCompleted(); + } + }; + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java new file mode 100644 index 000000000000..20927334f693 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service; + +import io.grpc.stub.StreamObserver; +import java.util.List; +import org.apache.skywalking.apm.collector.client.grpc.GRPCClient; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.grpc.proto.Empty; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteCommonServiceGrpc; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteMessage; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataIDGetter; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataMappingIdNotFoundException; +import org.apache.skywalking.apm.commons.datacarrier.DataCarrier; +import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; +import org.apache.skywalking.apm.commons.datacarrier.consumer.IConsumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GRPCRemoteClient implements RemoteClient { + + private final Logger logger = LoggerFactory.getLogger(GRPCRemoteClient.class); + + private final GRPCRemoteSerializeService service; + private final GRPCClient client; + private final DataCarrier carrier; + private final String address; + private final RemoteDataIDGetter remoteDataIDGetter; + + GRPCRemoteClient(GRPCClient client, RemoteDataIDGetter remoteDataIDGetter, int channelSize, int bufferSize) { + this.address = client.toString(); + this.client = client; + this.service = new GRPCRemoteSerializeService(); + this.remoteDataIDGetter = remoteDataIDGetter; + this.carrier = new DataCarrier<>(channelSize, bufferSize); + this.carrier.setBufferStrategy(BufferStrategy.BLOCKING); + this.carrier.consume(new RemoteMessageConsumer(), 1); + } + + @Override public final String getAddress() { + return this.address; + } + + @Override public void push(int graphId, int nodeId, Data data) { + try { + Integer remoteDataId = remoteDataIDGetter.getRemoteDataId(data.getClass()); + RemoteMessage.Builder builder = RemoteMessage.newBuilder(); + builder.setGraphId(graphId); + builder.setNodeId(nodeId); + builder.setRemoteDataId(remoteDataId); + builder.setRemoteData(service.serialize(data)); + + this.carrier.produce(builder.build()); + logger.debug("put remote message into queue, id: {}", data.getId()); + } catch (RemoteDataMappingIdNotFoundException e) { + logger.error(e.getMessage(), e); + } + } + + class RemoteMessageConsumer implements IConsumer { + @Override public void init() { + } + + @Override public void consume(List remoteMessages) { + StreamObserver streamObserver = createStreamObserver(); + for (RemoteMessage remoteMessage : remoteMessages) { + streamObserver.onNext(remoteMessage); + } + streamObserver.onCompleted(); + } + + @Override public void onError(List remoteMessages, Throwable t) { + logger.error(t.getMessage(), t); + } + + @Override public void onExit() { + } + } + + private StreamObserver createStreamObserver() { + RemoteCommonServiceGrpc.RemoteCommonServiceStub stub = RemoteCommonServiceGrpc.newStub(client.getChannel()); + + StreamStatus status = new StreamStatus(false); + return stub.call(new StreamObserver() { + @Override public void onNext(Empty empty) { + } + + @Override public void onError(Throwable throwable) { + logger.error(throwable.getMessage(), throwable); + } + + @Override public void onCompleted() { + status.finished(); + } + }); + } + + class StreamStatus { + + private final Logger logger = LoggerFactory.getLogger(StreamStatus.class); + + private volatile boolean status; + + StreamStatus(boolean status) { + this.status = status; + } + + public boolean isFinish() { + return status; + } + + void finished() { + this.status = true; + } + + /** + * @param maxTimeout max wait time, milliseconds. + */ + public void wait4Finish(long maxTimeout) { + long time = 0; + while (!status) { + if (time > maxTimeout) { + break; + } + try2Sleep(5); + time += 5; + } + } + + /** + * Try to sleep, and ignore the {@link InterruptedException} + * + * @param millis the length of time to sleep in milliseconds + */ + private void try2Sleep(long millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + logger.error(e.getMessage(), e); + } + } + } + + @Override public boolean equals(String address) { + return this.address.equals(address); + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + GRPCRemoteClient client = (GRPCRemoteClient)o; + + return address != null ? address.equals(client.address) : client.address == null; + } + + @Override public int hashCode() { + return address != null ? address.hashCode() : 0; + } + + @Override public int compareTo(RemoteClient o) { + return this.address.compareTo(o.getAddress()); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java new file mode 100644 index 000000000000..b3d64ed37ed2 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service; + +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.client.grpc.GRPCClient; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; +import org.apache.skywalking.apm.collector.remote.service.RemoteClientService; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataIDGetter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GRPCRemoteClientService implements RemoteClientService { + + private final Logger logger = LoggerFactory.getLogger(GRPCRemoteClientService.class); + + private final RemoteDataIDGetter remoteDataIDGetter; + + GRPCRemoteClientService(RemoteDataIDGetter remoteDataIDGetter) { + this.remoteDataIDGetter = remoteDataIDGetter; + } + + @Override public RemoteClient create(String host, int port, int channelSize, int bufferSize) { + GRPCClient client = new GRPCClient(host, port); + try { + client.initialize(); + } catch (ClientException e) { + logger.error(e.getMessage(), e); + } + return new GRPCRemoteClient(client, remoteDataIDGetter, channelSize, bufferSize); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java new file mode 100644 index 000000000000..97d222e7a8c0 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service; + +import org.apache.skywalking.apm.collector.remote.service.RemoteDeserializeService; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteData; + +/** + * @author peng-yongsheng + */ +public class GRPCRemoteDeserializeService implements RemoteDeserializeService { + + @Override public void deserialize(RemoteData remoteData, Data data) { + for (int i = 0; i < remoteData.getDataStringsCount(); i++) { + data.setDataString(i, remoteData.getDataStrings(i)); + } + for (int i = 0; i < remoteData.getDataIntegersCount(); i++) { + data.setDataInteger(i, remoteData.getDataIntegers(i)); + } + for (int i = 0; i < remoteData.getDataLongsCount(); i++) { + data.setDataLong(i, remoteData.getDataLongs(i)); + } + for (int i = 0; i < remoteData.getDataBooleansCount(); i++) { + data.setDataBoolean(i, remoteData.getDataBooleans(i)); + } + for (int i = 0; i < remoteData.getDataDoublesCount(); i++) { + data.setDataDouble(i, remoteData.getDataDoubles(i)); + } + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java new file mode 100644 index 000000000000..49bf25afbea6 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.RemoteModule; +import org.apache.skywalking.apm.collector.remote.grpc.RemoteModuleGRPCProvider; +import org.apache.skywalking.apm.collector.remote.grpc.service.selector.ForeverFirstSelector; +import org.apache.skywalking.apm.collector.remote.grpc.service.selector.HashCodeSelector; +import org.apache.skywalking.apm.collector.remote.grpc.service.selector.RollingSelector; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; +import org.apache.skywalking.apm.collector.remote.service.RemoteDataIDGetter; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.apache.skywalking.apm.collector.remote.service.Selector; + +/** + * @author peng-yongsheng + */ +public class GRPCRemoteSenderService extends ClusterModuleListener implements RemoteSenderService { + + private static final String PATH = "/" + RemoteModule.NAME + "/" + RemoteModuleGRPCProvider.NAME; + private final GRPCRemoteClientService service; + private List remoteClients; + private final String selfAddress; + private final HashCodeSelector hashCodeSelector; + private final ForeverFirstSelector foreverFirstSelector; + private final RollingSelector rollingSelector; + private final int channelSize; + private final int bufferSize; + + @Override public Mode send(int graphId, int nodeId, Data data, Selector selector) { + RemoteClient remoteClient; + switch (selector) { + case HashCode: + remoteClient = hashCodeSelector.select(remoteClients, data); + return sendToRemoteWhenNotSelf(remoteClient, graphId, nodeId, data); + case Rolling: + remoteClient = rollingSelector.select(remoteClients, data); + return sendToRemoteWhenNotSelf(remoteClient, graphId, nodeId, data); + case ForeverFirst: + remoteClient = foreverFirstSelector.select(remoteClients, data); + return sendToRemoteWhenNotSelf(remoteClient, graphId, nodeId, data); + } + throw new UnexpectedException("Selector not match, Just support hash, rolling, forever first selector."); + } + + private Mode sendToRemoteWhenNotSelf(RemoteClient remoteClient, int graphId, int nodeId, Data data) { + if (remoteClient.equals(selfAddress)) { + return Mode.Local; + } else { + remoteClient.push(graphId, nodeId, data); + return Mode.Remote; + } + } + + public GRPCRemoteSenderService(String host, int port, int channelSize, int bufferSize, + RemoteDataIDGetter remoteDataIDGetter) { + this.service = new GRPCRemoteClientService(remoteDataIDGetter); + this.remoteClients = new ArrayList<>(); + this.selfAddress = host + ":" + String.valueOf(port); + this.hashCodeSelector = new HashCodeSelector(); + this.foreverFirstSelector = new ForeverFirstSelector(); + this.rollingSelector = new RollingSelector(); + this.channelSize = channelSize; + this.bufferSize = bufferSize; + } + + @Override public String path() { + return PATH; + } + + @Override public synchronized void serverJoinNotify(String serverAddress) { + List newRemoteClients = new ArrayList<>(); + newRemoteClients.addAll(remoteClients); + + String host = serverAddress.split(":")[0]; + int port = Integer.parseInt(serverAddress.split(":")[1]); + RemoteClient remoteClient = service.create(host, port, channelSize, bufferSize); + newRemoteClients.add(remoteClient); + + Collections.sort(newRemoteClients); + + this.remoteClients = newRemoteClients; + } + + @Override public synchronized void serverQuitNotify(String serverAddress) { + List newRemoteClients = new ArrayList<>(); + newRemoteClients.addAll(remoteClients); + + for (int i = newRemoteClients.size() - 1; i >= 0; i--) { + RemoteClient remoteClient = newRemoteClients.get(i); + if (remoteClient.equals(serverAddress)) { + newRemoteClients.remove(i); + } + } + + this.remoteClients = newRemoteClients; + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java new file mode 100644 index 000000000000..bc22445b3fe2 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.grpc.proto.RemoteData; +import org.apache.skywalking.apm.collector.remote.service.RemoteSerializeService; + +/** + * @author peng-yongsheng + */ +public class GRPCRemoteSerializeService implements RemoteSerializeService { + + @Override public RemoteData.Builder serialize(Data data) { + RemoteData.Builder builder = RemoteData.newBuilder(); + for (int i = 0; i < data.getDataStringsCount(); i++) { + builder.addDataStrings(data.getDataString(i)); + } + for (int i = 0; i < data.getDataIntegersCount(); i++) { + builder.addDataIntegers(data.getDataInteger(i)); + } + for (int i = 0; i < data.getDataLongsCount(); i++) { + builder.addDataLongs(data.getDataLong(i)); + } + for (int i = 0; i < data.getDataBooleansCount(); i++) { + builder.addDataBooleans(data.getDataBoolean(i)); + } + for (int i = 0; i < data.getDataDoublesCount(); i++) { + builder.addDataDoubles(data.getDataDouble(i)); + } + for (int i = 0; i < data.getDataBytesCount(); i++) { +// builder.addDataBytes(ByteString.copyFrom(data.getDataBytes(i))); + } + return builder; + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java new file mode 100644 index 000000000000..63a263e6e4a2 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service.selector; + +import java.util.List; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ForeverFirstSelector implements RemoteClientSelector { + + private final Logger logger = LoggerFactory.getLogger(ForeverFirstSelector.class); + + @Override public RemoteClient select(List clients, Data message) { + logger.debug("clients size: {}", clients.size()); + return clients.get(0); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java new file mode 100644 index 000000000000..a31fd2068ea5 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service.selector; + +import java.util.List; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; + +/** + * @author peng-yongsheng + */ +public class HashCodeSelector implements RemoteClientSelector { + + @Override public RemoteClient select(List clients, Data message) { + int size = clients.size(); + int selectIndex = Math.abs(message.getHashCode()) % size; + return clients.get(selectIndex); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java new file mode 100644 index 000000000000..f6d59e2fef76 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service.selector; + +import java.util.List; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; + +/** + * @author peng-yongsheng + */ +public interface RemoteClientSelector { + RemoteClient select(List clients, Data message); +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java new file mode 100644 index 000000000000..064bb2dafb17 --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.remote.grpc.service.selector; + +import java.util.List; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.service.RemoteClient; + +/** + * @author peng-yongsheng + */ +public class RollingSelector implements RemoteClientSelector { + + private int index = 0; + + @Override public RemoteClient select(List clients, Data message) { + int size = clients.size(); + index++; + int selectIndex = Math.abs(index) % size; + return clients.get(selectIndex); + } +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java deleted file mode 100644 index eb9bad86c183..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCProvider.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc; - -import java.util.Properties; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.grpc.manager.GRPCManagerModule; -import org.skywalking.apm.collector.grpc.manager.service.GRPCManagerService; -import org.skywalking.apm.collector.remote.RemoteModule; -import org.skywalking.apm.collector.remote.grpc.handler.RemoteCommonServiceHandler; -import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteSenderService; -import org.skywalking.apm.collector.remote.service.CommonRemoteDataRegisterService; -import org.skywalking.apm.collector.remote.service.RemoteDataRegisterService; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.server.Server; - -/** - * @author peng-yongsheng - */ -public class RemoteModuleGRPCProvider extends ModuleProvider { - - public static final String NAME = "gRPC"; - - private static final String HOST = "host"; - private static final String PORT = "port"; - private static final String CHANNEL_SIZE = "channel_size"; - private static final String BUFFER_SIZE = "buffer_size"; - - private GRPCRemoteSenderService remoteSenderService; - private CommonRemoteDataRegisterService remoteDataRegisterService; - - @Override public String name() { - return NAME; - } - - @Override public Class module() { - return RemoteModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - String host = config.getProperty(HOST); - Integer port = (Integer)config.get(PORT); - Integer channelSize = (Integer)config.getOrDefault(CHANNEL_SIZE, 5); - Integer bufferSize = (Integer)config.getOrDefault(BUFFER_SIZE, 1000); - - remoteDataRegisterService = new CommonRemoteDataRegisterService(); - remoteSenderService = new GRPCRemoteSenderService(host, port, channelSize, bufferSize, remoteDataRegisterService); - this.registerServiceImplementation(RemoteSenderService.class, remoteSenderService); - this.registerServiceImplementation(RemoteDataRegisterService.class, remoteDataRegisterService); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - String host = config.getProperty(HOST); - Integer port = (Integer)config.get(PORT); - - GRPCManagerService managerService = getManager().find(GRPCManagerModule.NAME).getService(GRPCManagerService.class); - Server gRPCServer = managerService.createIfAbsent(host, port); - gRPCServer.addHandler(new RemoteCommonServiceHandler(remoteDataRegisterService)); - - ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); - moduleRegisterService.register(RemoteModule.NAME, this.name(), new RemoteModuleGRPCRegistration(host, port)); - - ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); - moduleListenerService.addListener(remoteSenderService); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {ClusterModule.NAME, GRPCManagerModule.NAME}; - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java deleted file mode 100644 index 9f6c9c605ac5..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/RemoteModuleGRPCRegistration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.core.util.Const; - -/** - * @author peng-yongsheng - */ -public class RemoteModuleGRPCRegistration extends ModuleRegistration { - - private final String host; - private final int port; - - public RemoteModuleGRPCRegistration(String host, int port) { - this.host = host; - this.port = port; - } - - @Override public Value buildValue() { - return new Value(host, port, Const.EMPTY_STRING); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java deleted file mode 100644 index b6d1d3ea8b2e..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/handler/RemoteCommonServiceHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.handler; - -import io.grpc.stub.StreamObserver; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.graph.GraphManager; -import org.skywalking.apm.collector.core.graph.Next; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.remote.grpc.proto.Empty; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteCommonServiceGrpc; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteData; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteMessage; -import org.skywalking.apm.collector.remote.grpc.service.GRPCRemoteDeserializeService; -import org.skywalking.apm.collector.remote.service.RemoteDataInstanceCreatorGetter; -import org.skywalking.apm.collector.remote.service.RemoteDataInstanceCreatorNotFoundException; -import org.skywalking.apm.collector.server.grpc.GRPCHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class RemoteCommonServiceHandler extends RemoteCommonServiceGrpc.RemoteCommonServiceImplBase implements GRPCHandler { - - private final Logger logger = LoggerFactory.getLogger(RemoteCommonServiceHandler.class); - - private final RemoteDataInstanceCreatorGetter instanceCreatorGetter; - private final GRPCRemoteDeserializeService service; - - public RemoteCommonServiceHandler(RemoteDataInstanceCreatorGetter instanceCreatorGetter) { - this.instanceCreatorGetter = instanceCreatorGetter; - this.service = new GRPCRemoteDeserializeService(); - } - - @SuppressWarnings("unchecked") - @Override public StreamObserver call(StreamObserver responseObserver) { - return new StreamObserver() { - @Override public void onNext(RemoteMessage message) { - int graphId = message.getGraphId(); - int nodeId = message.getNodeId(); - int remoteDataId = message.getRemoteDataId(); - RemoteData remoteData = message.getRemoteData(); - - try { - Data output = instanceCreatorGetter.getInstanceCreator(remoteDataId).createInstance(Const.EMPTY_STRING); - service.deserialize(remoteData, output); - Next next = GraphManager.INSTANCE.findGraph(graphId).toFinder().findNext(nodeId); - next.execute(output); - } catch (RemoteDataInstanceCreatorNotFoundException e) { - logger.error(e.getMessage(), e); - } - } - - @Override public void onError(Throwable throwable) { - logger.error(throwable.getMessage(), throwable); - } - - @Override public void onCompleted() { - responseObserver.onNext(Empty.newBuilder().build()); - responseObserver.onCompleted(); - } - }; - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java deleted file mode 100644 index 68f122bf290b..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClient.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service; - -import io.grpc.stub.StreamObserver; -import java.util.List; -import org.skywalking.apm.collector.client.grpc.GRPCClient; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.grpc.proto.Empty; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteCommonServiceGrpc; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteMessage; -import org.skywalking.apm.collector.remote.service.RemoteClient; -import org.skywalking.apm.collector.remote.service.RemoteDataIDGetter; -import org.skywalking.apm.collector.remote.service.RemoteDataMappingIdNotFoundException; -import org.skywalking.apm.commons.datacarrier.DataCarrier; -import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; -import org.skywalking.apm.commons.datacarrier.consumer.IConsumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GRPCRemoteClient implements RemoteClient { - - private final Logger logger = LoggerFactory.getLogger(GRPCRemoteClient.class); - - private final GRPCRemoteSerializeService service; - private final GRPCClient client; - private final DataCarrier carrier; - private final String address; - private final RemoteDataIDGetter remoteDataIDGetter; - - GRPCRemoteClient(GRPCClient client, RemoteDataIDGetter remoteDataIDGetter, int channelSize, int bufferSize) { - this.address = client.toString(); - this.client = client; - this.service = new GRPCRemoteSerializeService(); - this.remoteDataIDGetter = remoteDataIDGetter; - this.carrier = new DataCarrier<>(channelSize, bufferSize); - this.carrier.setBufferStrategy(BufferStrategy.BLOCKING); - this.carrier.consume(new RemoteMessageConsumer(), 1); - } - - @Override public final String getAddress() { - return this.address; - } - - @Override public void push(int graphId, int nodeId, Data data) { - try { - Integer remoteDataId = remoteDataIDGetter.getRemoteDataId(data.getClass()); - RemoteMessage.Builder builder = RemoteMessage.newBuilder(); - builder.setGraphId(graphId); - builder.setNodeId(nodeId); - builder.setRemoteDataId(remoteDataId); - builder.setRemoteData(service.serialize(data)); - - this.carrier.produce(builder.build()); - logger.debug("put remote message into queue, id: {}", data.getId()); - } catch (RemoteDataMappingIdNotFoundException e) { - logger.error(e.getMessage(), e); - } - } - - class RemoteMessageConsumer implements IConsumer { - @Override public void init() { - } - - @Override public void consume(List remoteMessages) { - StreamObserver streamObserver = createStreamObserver(); - for (RemoteMessage remoteMessage : remoteMessages) { - streamObserver.onNext(remoteMessage); - } - streamObserver.onCompleted(); - } - - @Override public void onError(List remoteMessages, Throwable t) { - logger.error(t.getMessage(), t); - } - - @Override public void onExit() { - } - } - - private StreamObserver createStreamObserver() { - RemoteCommonServiceGrpc.RemoteCommonServiceStub stub = RemoteCommonServiceGrpc.newStub(client.getChannel()); - - StreamStatus status = new StreamStatus(false); - return stub.call(new StreamObserver() { - @Override public void onNext(Empty empty) { - } - - @Override public void onError(Throwable throwable) { - logger.error(throwable.getMessage(), throwable); - } - - @Override public void onCompleted() { - status.finished(); - } - }); - } - - class StreamStatus { - - private final Logger logger = LoggerFactory.getLogger(StreamStatus.class); - - private volatile boolean status; - - StreamStatus(boolean status) { - this.status = status; - } - - public boolean isFinish() { - return status; - } - - void finished() { - this.status = true; - } - - /** - * @param maxTimeout max wait time, milliseconds. - */ - public void wait4Finish(long maxTimeout) { - long time = 0; - while (!status) { - if (time > maxTimeout) { - break; - } - try2Sleep(5); - time += 5; - } - } - - /** - * Try to sleep, and ignore the {@link InterruptedException} - * - * @param millis the length of time to sleep in milliseconds - */ - private void try2Sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - logger.error(e.getMessage(), e); - } - } - } - - @Override public boolean equals(String address) { - return this.address.equals(address); - } - - @Override public int compareTo(RemoteClient o) { - return this.address.compareTo(o.getAddress()); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java deleted file mode 100644 index 7739acdedf97..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteClientService.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service; - -import org.skywalking.apm.collector.client.ClientException; -import org.skywalking.apm.collector.client.grpc.GRPCClient; -import org.skywalking.apm.collector.remote.service.RemoteClient; -import org.skywalking.apm.collector.remote.service.RemoteClientService; -import org.skywalking.apm.collector.remote.service.RemoteDataIDGetter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GRPCRemoteClientService implements RemoteClientService { - - private final Logger logger = LoggerFactory.getLogger(GRPCRemoteClientService.class); - - private final RemoteDataIDGetter remoteDataIDGetter; - - GRPCRemoteClientService(RemoteDataIDGetter remoteDataIDGetter) { - this.remoteDataIDGetter = remoteDataIDGetter; - } - - @Override public RemoteClient create(String host, int port, int channelSize, int bufferSize) { - GRPCClient client = new GRPCClient(host, port); - try { - client.initialize(); - } catch (ClientException e) { - logger.error(e.getMessage(), e); - } - return new GRPCRemoteClient(client, remoteDataIDGetter, channelSize, bufferSize); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java deleted file mode 100644 index 0ef2a20c78ba..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteDeserializeService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteData; -import org.skywalking.apm.collector.remote.service.RemoteDeserializeService; - -/** - * @author peng-yongsheng - */ -public class GRPCRemoteDeserializeService implements RemoteDeserializeService { - - @Override public void deserialize(RemoteData remoteData, Data data) { - for (int i = 0; i < remoteData.getDataStringsCount(); i++) { - data.setDataString(i, remoteData.getDataStrings(i)); - } - for (int i = 0; i < remoteData.getDataIntegersCount(); i++) { - data.setDataInteger(i, remoteData.getDataIntegers(i)); - } - for (int i = 0; i < remoteData.getDataLongsCount(); i++) { - data.setDataLong(i, remoteData.getDataLongs(i)); - } - for (int i = 0; i < remoteData.getDataBooleansCount(); i++) { - data.setDataBoolean(i, remoteData.getDataBooleans(i)); - } - for (int i = 0; i < remoteData.getDataDoublesCount(); i++) { - data.setDataDouble(i, remoteData.getDataDoubles(i)); - } - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java deleted file mode 100644 index 39d954a984e0..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSenderService.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.RemoteModule; -import org.skywalking.apm.collector.remote.grpc.RemoteModuleGRPCProvider; -import org.skywalking.apm.collector.remote.grpc.service.selector.ForeverFirstSelector; -import org.skywalking.apm.collector.remote.grpc.service.selector.HashCodeSelector; -import org.skywalking.apm.collector.remote.grpc.service.selector.RollingSelector; -import org.skywalking.apm.collector.remote.service.RemoteClient; -import org.skywalking.apm.collector.remote.service.RemoteDataIDGetter; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.skywalking.apm.collector.remote.service.Selector; - -/** - * @author peng-yongsheng - */ -public class GRPCRemoteSenderService extends ClusterModuleListener implements RemoteSenderService { - - private static final String PATH = "/" + RemoteModule.NAME + "/" + RemoteModuleGRPCProvider.NAME; - private final GRPCRemoteClientService service; - private List remoteClients; - private final String selfAddress; - private final HashCodeSelector hashCodeSelector; - private final ForeverFirstSelector foreverFirstSelector; - private final RollingSelector rollingSelector; - private final int channelSize; - private final int bufferSize; - - @Override public Mode send(int graphId, int nodeId, Data data, Selector selector) { - RemoteClient remoteClient; - switch (selector) { - case HashCode: - remoteClient = hashCodeSelector.select(remoteClients, data); - return sendToRemoteWhenNotSelf(remoteClient, graphId, nodeId, data); - case Rolling: - remoteClient = rollingSelector.select(remoteClients, data); - return sendToRemoteWhenNotSelf(remoteClient, graphId, nodeId, data); - case ForeverFirst: - remoteClient = foreverFirstSelector.select(remoteClients, data); - return sendToRemoteWhenNotSelf(remoteClient, graphId, nodeId, data); - } - throw new UnexpectedException("Selector not match, Just support hash, rolling, forever first selector."); - } - - private Mode sendToRemoteWhenNotSelf(RemoteClient remoteClient, int graphId, int nodeId, Data data) { - if (remoteClient.equals(selfAddress)) { - return Mode.Local; - } else { - remoteClient.push(graphId, nodeId, data); - return Mode.Remote; - } - } - - public GRPCRemoteSenderService(String host, int port, int channelSize, int bufferSize, - RemoteDataIDGetter remoteDataIDGetter) { - this.service = new GRPCRemoteClientService(remoteDataIDGetter); - this.remoteClients = new ArrayList<>(); - this.selfAddress = host + ":" + String.valueOf(port); - this.hashCodeSelector = new HashCodeSelector(); - this.foreverFirstSelector = new ForeverFirstSelector(); - this.rollingSelector = new RollingSelector(); - this.channelSize = channelSize; - this.bufferSize = bufferSize; - } - - @Override public String path() { - return PATH; - } - - @Override public synchronized void serverJoinNotify(String serverAddress) { - List newRemoteClients = new ArrayList<>(); - newRemoteClients.addAll(remoteClients); - - String host = serverAddress.split(":")[0]; - int port = Integer.parseInt(serverAddress.split(":")[1]); - RemoteClient remoteClient = service.create(host, port, channelSize, bufferSize); - newRemoteClients.add(remoteClient); - - Collections.sort(newRemoteClients); - - this.remoteClients = newRemoteClients; - } - - @Override public synchronized void serverQuitNotify(String serverAddress) { - List newRemoteClients = new ArrayList<>(); - newRemoteClients.addAll(remoteClients); - - for (int i = newRemoteClients.size() - 1; i >= 0; i--) { - RemoteClient remoteClient = newRemoteClients.get(i); - if (remoteClient.equals(serverAddress)) { - newRemoteClients.remove(i); - } - } - - this.remoteClients = newRemoteClients; - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java deleted file mode 100644 index 8fe6cb35930d..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/GRPCRemoteSerializeService.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.grpc.proto.RemoteData; -import org.skywalking.apm.collector.remote.service.RemoteSerializeService; - -/** - * @author peng-yongsheng - */ -public class GRPCRemoteSerializeService implements RemoteSerializeService { - - @Override public RemoteData.Builder serialize(Data data) { - RemoteData.Builder builder = RemoteData.newBuilder(); - for (int i = 0; i < data.getDataStringsCount(); i++) { - builder.addDataStrings(data.getDataString(i)); - } - for (int i = 0; i < data.getDataIntegersCount(); i++) { - builder.addDataIntegers(data.getDataInteger(i)); - } - for (int i = 0; i < data.getDataLongsCount(); i++) { - builder.addDataLongs(data.getDataLong(i)); - } - for (int i = 0; i < data.getDataBooleansCount(); i++) { - builder.addDataBooleans(data.getDataBoolean(i)); - } - for (int i = 0; i < data.getDataDoublesCount(); i++) { - builder.addDataDoubles(data.getDataDouble(i)); - } - for (int i = 0; i < data.getDataBytesCount(); i++) { -// builder.addDataBytes(ByteString.copyFrom(data.getDataBytes(i))); - } - return builder; - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java deleted file mode 100644 index d5d52ee0f115..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/ForeverFirstSelector.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service.selector; - -import java.util.List; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.service.RemoteClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ForeverFirstSelector implements RemoteClientSelector { - - private final Logger logger = LoggerFactory.getLogger(ForeverFirstSelector.class); - - @Override public RemoteClient select(List clients, Data message) { - logger.debug("clients size: {}", clients.size()); - return clients.get(0); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java deleted file mode 100644 index cb5ecd935094..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/HashCodeSelector.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service.selector; - -import java.util.List; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.service.RemoteClient; - -/** - * @author peng-yongsheng - */ -public class HashCodeSelector implements RemoteClientSelector { - - @Override public RemoteClient select(List clients, Data message) { - int size = clients.size(); - int selectIndex = Math.abs(message.getHashCode()) % size; - return clients.get(selectIndex); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java deleted file mode 100644 index c969c5db4298..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RemoteClientSelector.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service.selector; - -import java.util.List; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.service.RemoteClient; - -/** - * @author peng-yongsheng - */ -public interface RemoteClientSelector { - RemoteClient select(List clients, Data message); -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java deleted file mode 100644 index c1c1058fdf51..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/java/org/skywalking/apm/collector/remote/grpc/service/selector/RollingSelector.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.remote.grpc.service.selector; - -import java.util.List; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.service.RemoteClient; - -/** - * @author peng-yongsheng - */ -public class RollingSelector implements RemoteClientSelector { - - private int index = 0; - - @Override public RemoteClient select(List clients, Data message) { - int size = clients.size(); - index++; - int selectIndex = Math.abs(index) % size; - return clients.get(selectIndex); - } -} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/proto/RemoteCommonService.proto b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/proto/RemoteCommonService.proto index 7e5077631607..2d831481dd6e 100644 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/proto/RemoteCommonService.proto +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/proto/RemoteCommonService.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.collector.remote.grpc.proto"; +option java_package = "org.apache.skywalking.apm.collector.remote.grpc.proto"; service RemoteCommonService { rpc call (stream RemoteMessage) returns (Empty) { @@ -25,4 +25,4 @@ message RemoteData { } message Empty { -} \ No newline at end of file +} diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..42e51b95e01e --- /dev/null +++ b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.remote.grpc.RemoteModuleGRPCProvider diff --git a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 58668b35bfd6..000000000000 --- a/apm-collector/apm-collector-remote/collector-remote-grpc-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.remote.grpc.RemoteModuleGRPCProvider diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageException.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageException.java new file mode 100644 index 000000000000..c8cab5d0c08b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageException.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * @author peng-yongsheng + */ +public abstract class StorageException extends CollectorException { + + public StorageException(String message) { + super(message); + } + + public StorageException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstallException.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstallException.java new file mode 100644 index 000000000000..ab204f845477 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstallException.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage; + +/** + * @author peng-yongsheng + */ +public class StorageInstallException extends StorageException { + + public StorageInstallException(String message) { + super(message); + } + + public StorageInstallException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstaller.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstaller.java new file mode 100644 index 000000000000..f827774899ff --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageInstaller.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage; + +import java.util.List; +import org.apache.skywalking.apm.collector.core.data.StorageDefineLoader; +import org.apache.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.core.define.DefineException; +import org.apache.skywalking.apm.collector.core.data.TableDefine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public abstract class StorageInstaller { + + private final Logger logger = LoggerFactory.getLogger(StorageInstaller.class); + + public final void install(Client client) throws StorageException { + StorageDefineLoader defineLoader = new StorageDefineLoader(); + try { + List tableDefines = defineLoader.load(); + defineFilter(tableDefines); + Boolean debug = System.getProperty("debug") != null; + + for (TableDefine tableDefine : tableDefines) { + tableDefine.initialize(); + if (!isExists(client, tableDefine)) { + logger.info("table: {} not exists", tableDefine.getName()); + createTable(client, tableDefine); + } else if (debug) { + logger.info("table: {} exists", tableDefine.getName()); + deleteTable(client, tableDefine); + createTable(client, tableDefine); + } + } + } catch (DefineException e) { + throw new StorageInstallException(e.getMessage(), e); + } + } + + protected abstract void defineFilter(List tableDefines); + + protected abstract boolean isExists(Client client, TableDefine tableDefine) throws StorageException; + + protected abstract boolean deleteTable(Client client, TableDefine tableDefine) throws StorageException; + + protected abstract boolean createTable(Client client, TableDefine tableDefine) throws StorageException; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java new file mode 100644 index 000000000000..db5ecebbeaa1 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public class StorageModule extends Module { + + public static final String NAME = "storage"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + List classes = new ArrayList<>(); + classes.add(IBatchDAO.class); + + addCacheDAO(classes); + addRegisterDAO(classes); + addPersistenceDAO(classes); + addUiDAO(classes); + addAlertingDAO(classes); + + return classes.toArray(new Class[] {}); + } + + private void addCacheDAO(List classes) { + classes.add(IApplicationCacheDAO.class); + classes.add(IInstanceCacheDAO.class); + classes.add(IServiceNameCacheDAO.class); + } + + private void addRegisterDAO(List classes) { + classes.add(IApplicationRegisterDAO.class); + classes.add(IInstanceRegisterDAO.class); + classes.add(IServiceNameRegisterDAO.class); + } + + private void addPersistenceDAO(List classes) { + classes.add(ICpuMetricPersistenceDAO.class); + classes.add(IGCMetricPersistenceDAO.class); + classes.add(IMemoryMetricPersistenceDAO.class); + classes.add(IMemoryPoolMetricPersistenceDAO.class); + + classes.add(IGlobalTracePersistenceDAO.class); + classes.add(IInstanceMetricPersistenceDAO.class); + classes.add(IApplicationComponentPersistenceDAO.class); + classes.add(IApplicationMappingPersistenceDAO.class); + classes.add(IApplicationMetricPersistenceDAO.class); + classes.add(IApplicationReferenceMetricPersistenceDAO.class); + classes.add(ISegmentCostPersistenceDAO.class); + classes.add(ISegmentPersistenceDAO.class); + classes.add(IServiceEntryPersistenceDAO.class); + classes.add(IServiceMetricPersistenceDAO.class); + classes.add(IServiceReferenceMetricPersistenceDAO.class); + + classes.add(IInstanceHeartBeatPersistenceDAO.class); + } + + private void addUiDAO(List classes) { + classes.add(IInstanceUIDAO.class); + + classes.add(ICpuMetricUIDAO.class); + classes.add(IGCMetricUIDAO.class); + classes.add(IMemoryMetricUIDAO.class); + classes.add(IMemoryPoolMetricUIDAO.class); + + classes.add(IGlobalTraceUIDAO.class); + classes.add(IInstanceMetricUIDAO.class); + classes.add(IApplicationComponentUIDAO.class); + classes.add(IApplicationMappingUIDAO.class); + classes.add(IApplicationReferenceMetricUIDAO.class); + classes.add(ISegmentCostUIDAO.class); + classes.add(ISegmentUIDAO.class); + classes.add(IServiceEntryUIDAO.class); + classes.add(IServiceReferenceUIDAO.class); + } + + private void addAlertingDAO(List classes) { + classes.add(IAlertingListPersistenceDAO.class); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/AbstractDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/AbstractDAO.java new file mode 100644 index 000000000000..8e092aa4cd05 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/AbstractDAO.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.base.dao; + +import org.apache.skywalking.apm.collector.client.Client; + +/** + * @author peng-yongsheng + */ +public abstract class AbstractDAO implements DAO { + private final C client; + + public AbstractDAO(C client) { + this.client = client; + } + + public final C getClient() { + return client; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/DAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/DAO.java new file mode 100644 index 000000000000..bd799a3e9a39 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/DAO.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.base.dao; + +import org.apache.skywalking.apm.collector.core.module.Service; + +/** + * @author peng-yongsheng + */ +public interface DAO extends Service { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IBatchDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IBatchDAO.java new file mode 100644 index 000000000000..c254422ea20e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IBatchDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.base.dao; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public interface IBatchDAO extends DAO { + void batchPersistence(List batchCollection); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java new file mode 100644 index 000000000000..c87872fd508a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.base.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface IPersistenceDAO extends DAO { + DataImpl get(String id); + + Insert prepareBatchInsert(DataImpl data); + + Update prepareBatchUpdate(DataImpl data); + + void deleteHistory(Long startTimestamp, Long endTimestamp); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/sql/SqlBuilder.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/sql/SqlBuilder.java new file mode 100644 index 000000000000..6728989c1679 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/base/sql/SqlBuilder.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.base.sql; + +import java.text.MessageFormat; +import java.util.List; +import java.util.Set; + +public class SqlBuilder { + public static String buildSql(String sql, Object... args) { + return MessageFormat.format(sql, args); + } + + public static String buildSql(String sql, List args) { + MessageFormat messageFormat = new MessageFormat(sql); + return messageFormat.format(args.toArray(new Object[0])); + } + + public static String buildBatchInsertSql(String tableName, Set columnNames) { + StringBuilder sb = new StringBuilder("insert into "); + sb.append(tableName).append("("); + columnNames.forEach((columnName) -> sb.append(columnName).append(",")); + sb.delete(sb.length() - 1, sb.length()); + sb.append(") values("); + for (int i = 0; i < columnNames.size(); i++) { + sb.append("?,"); + } + sb.delete(sb.length() - 1, sb.length()); + sb.append(")"); + return sb.toString(); + } + + public static String buildBatchUpdateSql(String tableName, Set columnNames, String whereClauseName) { + StringBuilder sb = new StringBuilder("update "); + sb.append(tableName).append(" set "); + columnNames.forEach((columnName) -> sb.append(columnName).append("=?,")); + sb.delete(sb.length() - 1, sb.length()); + sb.append(" where ").append(whereClauseName).append("=?"); + return sb.toString(); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java new file mode 100644 index 000000000000..57133172177f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IAlertingListPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java new file mode 100644 index 000000000000..894922775425 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationCacheDAO extends DAO { + int getApplicationId(String applicationCode); + + String getApplicationCode(int applicationId); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java new file mode 100644 index 000000000000..daa08dc64273 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationComponentPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java new file mode 100644 index 000000000000..3f449368c2ee --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationComponentUIDAO extends DAO { + JsonArray load(long startTime, long endTime); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java new file mode 100644 index 000000000000..4551d370419c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationMappingPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java new file mode 100644 index 000000000000..60aadea355d0 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationMappingUIDAO extends DAO { + JsonArray load(long startTime, long endTime); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java new file mode 100644 index 000000000000..efd579509b06 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java new file mode 100644 index 000000000000..372e4d7f47fa --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface IApplicationReferenceMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java new file mode 100644 index 000000000000..a8c4aa06d3fd --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IApplicationReferenceMetricUIDAO extends DAO { + JsonArray load(long startTime, long endTime); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java new file mode 100644 index 000000000000..5b6311701dbc --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; + +/** + * @author peng-yongsheng + */ +public interface IApplicationRegisterDAO extends DAO { + int getMaxApplicationId(); + + int getMinApplicationId(); + + void save(Application application); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java new file mode 100644 index 000000000000..151b086bfec4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface ICpuMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java new file mode 100644 index 000000000000..2d4a420e138d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface ICpuMetricUIDAO extends DAO { + int getMetric(int instanceId, long timeBucket); + + JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java new file mode 100644 index 000000000000..7bb6a2ab2182 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IGCMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java new file mode 100644 index 000000000000..ef4f0dc49ec8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IGCMetricUIDAO extends DAO { + + GCCount getGCCount(long[] timeBuckets, int instanceId); + + JsonObject getMetric(int instanceId, long timeBucket); + + JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket); + + class GCCount { + private int young; + private int old; + private int full; + + public int getYoung() { + return young; + } + + public int getOld() { + return old; + } + + public int getFull() { + return full; + } + + public void setYoung(int young) { + this.young = young; + } + + public void setOld(int old) { + this.old = old; + } + + public void setFull(int full) { + this.full = full; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java new file mode 100644 index 000000000000..d072cc41cd8e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IGlobalTracePersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java new file mode 100644 index 000000000000..85bfa292b6c8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IGlobalTraceUIDAO extends DAO { + List getGlobalTraceId(String segmentId); + + List getSegmentIds(String globalTraceId); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java new file mode 100644 index 000000000000..47c9e919cd04 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IInstanceCacheDAO extends DAO { + int getApplicationId(int instanceId); + + int getInstanceId(int applicationId, String agentUUID); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java new file mode 100644 index 000000000000..bbf93b89880c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IInstanceHeartBeatPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java new file mode 100644 index 000000000000..7a0258962e00 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IInstanceMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java new file mode 100644 index 000000000000..63d7c2112ebc --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IInstanceMetricUIDAO extends DAO { + InstanceMetric get(long[] timeBuckets, int instanceId); + + long getTpsMetric(int instanceId, long timeBucket); + + JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket); + + long getRespTimeMetric(int instanceId, long timeBucket); + + JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket); + + class InstanceMetric { + private final int instanceId; + private final long calls; + private final long durationSum; + + public InstanceMetric(int instanceId, long calls, long durationSum) { + this.instanceId = instanceId; + this.calls = calls; + this.durationSum = durationSum; + } + + public int getInstanceId() { + return instanceId; + } + + public long getCalls() { + return calls; + } + + public long getDurationSum() { + return durationSum; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java new file mode 100644 index 000000000000..c8128bd94f8d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IInstanceReferenceMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java new file mode 100644 index 000000000000..b205f2060b7f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; + +/** + * @author peng-yongsheng + */ +public interface IInstanceRegisterDAO extends DAO { + int getMaxInstanceId(); + + int getMinInstanceId(); + + void save(Instance instance); + + void updateHeartbeatTime(int instanceId, long heartbeatTime); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java new file mode 100644 index 000000000000..aa85b69ba3d8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonArray; +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; + +/** + * @author peng-yongsheng + */ +public interface IInstanceUIDAO extends DAO { + Long lastHeartBeatTime(); + + Long instanceLastHeartBeatTime(long applicationInstanceId); + + JsonArray getApplications(long startTime, long endTime); + + Instance getInstance(int instanceId); + + List getInstances(int applicationId, long timeBucket); + + class Application { + private final int applicationId; + private final long count; + + public Application(int applicationId, long count) { + this.applicationId = applicationId; + this.count = count; + } + + public int getApplicationId() { + return applicationId; + } + + public long getCount() { + return count; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java new file mode 100644 index 000000000000..0b1edc5c7d08 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IMemoryMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java new file mode 100644 index 000000000000..60abe97236ba --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IMemoryMetricUIDAO extends DAO { + JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap); + + JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java new file mode 100644 index 000000000000..c168ae02df3d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IMemoryPoolMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java new file mode 100644 index 000000000000..1c2f98639d62 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IMemoryPoolMetricUIDAO extends DAO { + JsonObject getMetric(int instanceId, long timeBucket, int poolType); + + JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java new file mode 100644 index 000000000000..2edcb9f5d9c4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface ISegmentCostPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java new file mode 100644 index 000000000000..174013560e98 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonObject; +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface ISegmentCostUIDAO extends DAO { + JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, + Error error, int applicationId, List segmentIds, int limit, int from, Sort sort); + + enum Sort { + Cost, Time + } + + enum Error { + All, True, False + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java new file mode 100644 index 000000000000..abcc026dfae9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface ISegmentPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java new file mode 100644 index 000000000000..7114f0fcc17c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; + +/** + * @author peng-yongsheng + */ +public interface ISegmentUIDAO extends DAO { + TraceSegmentObject load(String segmentId); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java new file mode 100644 index 000000000000..574c4cd809fc --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IServiceEntryPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java new file mode 100644 index 000000000000..145bc3a5105c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IServiceEntryUIDAO extends DAO { + JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from, int size); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java new file mode 100644 index 000000000000..4bb6a8331d60 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IServiceMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java new file mode 100644 index 000000000000..f4b8f1b50744 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IServiceNameCacheDAO extends DAO { + String getServiceName(int serviceId); + + int getServiceId(int applicationId, String serviceName); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java new file mode 100644 index 000000000000..649aabeca3cb --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; + +/** + * @author peng-yongsheng + */ +public interface IServiceNameRegisterDAO extends DAO { + int getMaxServiceId(); + + int getMinServiceId(); + + void save(ServiceName serviceName); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java new file mode 100644 index 000000000000..3d486d9b1706 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public interface IServiceReferenceMetricPersistenceDAO extends IPersistenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java new file mode 100644 index 000000000000..7b8e0f564544 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.dao; + +import com.google.gson.JsonObject; +import java.util.Map; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; + +/** + * @author peng-yongsheng + */ +public interface IServiceReferenceUIDAO extends DAO { + Map load(int entryServiceId, long startTime, long endTime); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/CommonMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/CommonMetricTable.java new file mode 100644 index 000000000000..9839bc4d4191 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/CommonMetricTable.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public abstract class CommonMetricTable extends CommonTable { + public static final String COLUMN_TRANSACTION_CALLS = "transaction_calls"; + public static final String COLUMN_TRANSACTION_ERROR_CALLS = "transaction_error_calls"; + public static final String COLUMN_TRANSACTION_DURATION_SUM = "transaction_duration_sum"; + public static final String COLUMN_TRANSACTION_ERROR_DURATION_SUM = "transaction_error_duration_sum"; + public static final String COLUMN_BUSINESS_TRANSACTION_CALLS = "business_transaction_calls"; + public static final String COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS = "business_transaction_error_calls"; + public static final String COLUMN_BUSINESS_TRANSACTION_DURATION_SUM = "business_transaction_duration_sum"; + public static final String COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM = "business_transaction_error_duration_sum"; + public static final String COLUMN_MQ_TRANSACTION_CALLS = "mq_transaction_calls"; + public static final String COLUMN_MQ_TRANSACTION_ERROR_CALLS = "mq_transaction_error_calls"; + public static final String COLUMN_MQ_TRANSACTION_DURATION_SUM = "mq_transaction_duration_sum"; + public static final String COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM = "mq_transaction_error_duration_sum"; + public static final String COLUMN_SOURCE_VALUE = "source_value"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingList.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingList.java new file mode 100644 index 000000000000..52b8671ad80a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingList.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.alerting; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class AlertingList extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(AlertingListTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(AlertingListTable.COLUMN_FIRST_TIME_BUCKET, new NonOperation()), + new Column(AlertingListTable.COLUMN_LAST_TIME_BUCKET, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + + private static final Column[] INTEGER_COLUMNS = { + new Column(AlertingListTable.COLUMN_LAYER, new CoverOperation()), + new Column(AlertingListTable.COLUMN_LAYER_ID, new CoverOperation()), + new Column(AlertingListTable.COLUMN_EXPECTED, new CoverOperation()), + new Column(AlertingListTable.COLUMN_ACTUAL, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = { + new Column(AlertingListTable.COLUMN_VALID, new CoverOperation()), + }; + + private static final Column[] BYTE_COLUMNS = {}; + + public AlertingList(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public Integer getLayer() { + return getDataInteger(0); + } + + public void setLayer(Integer layer) { + setDataInteger(0, layer); + } + + public Integer getLayerId() { + return getDataInteger(1); + } + + public void setLayerId(Integer layerId) { + setDataInteger(1, layerId); + } + + public Integer getExpected() { + return getDataInteger(2); + } + + public void setExpected(Integer expected) { + setDataInteger(2, expected); + } + + public Integer getActual() { + return getDataInteger(3); + } + + public void setActual(Integer actual) { + setDataInteger(3, actual); + } + + public Long getFirstTimeBucket() { + return getDataLong(0); + } + + public void setFirstTimeBucket(Long firstTimeBucket) { + setDataLong(0, firstTimeBucket); + } + + public Long getLastTimeBucket() { + return getDataLong(1); + } + + public void setLastTimeBucket(Long lastTimeBucket) { + setDataLong(1, lastTimeBucket); + } + + public Boolean getValid() { + return getDataBoolean(0); + } + + public void setValid(Boolean valid) { + setDataBoolean(0, valid); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java new file mode 100644 index 000000000000..ef12315669b4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.alerting; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class AlertingListTable extends CommonTable { + public static final String TABLE = "alerting_list"; + public static final String COLUMN_LAYER = "layer"; + public static final String COLUMN_LAYER_ID = "layer_id"; + public static final String COLUMN_FIRST_TIME_BUCKET = "first_time_bucket"; + public static final String COLUMN_LAST_TIME_BUCKET = "last_time_bucket"; + public static final String COLUMN_EXPECTED = "expected"; + public static final String COLUMN_ACTUAL = "actual"; + public static final String COLUMN_VALID = "valid"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java new file mode 100644 index 000000000000..a23707806e1d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponent extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(ApplicationComponentTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(ApplicationComponentTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(ApplicationComponentTable.COLUMN_COMPONENT_ID, new CoverOperation()), + new Column(ApplicationComponentTable.COLUMN_PEER_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public ApplicationComponent(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public Long getTimeBucket() { + return getDataLong(0); + } + + public void setTimeBucket(Long timeBucket) { + setDataLong(0, timeBucket); + } + + public Integer getComponentId() { + return getDataInteger(0); + } + + public void setComponentId(Integer componentId) { + setDataInteger(0, componentId); + } + + public Integer getPeerId() { + return getDataInteger(1); + } + + public void setPeerId(Integer peerId) { + setDataInteger(1, peerId); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java new file mode 100644 index 000000000000..7ba317f0ce3b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentTable extends CommonTable { + public static final String TABLE = "application_component"; + public static final String COLUMN_COMPONENT_ID = "component_id"; + public static final String COLUMN_PEER_ID = "peer_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java new file mode 100644 index 000000000000..9bcdf617e1a3 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class ApplicationMapping extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(ApplicationMappingTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(ApplicationMappingTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(ApplicationMappingTable.COLUMN_APPLICATION_ID, new CoverOperation()), + new Column(ApplicationMappingTable.COLUMN_ADDRESS_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public ApplicationMapping(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public int getApplicationId() { + return getDataInteger(0); + } + + public void setApplicationId(int applicationId) { + setDataInteger(0, applicationId); + } + + public int getAddressId() { + return getDataInteger(1); + } + + public void setAddressId(int addressId) { + setDataInteger(1, addressId); + } + + public long getTimeBucket() { + return getDataLong(0); + } + + public void setTimeBucket(long timeBucket) { + setDataLong(0, timeBucket); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java new file mode 100644 index 000000000000..769d46cf9239 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingTable extends CommonTable { + public static final String TABLE = "application_mapping"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_ADDRESS_ID = "address_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetric.java similarity index 84% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetric.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetric.java index b49bbe6a5c54..f2901a5a5122 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetric.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetric.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.collector.storage.table.application; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java new file mode 100644 index 000000000000..55b8f26ed3ad --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; + +import org.apache.skywalking.apm.collector.storage.table.CommonMetricTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationMetricTable extends CommonMetricTable { + public static final String TABLE = "application_metric"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_SATISFIED_COUNT = "satisfied_count"; + public static final String COLUMN_TOLERATING_COUNT = "tolerating_count"; + public static final String COLUMN_FRUSTRATED_COUNT = "frustrated_count"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java similarity index 85% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java index 095739b94fb2..5fe61c12a8e4 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetric.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.collector.storage.table.application; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java new file mode 100644 index 000000000000..57941251dd97 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.application; + +import org.apache.skywalking.apm.collector.storage.table.CommonMetricTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationReferenceMetricTable extends CommonMetricTable { + public static final String TABLE = "application_reference"; + public static final String COLUMN_FRONT_APPLICATION_ID = "front_application_id"; + public static final String COLUMN_BEHIND_APPLICATION_ID = "behind_application_id"; + public static final String COLUMN_SATISFIED_COUNT = "satisfied_count"; + public static final String COLUMN_TOLERATING_COUNT = "tolerating_count"; + public static final String COLUMN_FRUSTRATED_COUNT = "frustrated_count"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTrace.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTrace.java new file mode 100644 index 000000000000..9a0d99a0df6e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTrace.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.global; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class GlobalTrace extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(GlobalTraceTable.COLUMN_ID, new NonOperation()), + new Column(GlobalTraceTable.COLUMN_SEGMENT_ID, new CoverOperation()), + new Column(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, new CoverOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(GlobalTraceTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public GlobalTrace(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public String getSegmentId() { + return getDataString(1); + } + + public void setSegmentId(String segmentId) { + setDataString(1, segmentId); + } + + public String getGlobalTraceId() { + return getDataString(2); + } + + public void setGlobalTraceId(String globalTraceId) { + setDataString(2, globalTraceId); + } + + public Long getTimeBucket() { + return getDataLong(0); + } + + public void setTimeBucket(long timeBucket) { + setDataLong(0, timeBucket); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java new file mode 100644 index 000000000000..0128c2d52d2b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.global; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceTable extends CommonTable { + public static final String TABLE = "global_trace"; + public static final String COLUMN_SEGMENT_ID = "segment_id"; + public static final String COLUMN_GLOBAL_TRACE_ID = "global_trace_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetric.java similarity index 83% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetric.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetric.java index b176575ad36b..06d5be9964b6 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetric.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetric.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.collector.storage.table.instance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.instance; -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java new file mode 100644 index 000000000000..efbe5c75b83c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.instance; + +import org.apache.skywalking.apm.collector.storage.table.CommonMetricTable; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricTable extends CommonMetricTable { + public static final String TABLE = "instance_metric"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_INSTANCE_ID = "instance_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java similarity index 85% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java index 56c0ffb71e2a..25ad99156294 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetric.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.collector.storage.table.instance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.instance; -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java new file mode 100644 index 000000000000..2b254a81927f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.instance; + +import org.apache.skywalking.apm.collector.storage.table.CommonMetricTable; + +/** + * @author peng-yongsheng + */ +public class InstanceReferenceMetricTable extends CommonMetricTable { + public static final String TABLE = "instance_reference_metric"; + public static final String COLUMN_FRONT_INSTANCE_ID = "front_instance_id"; + public static final String COLUMN_BEHIND_INSTANCE_ID = "behind_instance_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetric.java new file mode 100644 index 000000000000..46914ed621e4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetric.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class CpuMetric extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(CpuMetricTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(CpuMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + + private static final Column[] DOUBLE_COLUMNS = { + new Column(CpuMetricTable.COLUMN_USAGE_PERCENT, new AddOperation()), + }; + + private static final Column[] INTEGER_COLUMNS = { + new Column(CpuMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public CpuMetric(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public Integer getInstanceId() { + return getDataInteger(0); + } + + public void setInstanceId(Integer instanceId) { + setDataInteger(0, instanceId); + } + + public Double getUsagePercent() { + return getDataDouble(0); + } + + public void setUsagePercent(Double usagePercent) { + setDataDouble(0, usagePercent); + } + + public Long getTimeBucket() { + return getDataLong(0); + } + + public void setTimeBucket(Long timeBucket) { + setDataLong(0, timeBucket); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java new file mode 100644 index 000000000000..e471af2272fe --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class CpuMetricTable extends CommonTable { + public static final String TABLE = "cpu_metric"; + public static final String COLUMN_INSTANCE_ID = "instance_id"; + public static final String COLUMN_USAGE_PERCENT = "usage_percent"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetric.java new file mode 100644 index 000000000000..7c5f24820ae5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetric.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class GCMetric extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(GCMetricTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(GCMetricTable.COLUMN_COUNT, new CoverOperation()), + new Column(GCMetricTable.COLUMN_TIME, new CoverOperation()), + new Column(GCMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + + private static final Column[] DOUBLE_COLUMNS = { + }; + + private static final Column[] INTEGER_COLUMNS = { + new Column(GCMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), + new Column(GCMetricTable.COLUMN_PHRASE, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public GCMetric(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public Long getCount() { + return getDataLong(0); + } + + public void setCount(Long count) { + setDataLong(0, count); + } + + public Long getTime() { + return getDataLong(1); + } + + public void setTime(Long time) { + setDataLong(1, time); + } + + public Long getTimeBucket() { + return getDataLong(2); + } + + public void setTimeBucket(Long timeBucket) { + setDataLong(2, timeBucket); + } + + public Integer getInstanceId() { + return getDataInteger(0); + } + + public void setInstanceId(Integer instanceId) { + setDataInteger(0, instanceId); + } + + public Integer getPhrase() { + return getDataInteger(1); + } + + public void setPhrase(Integer phrase) { + setDataInteger(1, phrase); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java new file mode 100644 index 000000000000..c3a67ffbe309 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class GCMetricTable extends CommonTable { + public static final String TABLE = "gc_metric"; + public static final String COLUMN_INSTANCE_ID = "instance_id"; + public static final String COLUMN_PHRASE = "phrase"; + public static final String COLUMN_COUNT = "count"; + public static final String COLUMN_TIME = "time"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java new file mode 100644 index 000000000000..c76495c8bdbe --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class MemoryMetric extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(MemoryMetricTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(MemoryMetricTable.COLUMN_INIT, new CoverOperation()), + new Column(MemoryMetricTable.COLUMN_MAX, new CoverOperation()), + new Column(MemoryMetricTable.COLUMN_USED, new CoverOperation()), + new Column(MemoryMetricTable.COLUMN_COMMITTED, new CoverOperation()), + new Column(MemoryMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + + private static final Column[] DOUBLE_COLUMNS = { + }; + + private static final Column[] INTEGER_COLUMNS = { + new Column(MemoryMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = { + new Column(MemoryMetricTable.COLUMN_IS_HEAP, new CoverOperation()), + }; + private static final Column[] BYTE_COLUMNS = {}; + + public MemoryMetric(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public Long getInit() { + return getDataLong(0); + } + + public void setInit(Long init) { + setDataLong(0, init); + } + + public Long getMax() { + return getDataLong(1); + } + + public void setMax(Long max) { + setDataLong(1, max); + } + + public Long getUsed() { + return getDataLong(2); + } + + public void setUsed(Long used) { + setDataLong(2, used); + } + + public Long getCommitted() { + return getDataLong(3); + } + + public void setCommitted(Long committed) { + setDataLong(3, committed); + } + + public Long getTimeBucket() { + return getDataLong(4); + } + + public void setTimeBucket(Long timeBucket) { + setDataLong(4, timeBucket); + } + + public Boolean getIsHeap() { + return getDataBoolean(0); + } + + public void setIsHeap(Boolean isHeap) { + setDataBoolean(0, isHeap); + } + + public Integer getInstanceId() { + return getDataInteger(0); + } + + public void setInstanceId(Integer instanceId) { + setDataInteger(0, instanceId); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java new file mode 100644 index 000000000000..d6a185d02d59 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricTable extends CommonTable { + public static final String TABLE = "memory_metric"; + public static final String COLUMN_INSTANCE_ID = "instance_id"; + public static final String COLUMN_IS_HEAP = "is_heap"; + public static final String COLUMN_INIT = "init"; + public static final String COLUMN_MAX = "max"; + public static final String COLUMN_USED = "used"; + public static final String COLUMN_COMMITTED = "committed"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java new file mode 100644 index 000000000000..fb07aeffb1d8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetric extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(MemoryPoolMetricTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(MemoryPoolMetricTable.COLUMN_INIT, new CoverOperation()), + new Column(MemoryPoolMetricTable.COLUMN_MAX, new CoverOperation()), + new Column(MemoryPoolMetricTable.COLUMN_USED, new CoverOperation()), + new Column(MemoryPoolMetricTable.COLUMN_COMMITTED, new CoverOperation()), + new Column(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + + private static final Column[] DOUBLE_COLUMNS = { + }; + + private static final Column[] INTEGER_COLUMNS = { + new Column(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), + new Column(MemoryPoolMetricTable.COLUMN_POOL_TYPE, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public MemoryPoolMetric(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public Long getInit() { + return getDataLong(0); + } + + public void setInit(Long init) { + setDataLong(0, init); + } + + public Long getMax() { + return getDataLong(1); + } + + public void setMax(Long max) { + setDataLong(1, max); + } + + public Long getUsed() { + return getDataLong(2); + } + + public void setUsed(Long used) { + setDataLong(2, used); + } + + public Long getCommitted() { + return getDataLong(3); + } + + public void setCommitted(Long committed) { + setDataLong(3, committed); + } + + public Long getTimeBucket() { + return getDataLong(4); + } + + public void setTimeBucket(Long timeBucket) { + setDataLong(4, timeBucket); + } + + public Integer getInstanceId() { + return getDataInteger(0); + } + + public void setInstanceId(Integer instanceId) { + setDataInteger(0, instanceId); + } + + public Integer getPoolType() { + return getDataInteger(1); + } + + public void setPoolType(Integer poolType) { + setDataInteger(1, poolType); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java new file mode 100644 index 000000000000..5a75379a49e3 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.jvm; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricTable extends CommonTable { + public static final String TABLE = "memory_pool_metric"; + public static final String COLUMN_INSTANCE_ID = "instance_id"; + public static final String COLUMN_POOL_TYPE = "pool_type"; + public static final String COLUMN_INIT = "init"; + public static final String COLUMN_MAX = "max"; + public static final String COLUMN_USED = "used"; + public static final String COLUMN_COMMITTED = "committed"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java new file mode 100644 index 000000000000..ec4559b5f957 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.register; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class Application extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(ApplicationTable.COLUMN_ID, new NonOperation()), + new Column(ApplicationTable.COLUMN_APPLICATION_CODE, new CoverOperation()), + }; + + private static final Column[] LONG_COLUMNS = {}; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(ApplicationTable.COLUMN_APPLICATION_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public Application(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public String getApplicationCode() { + return getDataString(1); + } + + public void setApplicationCode(String applicationCode) { + setDataString(1, applicationCode); + } + + public int getApplicationId() { + return getDataInteger(0); + } + + public void setApplicationId(int applicationId) { + setDataInteger(0, applicationId); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java new file mode 100644 index 000000000000..4612289b99f8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.register; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationTable extends CommonTable { + public static final String TABLE = "application"; + public static final String COLUMN_APPLICATION_CODE = "application_code"; + public static final String COLUMN_APPLICATION_ID = "application_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Instance.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Instance.java new file mode 100644 index 000000000000..0dee44bd6ca9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Instance.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.register; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class Instance extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(InstanceTable.COLUMN_ID, new NonOperation()), + new Column(InstanceTable.COLUMN_AGENT_UUID, new CoverOperation()), + new Column(InstanceTable.COLUMN_OS_INFO, new CoverOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(InstanceTable.COLUMN_REGISTER_TIME, new CoverOperation()), + new Column(InstanceTable.COLUMN_HEARTBEAT_TIME, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(InstanceTable.COLUMN_APPLICATION_ID, new CoverOperation()), + new Column(InstanceTable.COLUMN_INSTANCE_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public Instance(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public String getId() { + return getDataString(0); + } + + public int getApplicationId() { + return getDataInteger(0); + } + + public void setApplicationId(Integer applicationId) { + setDataInteger(0, applicationId); + } + + public String getAgentUUID() { + return getDataString(1); + } + + public void setAgentUUID(String agentUUID) { + setDataString(1, agentUUID); + } + + public long getRegisterTime() { + return getDataLong(0); + } + + public void setRegisterTime(Long registerTime) { + setDataLong(0, registerTime); + } + + public int getInstanceId() { + return getDataInteger(1); + } + + public void setInstanceId(Integer instanceId) { + setDataInteger(1, instanceId); + } + + public long getHeartBeatTime() { + return getDataLong(1); + } + + public void setHeartBeatTime(Long heartBeatTime) { + setDataLong(1, heartBeatTime); + } + + public String getOsInfo() { + return getDataString(2); + } + + public void setOsInfo(String osInfo) { + setDataString(2, osInfo); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/InstanceTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/InstanceTable.java new file mode 100644 index 000000000000..49f09567dd5c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/InstanceTable.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.register; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class InstanceTable extends CommonTable { + public static final String TABLE = "instance"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_AGENT_UUID = "agent_uuid"; + public static final String COLUMN_REGISTER_TIME = "register_time"; + public static final String COLUMN_INSTANCE_ID = "instance_id"; + public static final String COLUMN_HEARTBEAT_TIME = "heartbeat_time"; + public static final String COLUMN_OS_INFO = "os_info"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceName.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceName.java new file mode 100644 index 000000000000..1a7bd1fc76b4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceName.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.register; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class ServiceName extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(ServiceNameTable.COLUMN_ID, new NonOperation()), + new Column(ServiceNameTable.COLUMN_SERVICE_NAME, new CoverOperation()), + }; + + private static final Column[] LONG_COLUMNS = {}; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(ServiceNameTable.COLUMN_APPLICATION_ID, new CoverOperation()), + new Column(ServiceNameTable.COLUMN_SERVICE_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public ServiceName(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public String getServiceName() { + return getDataString(1); + } + + public void setServiceName(String serviceName) { + setDataString(1, serviceName); + } + + public int getApplicationId() { + return getDataInteger(0); + } + + public void setApplicationId(int applicationId) { + setDataInteger(0, applicationId); + } + + public int getServiceId() { + return getDataInteger(1); + } + + public void setServiceId(int serviceId) { + setDataInteger(1, serviceId); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceNameTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceNameTable.java new file mode 100644 index 000000000000..46b67ee19375 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServiceNameTable.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.register; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class ServiceNameTable extends CommonTable { + public static final String TABLE = "service_name"; + public static final String COLUMN_SERVICE_NAME = "service_name"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_SERVICE_ID = "service_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/Segment.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/Segment.java new file mode 100644 index 000000000000..9e5529a079db --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/Segment.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.segment; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class Segment extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(SegmentTable.COLUMN_ID, new NonOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(SegmentTable.COLUMN_TIME_BUCKET, new NonOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = { + new Column(SegmentTable.COLUMN_DATA_BINARY, new CoverOperation()), + }; + + public Segment(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public byte[] getDataBinary() { + return getDataBytes(0); + } + + public void setDataBinary(byte[] dataBinary) { + setDataBytes(0, dataBinary); + } + + public long getTimeBucket() { + return getDataLong(0); + } + + public void setTimeBucket(long timeBucket) { + setDataLong(0, timeBucket); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java new file mode 100644 index 000000000000..7015db1b0fb4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.segment; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class SegmentCost extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(SegmentCostTable.COLUMN_ID, new NonOperation()), + new Column(SegmentCostTable.COLUMN_SEGMENT_ID, new CoverOperation()), + new Column(SegmentCostTable.COLUMN_SERVICE_NAME, new CoverOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(SegmentCostTable.COLUMN_COST, new CoverOperation()), + new Column(SegmentCostTable.COLUMN_START_TIME, new CoverOperation()), + new Column(SegmentCostTable.COLUMN_END_TIME, new CoverOperation()), + new Column(SegmentCostTable.COLUMN_TIME_BUCKET, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(SegmentCostTable.COLUMN_APPLICATION_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = { + new Column(SegmentCostTable.COLUMN_IS_ERROR, new CoverOperation()), + }; + private static final Column[] BYTE_COLUMNS = {}; + + public SegmentCost(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public String getSegmentId() { + return getDataString(1); + } + + public void setSegmentId(String segmentId) { + setDataString(1, segmentId); + } + + public String getServiceName() { + return getDataString(2); + } + + public void setServiceName(String serviceName) { + setDataString(2, serviceName); + } + + public Long getCost() { + return getDataLong(0); + } + + public void setCost(Long cost) { + setDataLong(0, cost); + } + + public Long getStartTime() { + return getDataLong(1); + } + + public void setStartTime(Long startTime) { + setDataLong(1, startTime); + } + + public Long getEndTime() { + return getDataLong(2); + } + + public void setEndTime(Long endTime) { + setDataLong(2, endTime); + } + + public Long getTimeBucket() { + return getDataLong(3); + } + + public void setTimeBucket(Long timeBucket) { + setDataLong(3, timeBucket); + } + + public Integer getApplicationId() { + return getDataInteger(0); + } + + public void setApplicationId(Integer applicationId) { + setDataInteger(0, applicationId); + } + + public Boolean getIsError() { + return getDataBoolean(0); + } + + public void setIsError(Boolean isError) { + setDataBoolean(0, isError); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java new file mode 100644 index 000000000000..df82867d6122 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.segment; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class SegmentCostTable extends CommonTable { + public static final String TABLE = "segment_cost"; + public static final String COLUMN_SEGMENT_ID = "segment_id"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_START_TIME = "start_time"; + public static final String COLUMN_END_TIME = "end_time"; + public static final String COLUMN_SERVICE_NAME = "service_name"; + public static final String COLUMN_COST = "cost"; + public static final String COLUMN_IS_ERROR = "is_error"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentTable.java new file mode 100644 index 000000000000..e39a1e0e03c4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentTable.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.segment; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class SegmentTable extends CommonTable { + public static final String TABLE = "segment"; + public static final String COLUMN_DATA_BINARY = "data_binary"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntry.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntry.java new file mode 100644 index 000000000000..beaa6fd4f7f8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntry.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.service; + +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.CoverOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; + +/** + * @author peng-yongsheng + */ +public class ServiceEntry extends Data { + + private static final Column[] STRING_COLUMNS = { + new Column(ServiceEntryTable.COLUMN_ID, new NonOperation()), + new Column(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, new CoverOperation()), + }; + + private static final Column[] LONG_COLUMNS = { + new Column(ServiceEntryTable.COLUMN_REGISTER_TIME, new NonOperation()), + new Column(ServiceEntryTable.COLUMN_NEWEST_TIME, new CoverOperation()), + }; + private static final Column[] DOUBLE_COLUMNS = {}; + private static final Column[] INTEGER_COLUMNS = { + new Column(ServiceEntryTable.COLUMN_APPLICATION_ID, new CoverOperation()), + new Column(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, new CoverOperation()), + }; + + private static final Column[] BOOLEAN_COLUMNS = {}; + private static final Column[] BYTE_COLUMNS = {}; + + public ServiceEntry(String id) { + super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); + } + + public String getEntryServiceName() { + return getDataString(1); + } + + public void setEntryServiceName(String entryServiceName) { + setDataString(1, entryServiceName); + } + + public Long getRegisterTime() { + return getDataLong(0); + } + + public void setRegisterTime(Long registerTime) { + setDataLong(0, registerTime); + } + + public Long getNewestTime() { + return getDataLong(1); + } + + public void setNewestTime(Long newestTime) { + setDataLong(1, newestTime); + } + + public Integer getApplicationId() { + return getDataInteger(0); + } + + public void setApplicationId(Integer applicationId) { + setDataInteger(0, applicationId); + } + + public Integer getEntryServiceId() { + return getDataInteger(1); + } + + public void setEntryServiceId(Integer entryServiceId) { + setDataInteger(1, entryServiceId); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java new file mode 100644 index 000000000000..5663737fdaad --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.service; + +import org.apache.skywalking.apm.collector.core.data.CommonTable; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryTable extends CommonTable { + public static final String TABLE = "service_entry"; + public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_ENTRY_SERVICE_ID = "entry_service_id"; + public static final String COLUMN_ENTRY_SERVICE_NAME = "entry_service_name"; + public static final String COLUMN_REGISTER_TIME = "register_time"; + public static final String COLUMN_NEWEST_TIME = "newest_time"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetric.java similarity index 83% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetric.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetric.java index 779d7947d2e5..6dd0a6f23a3a 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetric.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetric.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.collector.storage.table.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.service; -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java new file mode 100644 index 000000000000..f227864a3f03 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.service; + +import org.apache.skywalking.apm.collector.storage.table.CommonMetricTable; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricTable extends CommonMetricTable { + public static final String TABLE = "service_metric"; + public static final String COLUMN_SERVICE_ID = "service_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java similarity index 87% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java index 70fffbf398f7..5df4cd84ca52 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetric.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.collector.storage.table.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.service; -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; +import org.apache.skywalking.apm.collector.core.data.Column; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.data.operator.AddOperation; +import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java new file mode 100644 index 000000000000..100fcfc428ff --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.table.service; + +import org.apache.skywalking.apm.collector.storage.table.CommonMetricTable; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceMetricTable extends CommonMetricTable { + public static final String TABLE = "service_reference_metric"; + public static final String COLUMN_ENTRY_SERVICE_ID = "entry_service_id"; + public static final String COLUMN_ENTRY_INSTANCE_ID = "entry_instance_id"; + public static final String COLUMN_FRONT_SERVICE_ID = "front_service_id"; + public static final String COLUMN_FRONT_INSTANCE_ID = "front_instance_id"; + public static final String COLUMN_BEHIND_SERVICE_ID = "behind_service_id"; + public static final String COLUMN_BEHIND_INSTANCE_ID = "behind_instance_id"; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageException.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageException.java deleted file mode 100644 index cb9f989980e6..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * @author peng-yongsheng - */ -public abstract class StorageException extends CollectorException { - - public StorageException(String message) { - super(message); - } - - public StorageException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstallException.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstallException.java deleted file mode 100644 index 624845ff6e2c..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstallException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage; - -/** - * @author peng-yongsheng - */ -public class StorageInstallException extends StorageException { - - public StorageInstallException(String message) { - super(message); - } - - public StorageInstallException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstaller.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstaller.java deleted file mode 100644 index 4a9b2f2331cd..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageInstaller.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage; - -import java.util.List; -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.core.define.DefineException; -import org.skywalking.apm.collector.core.data.StorageDefineLoader; -import org.skywalking.apm.collector.core.data.TableDefine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public abstract class StorageInstaller { - - private final Logger logger = LoggerFactory.getLogger(StorageInstaller.class); - - public final void install(Client client) throws StorageException { - StorageDefineLoader defineLoader = new StorageDefineLoader(); - try { - List tableDefines = defineLoader.load(); - defineFilter(tableDefines); - Boolean debug = System.getProperty("debug") != null; - - for (TableDefine tableDefine : tableDefines) { - tableDefine.initialize(); - if (!isExists(client, tableDefine)) { - logger.info("table: {} not exists", tableDefine.getName()); - createTable(client, tableDefine); - } else if (debug) { - logger.info("table: {} exists", tableDefine.getName()); - deleteTable(client, tableDefine); - createTable(client, tableDefine); - } - } - } catch (DefineException e) { - throw new StorageInstallException(e.getMessage(), e); - } - } - - protected abstract void defineFilter(List tableDefines); - - protected abstract boolean isExists(Client client, TableDefine tableDefine) throws StorageException; - - protected abstract boolean deleteTable(Client client, TableDefine tableDefine) throws StorageException; - - protected abstract boolean createTable(Client client, TableDefine tableDefine) throws StorageException; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageModule.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageModule.java deleted file mode 100644 index e249b35071c0..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/StorageModule.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage; - -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; - -/** - * @author peng-yongsheng - */ -public class StorageModule extends Module { - - public static final String NAME = "storage"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - List classes = new ArrayList<>(); - classes.add(IBatchDAO.class); - - addCacheDAO(classes); - addRegisterDAO(classes); - addPersistenceDAO(classes); - addUiDAO(classes); - addAlertingDAO(classes); - - return classes.toArray(new Class[] {}); - } - - private void addCacheDAO(List classes) { - classes.add(IApplicationCacheDAO.class); - classes.add(IInstanceCacheDAO.class); - classes.add(IServiceNameCacheDAO.class); - } - - private void addRegisterDAO(List classes) { - classes.add(IApplicationRegisterDAO.class); - classes.add(IInstanceRegisterDAO.class); - classes.add(IServiceNameRegisterDAO.class); - } - - private void addPersistenceDAO(List classes) { - classes.add(ICpuMetricPersistenceDAO.class); - classes.add(IGCMetricPersistenceDAO.class); - classes.add(IMemoryMetricPersistenceDAO.class); - classes.add(IMemoryPoolMetricPersistenceDAO.class); - - classes.add(IGlobalTracePersistenceDAO.class); - classes.add(IInstanceMetricPersistenceDAO.class); - classes.add(IApplicationComponentPersistenceDAO.class); - classes.add(IApplicationMappingPersistenceDAO.class); - classes.add(IApplicationMetricPersistenceDAO.class); - classes.add(IApplicationReferenceMetricPersistenceDAO.class); - classes.add(ISegmentCostPersistenceDAO.class); - classes.add(ISegmentPersistenceDAO.class); - classes.add(IServiceEntryPersistenceDAO.class); - classes.add(IServiceMetricPersistenceDAO.class); - classes.add(IServiceReferenceMetricPersistenceDAO.class); - - classes.add(IInstanceHeartBeatPersistenceDAO.class); - } - - private void addUiDAO(List classes) { - classes.add(IInstanceUIDAO.class); - - classes.add(ICpuMetricUIDAO.class); - classes.add(IGCMetricUIDAO.class); - classes.add(IMemoryMetricUIDAO.class); - classes.add(IMemoryPoolMetricUIDAO.class); - - classes.add(IGlobalTraceUIDAO.class); - classes.add(IInstanceMetricUIDAO.class); - classes.add(IApplicationComponentUIDAO.class); - classes.add(IApplicationMappingUIDAO.class); - classes.add(IApplicationReferenceMetricUIDAO.class); - classes.add(ISegmentCostUIDAO.class); - classes.add(ISegmentUIDAO.class); - classes.add(IServiceEntryUIDAO.class); - classes.add(IServiceReferenceUIDAO.class); - } - - private void addAlertingDAO(List classes) { - classes.add(IAlertingListPersistenceDAO.class); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/AbstractDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/AbstractDAO.java deleted file mode 100644 index 758420b4b315..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/AbstractDAO.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.base.dao; - -import org.skywalking.apm.collector.client.Client; - -/** - * @author peng-yongsheng - */ -public abstract class AbstractDAO implements DAO { - private final C client; - - public AbstractDAO(C client) { - this.client = client; - } - - public final C getClient() { - return client; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAO.java deleted file mode 100644 index 7eb44f9b917a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAO.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.base.dao; - -import org.skywalking.apm.collector.core.module.Service; - -/** - * @author peng-yongsheng - */ -public interface DAO extends Service { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IBatchDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IBatchDAO.java deleted file mode 100644 index d7377de7666e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IBatchDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.base.dao; - -import java.util.List; - -/** - * @author peng-yongsheng - */ -public interface IBatchDAO extends DAO { - void batchPersistence(List batchCollection); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java deleted file mode 100644 index b6ac57eaf093..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.base.dao; - -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public interface IPersistenceDAO extends DAO { - DataImpl get(String id); - - Insert prepareBatchInsert(DataImpl data); - - Update prepareBatchUpdate(DataImpl data); - - void deleteHistory(Long startTimestamp, Long endTimestamp); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/sql/SqlBuilder.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/sql/SqlBuilder.java deleted file mode 100644 index c89837a2a537..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/sql/SqlBuilder.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.base.sql; - -import java.text.MessageFormat; -import java.util.List; -import java.util.Set; - -public class SqlBuilder { - public static String buildSql(String sql, Object... args) { - return MessageFormat.format(sql, args); - } - - public static String buildSql(String sql, List args) { - MessageFormat messageFormat = new MessageFormat(sql); - return messageFormat.format(args.toArray(new Object[0])); - } - - public static String buildBatchInsertSql(String tableName, Set columnNames) { - StringBuilder sb = new StringBuilder("insert into "); - sb.append(tableName).append("("); - columnNames.forEach((columnName) -> sb.append(columnName).append(",")); - sb.delete(sb.length() - 1, sb.length()); - sb.append(") values("); - for (int i = 0; i < columnNames.size(); i++) { - sb.append("?,"); - } - sb.delete(sb.length() - 1, sb.length()); - sb.append(")"); - return sb.toString(); - } - - public static String buildBatchUpdateSql(String tableName, Set columnNames, String whereClauseName) { - StringBuilder sb = new StringBuilder("update "); - sb.append(tableName).append(" set "); - columnNames.forEach((columnName) -> sb.append(columnName).append("=?,")); - sb.delete(sb.length() - 1, sb.length()); - sb.append(" where ").append(whereClauseName).append("=?"); - return sb.toString(); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java deleted file mode 100644 index 53a9c558f49b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IAlertingListPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IAlertingListPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java deleted file mode 100644 index aa19fc77bc57..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationCacheDAO extends DAO { - int getApplicationId(String applicationCode); - - String getApplicationCode(int applicationId); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java deleted file mode 100644 index 56ff4dd25f60..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationComponentPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java deleted file mode 100644 index f37a63db855f..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonArray; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationComponentUIDAO extends DAO { - JsonArray load(long startTime, long endTime); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java deleted file mode 100644 index 2fd399dd103d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationMappingPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java deleted file mode 100644 index 72efeaf85647..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonArray; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationMappingUIDAO extends DAO { - JsonArray load(long startTime, long endTime); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java deleted file mode 100644 index 7bd114e2339a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java deleted file mode 100644 index ae2e8af4bad8..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationReferenceMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java deleted file mode 100644 index fc895c7a4b85..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonArray; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IApplicationReferenceMetricUIDAO extends DAO { - JsonArray load(long startTime, long endTime); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java deleted file mode 100644 index 7d5939deec9a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationRegisterDAO.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; -import org.skywalking.apm.collector.storage.table.register.Application; - -/** - * @author peng-yongsheng - */ -public interface IApplicationRegisterDAO extends DAO { - int getMaxApplicationId(); - - int getMinApplicationId(); - - void save(Application application); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java deleted file mode 100644 index ace07bf06c32..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface ICpuMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java deleted file mode 100644 index 9803b091b982..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonArray; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface ICpuMetricUIDAO extends DAO { - int getMetric(int instanceId, long timeBucket); - - JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java deleted file mode 100644 index 7790bf86b00b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IGCMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java deleted file mode 100644 index e87ec24040e8..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonObject; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IGCMetricUIDAO extends DAO { - - GCCount getGCCount(long[] timeBuckets, int instanceId); - - JsonObject getMetric(int instanceId, long timeBucket); - - JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket); - - class GCCount { - private int young; - private int old; - private int full; - - public int getYoung() { - return young; - } - - public int getOld() { - return old; - } - - public int getFull() { - return full; - } - - public void setYoung(int young) { - this.young = young; - } - - public void setOld(int old) { - this.old = old; - } - - public void setFull(int full) { - this.full = full; - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java deleted file mode 100644 index 883600e41f94..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTracePersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IGlobalTracePersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java deleted file mode 100644 index a953f45cb4fb..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import java.util.List; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IGlobalTraceUIDAO extends DAO { - List getGlobalTraceId(String segmentId); - - List getSegmentIds(String globalTraceId); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java deleted file mode 100644 index d4bbeaeff053..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IInstanceCacheDAO extends DAO { - int getApplicationId(int instanceId); - - int getInstanceId(int applicationId, String agentUUID); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java deleted file mode 100644 index 29ce4b5ec52b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceHeartBeatPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IInstanceHeartBeatPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java deleted file mode 100644 index c070d27862c8..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IInstanceMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java deleted file mode 100644 index 61f5b5f14820..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonArray; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IInstanceMetricUIDAO extends DAO { - InstanceMetric get(long[] timeBuckets, int instanceId); - - long getTpsMetric(int instanceId, long timeBucket); - - JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket); - - long getRespTimeMetric(int instanceId, long timeBucket); - - JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket); - - class InstanceMetric { - private final int instanceId; - private final long calls; - private final long durationSum; - - public InstanceMetric(int instanceId, long calls, long durationSum) { - this.instanceId = instanceId; - this.calls = calls; - this.durationSum = durationSum; - } - - public int getInstanceId() { - return instanceId; - } - - public long getCalls() { - return calls; - } - - public long getDurationSum() { - return durationSum; - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java deleted file mode 100644 index 7ae77ca5d0e9..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceReferenceMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IInstanceReferenceMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java deleted file mode 100644 index 9e95b63a1e3d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceRegisterDAO.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; -import org.skywalking.apm.collector.storage.table.register.Instance; - -/** - * @author peng-yongsheng - */ -public interface IInstanceRegisterDAO extends DAO { - int getMaxInstanceId(); - - int getMinInstanceId(); - - void save(Instance instance); - - void updateHeartbeatTime(int instanceId, long heartbeatTime); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java deleted file mode 100644 index 1c283399575b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonArray; -import java.util.List; -import org.skywalking.apm.collector.storage.base.dao.DAO; -import org.skywalking.apm.collector.storage.table.register.Instance; - -/** - * @author peng-yongsheng - */ -public interface IInstanceUIDAO extends DAO { - Long lastHeartBeatTime(); - - Long instanceLastHeartBeatTime(long applicationInstanceId); - - JsonArray getApplications(long startTime, long endTime); - - Instance getInstance(int instanceId); - - List getInstances(int applicationId, long timeBucket); - - class Application { - private final int applicationId; - private final long count; - - public Application(int applicationId, long count) { - this.applicationId = applicationId; - this.count = count; - } - - public int getApplicationId() { - return applicationId; - } - - public long getCount() { - return count; - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java deleted file mode 100644 index 5cb0fc2cb7c3..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IMemoryMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java deleted file mode 100644 index bac8f55fb2af..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonObject; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IMemoryMetricUIDAO extends DAO { - JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap); - - JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java deleted file mode 100644 index 1d3279924311..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IMemoryPoolMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java deleted file mode 100644 index ac474ebd9cd2..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonObject; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IMemoryPoolMetricUIDAO extends DAO { - JsonObject getMetric(int instanceId, long timeBucket, int poolType); - - JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java deleted file mode 100644 index 5f4ba4cd11ac..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface ISegmentCostPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java deleted file mode 100644 index f2404d23ed08..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonObject; -import java.util.List; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface ISegmentCostUIDAO extends DAO { - JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, - Error error, int applicationId, List segmentIds, int limit, int from, Sort sort); - - enum Sort { - Cost, Time - } - - enum Error { - All, True, False - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java deleted file mode 100644 index a62fe5aaf4c3..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface ISegmentPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java deleted file mode 100644 index 9f0c315d59a4..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; -import org.skywalking.apm.network.proto.TraceSegmentObject; - -/** - * @author peng-yongsheng - */ -public interface ISegmentUIDAO extends DAO { - TraceSegmentObject load(String segmentId); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java deleted file mode 100644 index ff69be0f91f0..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IServiceEntryPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java deleted file mode 100644 index bd09ec5b4c4f..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryUIDAO.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonObject; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IServiceEntryUIDAO extends DAO { - JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from, int size); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java deleted file mode 100644 index adf6fef9c75d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IServiceMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java deleted file mode 100644 index 0a2c8f434295..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IServiceNameCacheDAO extends DAO { - String getServiceName(int serviceId); - - int getServiceId(int applicationId, String serviceName); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java deleted file mode 100644 index 7c2ac77db36b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameRegisterDAO.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.storage.base.dao.DAO; -import org.skywalking.apm.collector.storage.table.register.ServiceName; - -/** - * @author peng-yongsheng - */ -public interface IServiceNameRegisterDAO extends DAO { - int getMaxServiceId(); - - int getMinServiceId(); - - void save(ServiceName serviceName); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java deleted file mode 100644 index 647fe35e7ced..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceMetricPersistenceDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public interface IServiceReferenceMetricPersistenceDAO extends IPersistenceDAO { -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java deleted file mode 100644 index c750a2630511..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.dao; - -import com.google.gson.JsonObject; -import java.util.Map; -import org.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IServiceReferenceUIDAO extends DAO { - Map load(int entryServiceId, long startTime, long endTime); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/CommonMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/CommonMetricTable.java deleted file mode 100644 index 6694bd509c2b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/CommonMetricTable.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public abstract class CommonMetricTable extends CommonTable { - public static final String COLUMN_TRANSACTION_CALLS = "transaction_calls"; - public static final String COLUMN_TRANSACTION_ERROR_CALLS = "transaction_error_calls"; - public static final String COLUMN_TRANSACTION_DURATION_SUM = "transaction_duration_sum"; - public static final String COLUMN_TRANSACTION_ERROR_DURATION_SUM = "transaction_error_duration_sum"; - public static final String COLUMN_BUSINESS_TRANSACTION_CALLS = "business_transaction_calls"; - public static final String COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS = "business_transaction_error_calls"; - public static final String COLUMN_BUSINESS_TRANSACTION_DURATION_SUM = "business_transaction_duration_sum"; - public static final String COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM = "business_transaction_error_duration_sum"; - public static final String COLUMN_MQ_TRANSACTION_CALLS = "mq_transaction_calls"; - public static final String COLUMN_MQ_TRANSACTION_ERROR_CALLS = "mq_transaction_error_calls"; - public static final String COLUMN_MQ_TRANSACTION_DURATION_SUM = "mq_transaction_duration_sum"; - public static final String COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM = "mq_transaction_error_duration_sum"; - public static final String COLUMN_SOURCE_VALUE = "source_value"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingList.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingList.java deleted file mode 100644 index cc09173a67ed..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingList.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.alerting; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class AlertingList extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(AlertingListTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(AlertingListTable.COLUMN_FIRST_TIME_BUCKET, new NonOperation()), - new Column(AlertingListTable.COLUMN_LAST_TIME_BUCKET, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - - private static final Column[] INTEGER_COLUMNS = { - new Column(AlertingListTable.COLUMN_LAYER, new CoverOperation()), - new Column(AlertingListTable.COLUMN_LAYER_ID, new CoverOperation()), - new Column(AlertingListTable.COLUMN_EXPECTED, new CoverOperation()), - new Column(AlertingListTable.COLUMN_ACTUAL, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = { - new Column(AlertingListTable.COLUMN_VALID, new CoverOperation()), - }; - - private static final Column[] BYTE_COLUMNS = {}; - - public AlertingList(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public Integer getLayer() { - return getDataInteger(0); - } - - public void setLayer(Integer layer) { - setDataInteger(0, layer); - } - - public Integer getLayerId() { - return getDataInteger(1); - } - - public void setLayerId(Integer layerId) { - setDataInteger(1, layerId); - } - - public Integer getExpected() { - return getDataInteger(2); - } - - public void setExpected(Integer expected) { - setDataInteger(2, expected); - } - - public Integer getActual() { - return getDataInteger(3); - } - - public void setActual(Integer actual) { - setDataInteger(3, actual); - } - - public Long getFirstTimeBucket() { - return getDataLong(0); - } - - public void setFirstTimeBucket(Long firstTimeBucket) { - setDataLong(0, firstTimeBucket); - } - - public Long getLastTimeBucket() { - return getDataLong(1); - } - - public void setLastTimeBucket(Long lastTimeBucket) { - setDataLong(1, lastTimeBucket); - } - - public Boolean getValid() { - return getDataBoolean(0); - } - - public void setValid(Boolean valid) { - setDataBoolean(0, valid); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java deleted file mode 100644 index d7d0ac43e3b2..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/alerting/AlertingListTable.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.alerting; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class AlertingListTable extends CommonTable { - public static final String TABLE = "alerting_list"; - public static final String COLUMN_LAYER = "layer"; - public static final String COLUMN_LAYER_ID = "layer_id"; - public static final String COLUMN_FIRST_TIME_BUCKET = "first_time_bucket"; - public static final String COLUMN_LAST_TIME_BUCKET = "last_time_bucket"; - public static final String COLUMN_EXPECTED = "expected"; - public static final String COLUMN_ACTUAL = "actual"; - public static final String COLUMN_VALID = "valid"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponent.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponent.java deleted file mode 100644 index e92b8ca9cf64..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponent.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.application; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponent extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(ApplicationComponentTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(ApplicationComponentTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(ApplicationComponentTable.COLUMN_COMPONENT_ID, new CoverOperation()), - new Column(ApplicationComponentTable.COLUMN_PEER_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public ApplicationComponent(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public Long getTimeBucket() { - return getDataLong(0); - } - - public void setTimeBucket(Long timeBucket) { - setDataLong(0, timeBucket); - } - - public Integer getComponentId() { - return getDataInteger(0); - } - - public void setComponentId(Integer componentId) { - setDataInteger(0, componentId); - } - - public Integer getPeerId() { - return getDataInteger(1); - } - - public void setPeerId(Integer peerId) { - setDataInteger(1, peerId); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java deleted file mode 100644 index cf21e3a73c5e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.application; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentTable extends CommonTable { - public static final String TABLE = "application_component"; - public static final String COLUMN_COMPONENT_ID = "component_id"; - public static final String COLUMN_PEER_ID = "peer_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMapping.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMapping.java deleted file mode 100644 index 73b6338cec01..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMapping.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.application; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class ApplicationMapping extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(ApplicationMappingTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(ApplicationMappingTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(ApplicationMappingTable.COLUMN_APPLICATION_ID, new CoverOperation()), - new Column(ApplicationMappingTable.COLUMN_ADDRESS_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public ApplicationMapping(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public int getApplicationId() { - return getDataInteger(0); - } - - public void setApplicationId(int applicationId) { - setDataInteger(0, applicationId); - } - - public int getAddressId() { - return getDataInteger(1); - } - - public void setAddressId(int addressId) { - setDataInteger(1, addressId); - } - - public long getTimeBucket() { - return getDataLong(0); - } - - public void setTimeBucket(long timeBucket) { - setDataLong(0, timeBucket); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java deleted file mode 100644 index a8560ca32774..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.application; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingTable extends CommonTable { - public static final String TABLE = "application_mapping"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_ADDRESS_ID = "address_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java deleted file mode 100644 index 2449d1aaaf93..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationMetricTable.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.application; - -import org.skywalking.apm.collector.storage.table.CommonMetricTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationMetricTable extends CommonMetricTable { - public static final String TABLE = "application_metric"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_SATISFIED_COUNT = "satisfied_count"; - public static final String COLUMN_TOLERATING_COUNT = "tolerating_count"; - public static final String COLUMN_FRUSTRATED_COUNT = "frustrated_count"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java deleted file mode 100644 index 7606bd3358bc..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/application/ApplicationReferenceMetricTable.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.application; - -import org.skywalking.apm.collector.storage.table.CommonMetricTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationReferenceMetricTable extends CommonMetricTable { - public static final String TABLE = "application_reference"; - public static final String COLUMN_FRONT_APPLICATION_ID = "front_application_id"; - public static final String COLUMN_BEHIND_APPLICATION_ID = "behind_application_id"; - public static final String COLUMN_SATISFIED_COUNT = "satisfied_count"; - public static final String COLUMN_TOLERATING_COUNT = "tolerating_count"; - public static final String COLUMN_FRUSTRATED_COUNT = "frustrated_count"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTrace.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTrace.java deleted file mode 100644 index 12c08d079d35..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTrace.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.global; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class GlobalTrace extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(GlobalTraceTable.COLUMN_ID, new NonOperation()), - new Column(GlobalTraceTable.COLUMN_SEGMENT_ID, new CoverOperation()), - new Column(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, new CoverOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(GlobalTraceTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public GlobalTrace(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public String getSegmentId() { - return getDataString(1); - } - - public void setSegmentId(String segmentId) { - setDataString(1, segmentId); - } - - public String getGlobalTraceId() { - return getDataString(2); - } - - public void setGlobalTraceId(String globalTraceId) { - setDataString(2, globalTraceId); - } - - public Long getTimeBucket() { - return getDataLong(0); - } - - public void setTimeBucket(long timeBucket) { - setDataLong(0, timeBucket); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java deleted file mode 100644 index db0052789928..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/global/GlobalTraceTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.global; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class GlobalTraceTable extends CommonTable { - public static final String TABLE = "global_trace"; - public static final String COLUMN_SEGMENT_ID = "segment_id"; - public static final String COLUMN_GLOBAL_TRACE_ID = "global_trace_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java deleted file mode 100644 index 769b80e1adb4..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceMetricTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.instance; - -import org.skywalking.apm.collector.storage.table.CommonMetricTable; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricTable extends CommonMetricTable { - public static final String TABLE = "instance_metric"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_INSTANCE_ID = "instance_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java deleted file mode 100644 index 7778d302d817..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/instance/InstanceReferenceMetricTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.instance; - -import org.skywalking.apm.collector.storage.table.CommonMetricTable; - -/** - * @author peng-yongsheng - */ -public class InstanceReferenceMetricTable extends CommonMetricTable { - public static final String TABLE = "instance_reference_metric"; - public static final String COLUMN_FRONT_INSTANCE_ID = "front_instance_id"; - public static final String COLUMN_BEHIND_INSTANCE_ID = "behind_instance_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetric.java deleted file mode 100644 index 06348e5069b5..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetric.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.AddOperation; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class CpuMetric extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(CpuMetricTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(CpuMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - - private static final Column[] DOUBLE_COLUMNS = { - new Column(CpuMetricTable.COLUMN_USAGE_PERCENT, new AddOperation()), - }; - - private static final Column[] INTEGER_COLUMNS = { - new Column(CpuMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public CpuMetric(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public Integer getInstanceId() { - return getDataInteger(0); - } - - public void setInstanceId(Integer instanceId) { - setDataInteger(0, instanceId); - } - - public Double getUsagePercent() { - return getDataDouble(0); - } - - public void setUsagePercent(Double usagePercent) { - setDataDouble(0, usagePercent); - } - - public Long getTimeBucket() { - return getDataLong(0); - } - - public void setTimeBucket(Long timeBucket) { - setDataLong(0, timeBucket); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java deleted file mode 100644 index cd88b83a809e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/CpuMetricTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class CpuMetricTable extends CommonTable { - public static final String TABLE = "cpu_metric"; - public static final String COLUMN_INSTANCE_ID = "instance_id"; - public static final String COLUMN_USAGE_PERCENT = "usage_percent"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetric.java deleted file mode 100644 index 525de0312367..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetric.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class GCMetric extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(GCMetricTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(GCMetricTable.COLUMN_COUNT, new CoverOperation()), - new Column(GCMetricTable.COLUMN_TIME, new CoverOperation()), - new Column(GCMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - - private static final Column[] DOUBLE_COLUMNS = { - }; - - private static final Column[] INTEGER_COLUMNS = { - new Column(GCMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), - new Column(GCMetricTable.COLUMN_PHRASE, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public GCMetric(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public Long getCount() { - return getDataLong(0); - } - - public void setCount(Long count) { - setDataLong(0, count); - } - - public Long getTime() { - return getDataLong(1); - } - - public void setTime(Long time) { - setDataLong(1, time); - } - - public Long getTimeBucket() { - return getDataLong(2); - } - - public void setTimeBucket(Long timeBucket) { - setDataLong(2, timeBucket); - } - - public Integer getInstanceId() { - return getDataInteger(0); - } - - public void setInstanceId(Integer instanceId) { - setDataInteger(0, instanceId); - } - - public Integer getPhrase() { - return getDataInteger(1); - } - - public void setPhrase(Integer phrase) { - setDataInteger(1, phrase); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java deleted file mode 100644 index 2d3f61ad49fd..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/GCMetricTable.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class GCMetricTable extends CommonTable { - public static final String TABLE = "gc_metric"; - public static final String COLUMN_INSTANCE_ID = "instance_id"; - public static final String COLUMN_PHRASE = "phrase"; - public static final String COLUMN_COUNT = "count"; - public static final String COLUMN_TIME = "time"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java deleted file mode 100644 index e7334f4cc3d4..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetric.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class MemoryMetric extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(MemoryMetricTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(MemoryMetricTable.COLUMN_INIT, new CoverOperation()), - new Column(MemoryMetricTable.COLUMN_MAX, new CoverOperation()), - new Column(MemoryMetricTable.COLUMN_USED, new CoverOperation()), - new Column(MemoryMetricTable.COLUMN_COMMITTED, new CoverOperation()), - new Column(MemoryMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - - private static final Column[] DOUBLE_COLUMNS = { - }; - - private static final Column[] INTEGER_COLUMNS = { - new Column(MemoryMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = { - new Column(MemoryMetricTable.COLUMN_IS_HEAP, new CoverOperation()), - }; - private static final Column[] BYTE_COLUMNS = {}; - - public MemoryMetric(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public Long getInit() { - return getDataLong(0); - } - - public void setInit(Long init) { - setDataLong(0, init); - } - - public Long getMax() { - return getDataLong(1); - } - - public void setMax(Long max) { - setDataLong(1, max); - } - - public Long getUsed() { - return getDataLong(2); - } - - public void setUsed(Long used) { - setDataLong(2, used); - } - - public Long getCommitted() { - return getDataLong(3); - } - - public void setCommitted(Long committed) { - setDataLong(3, committed); - } - - public Long getTimeBucket() { - return getDataLong(4); - } - - public void setTimeBucket(Long timeBucket) { - setDataLong(4, timeBucket); - } - - public Boolean getIsHeap() { - return getDataBoolean(0); - } - - public void setIsHeap(Boolean isHeap) { - setDataBoolean(0, isHeap); - } - - public Integer getInstanceId() { - return getDataInteger(0); - } - - public void setInstanceId(Integer instanceId) { - setDataInteger(0, instanceId); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java deleted file mode 100644 index a54c9f307cbf..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryMetricTable.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricTable extends CommonTable { - public static final String TABLE = "memory_metric"; - public static final String COLUMN_INSTANCE_ID = "instance_id"; - public static final String COLUMN_IS_HEAP = "is_heap"; - public static final String COLUMN_INIT = "init"; - public static final String COLUMN_MAX = "max"; - public static final String COLUMN_USED = "used"; - public static final String COLUMN_COMMITTED = "committed"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java deleted file mode 100644 index 9eb35d7f4812..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetric.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetric extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(MemoryPoolMetricTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(MemoryPoolMetricTable.COLUMN_INIT, new CoverOperation()), - new Column(MemoryPoolMetricTable.COLUMN_MAX, new CoverOperation()), - new Column(MemoryPoolMetricTable.COLUMN_USED, new CoverOperation()), - new Column(MemoryPoolMetricTable.COLUMN_COMMITTED, new CoverOperation()), - new Column(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - - private static final Column[] DOUBLE_COLUMNS = { - }; - - private static final Column[] INTEGER_COLUMNS = { - new Column(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, new CoverOperation()), - new Column(MemoryPoolMetricTable.COLUMN_POOL_TYPE, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public MemoryPoolMetric(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public Long getInit() { - return getDataLong(0); - } - - public void setInit(Long init) { - setDataLong(0, init); - } - - public Long getMax() { - return getDataLong(1); - } - - public void setMax(Long max) { - setDataLong(1, max); - } - - public Long getUsed() { - return getDataLong(2); - } - - public void setUsed(Long used) { - setDataLong(2, used); - } - - public Long getCommitted() { - return getDataLong(3); - } - - public void setCommitted(Long committed) { - setDataLong(3, committed); - } - - public Long getTimeBucket() { - return getDataLong(4); - } - - public void setTimeBucket(Long timeBucket) { - setDataLong(4, timeBucket); - } - - public Integer getInstanceId() { - return getDataInteger(0); - } - - public void setInstanceId(Integer instanceId) { - setDataInteger(0, instanceId); - } - - public Integer getPoolType() { - return getDataInteger(1); - } - - public void setPoolType(Integer poolType) { - setDataInteger(1, poolType); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java deleted file mode 100644 index ffcfcd80712f..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/jvm/MemoryPoolMetricTable.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.jvm; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricTable extends CommonTable { - public static final String TABLE = "memory_pool_metric"; - public static final String COLUMN_INSTANCE_ID = "instance_id"; - public static final String COLUMN_POOL_TYPE = "pool_type"; - public static final String COLUMN_INIT = "init"; - public static final String COLUMN_MAX = "max"; - public static final String COLUMN_USED = "used"; - public static final String COLUMN_COMMITTED = "committed"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Application.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Application.java deleted file mode 100644 index e782ba1b0db0..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Application.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.register; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class Application extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(ApplicationTable.COLUMN_ID, new NonOperation()), - new Column(ApplicationTable.COLUMN_APPLICATION_CODE, new CoverOperation()), - }; - - private static final Column[] LONG_COLUMNS = {}; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(ApplicationTable.COLUMN_APPLICATION_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public Application(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public String getApplicationCode() { - return getDataString(1); - } - - public void setApplicationCode(String applicationCode) { - setDataString(1, applicationCode); - } - - public int getApplicationId() { - return getDataInteger(0); - } - - public void setApplicationId(int applicationId) { - setDataInteger(0, applicationId); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationTable.java deleted file mode 100644 index 9618931e6519..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationTable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.register; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationTable extends CommonTable { - public static final String TABLE = "application"; - public static final String COLUMN_APPLICATION_CODE = "application_code"; - public static final String COLUMN_APPLICATION_ID = "application_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Instance.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Instance.java deleted file mode 100644 index b845ef5ca18d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/Instance.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.register; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class Instance extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(InstanceTable.COLUMN_ID, new NonOperation()), - new Column(InstanceTable.COLUMN_AGENT_UUID, new CoverOperation()), - new Column(InstanceTable.COLUMN_OS_INFO, new CoverOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(InstanceTable.COLUMN_REGISTER_TIME, new CoverOperation()), - new Column(InstanceTable.COLUMN_HEARTBEAT_TIME, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(InstanceTable.COLUMN_APPLICATION_ID, new CoverOperation()), - new Column(InstanceTable.COLUMN_INSTANCE_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public Instance(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public String getId() { - return getDataString(0); - } - - public int getApplicationId() { - return getDataInteger(0); - } - - public void setApplicationId(Integer applicationId) { - setDataInteger(0, applicationId); - } - - public String getAgentUUID() { - return getDataString(1); - } - - public void setAgentUUID(String agentUUID) { - setDataString(1, agentUUID); - } - - public long getRegisterTime() { - return getDataLong(0); - } - - public void setRegisterTime(Long registerTime) { - setDataLong(0, registerTime); - } - - public int getInstanceId() { - return getDataInteger(1); - } - - public void setInstanceId(Integer instanceId) { - setDataInteger(1, instanceId); - } - - public long getHeartBeatTime() { - return getDataLong(1); - } - - public void setHeartBeatTime(Long heartBeatTime) { - setDataLong(1, heartBeatTime); - } - - public String getOsInfo() { - return getDataString(2); - } - - public void setOsInfo(String osInfo) { - setDataString(2, osInfo); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceTable.java deleted file mode 100644 index c0a3cd740778..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceTable.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.register; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class InstanceTable extends CommonTable { - public static final String TABLE = "instance"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_AGENT_UUID = "agent_uuid"; - public static final String COLUMN_REGISTER_TIME = "register_time"; - public static final String COLUMN_INSTANCE_ID = "instance_id"; - public static final String COLUMN_HEARTBEAT_TIME = "heartbeat_time"; - public static final String COLUMN_OS_INFO = "os_info"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceName.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceName.java deleted file mode 100644 index 66dd68a17707..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceName.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.register; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class ServiceName extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(ServiceNameTable.COLUMN_ID, new NonOperation()), - new Column(ServiceNameTable.COLUMN_SERVICE_NAME, new CoverOperation()), - }; - - private static final Column[] LONG_COLUMNS = {}; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(ServiceNameTable.COLUMN_APPLICATION_ID, new CoverOperation()), - new Column(ServiceNameTable.COLUMN_SERVICE_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public ServiceName(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public String getServiceName() { - return getDataString(1); - } - - public void setServiceName(String serviceName) { - setDataString(1, serviceName); - } - - public int getApplicationId() { - return getDataInteger(0); - } - - public void setApplicationId(int applicationId) { - setDataInteger(0, applicationId); - } - - public int getServiceId() { - return getDataInteger(1); - } - - public void setServiceId(int serviceId) { - setDataInteger(1, serviceId); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameTable.java deleted file mode 100644 index 337b0a7ab7b4..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameTable.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.register; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class ServiceNameTable extends CommonTable { - public static final String TABLE = "service_name"; - public static final String COLUMN_SERVICE_NAME = "service_name"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_SERVICE_ID = "service_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/Segment.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/Segment.java deleted file mode 100644 index b917b2ea5d6d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/Segment.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.segment; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class Segment extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(SegmentTable.COLUMN_ID, new NonOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(SegmentTable.COLUMN_TIME_BUCKET, new NonOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = { - new Column(SegmentTable.COLUMN_DATA_BINARY, new CoverOperation()), - }; - - public Segment(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public byte[] getDataBinary() { - return getDataBytes(0); - } - - public void setDataBinary(byte[] dataBinary) { - setDataBytes(0, dataBinary); - } - - public long getTimeBucket() { - return getDataLong(0); - } - - public void setTimeBucket(long timeBucket) { - setDataLong(0, timeBucket); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCost.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCost.java deleted file mode 100644 index 800cd980a731..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCost.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.segment; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class SegmentCost extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(SegmentCostTable.COLUMN_ID, new NonOperation()), - new Column(SegmentCostTable.COLUMN_SEGMENT_ID, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_SERVICE_NAME, new CoverOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(SegmentCostTable.COLUMN_COST, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_START_TIME, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_END_TIME, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_TIME_BUCKET, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(SegmentCostTable.COLUMN_APPLICATION_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = { - new Column(SegmentCostTable.COLUMN_IS_ERROR, new CoverOperation()), - }; - private static final Column[] BYTE_COLUMNS = {}; - - public SegmentCost(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public String getSegmentId() { - return getDataString(1); - } - - public void setSegmentId(String segmentId) { - setDataString(1, segmentId); - } - - public String getServiceName() { - return getDataString(2); - } - - public void setServiceName(String serviceName) { - setDataString(2, serviceName); - } - - public Long getCost() { - return getDataLong(0); - } - - public void setCost(Long cost) { - setDataLong(0, cost); - } - - public Long getStartTime() { - return getDataLong(1); - } - - public void setStartTime(Long startTime) { - setDataLong(1, startTime); - } - - public Long getEndTime() { - return getDataLong(2); - } - - public void setEndTime(Long endTime) { - setDataLong(2, endTime); - } - - public Long getTimeBucket() { - return getDataLong(3); - } - - public void setTimeBucket(Long timeBucket) { - setDataLong(3, timeBucket); - } - - public Integer getApplicationId() { - return getDataInteger(0); - } - - public void setApplicationId(Integer applicationId) { - setDataInteger(0, applicationId); - } - - public Boolean getIsError() { - return getDataBoolean(0); - } - - public void setIsError(Boolean isError) { - setDataBoolean(0, isError); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java deleted file mode 100644 index d7f5e4e892dc..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.segment; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class SegmentCostTable extends CommonTable { - public static final String TABLE = "segment_cost"; - public static final String COLUMN_SEGMENT_ID = "segment_id"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_START_TIME = "start_time"; - public static final String COLUMN_END_TIME = "end_time"; - public static final String COLUMN_SERVICE_NAME = "service_name"; - public static final String COLUMN_COST = "cost"; - public static final String COLUMN_IS_ERROR = "is_error"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentTable.java deleted file mode 100644 index 1dbe28a6efa9..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/segment/SegmentTable.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.segment; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class SegmentTable extends CommonTable { - public static final String TABLE = "segment"; - public static final String COLUMN_DATA_BINARY = "data_binary"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntry.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntry.java deleted file mode 100644 index 7cdf811a9b1c..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntry.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.service; - -import org.skywalking.apm.collector.core.data.Column; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.data.operator.CoverOperation; -import org.skywalking.apm.collector.core.data.operator.NonOperation; - -/** - * @author peng-yongsheng - */ -public class ServiceEntry extends Data { - - private static final Column[] STRING_COLUMNS = { - new Column(ServiceEntryTable.COLUMN_ID, new NonOperation()), - new Column(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, new CoverOperation()), - }; - - private static final Column[] LONG_COLUMNS = { - new Column(ServiceEntryTable.COLUMN_REGISTER_TIME, new NonOperation()), - new Column(ServiceEntryTable.COLUMN_NEWEST_TIME, new CoverOperation()), - }; - private static final Column[] DOUBLE_COLUMNS = {}; - private static final Column[] INTEGER_COLUMNS = { - new Column(ServiceEntryTable.COLUMN_APPLICATION_ID, new CoverOperation()), - new Column(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, new CoverOperation()), - }; - - private static final Column[] BOOLEAN_COLUMNS = {}; - private static final Column[] BYTE_COLUMNS = {}; - - public ServiceEntry(String id) { - super(id, STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BOOLEAN_COLUMNS, BYTE_COLUMNS); - } - - public String getEntryServiceName() { - return getDataString(1); - } - - public void setEntryServiceName(String entryServiceName) { - setDataString(1, entryServiceName); - } - - public Long getRegisterTime() { - return getDataLong(0); - } - - public void setRegisterTime(Long registerTime) { - setDataLong(0, registerTime); - } - - public Long getNewestTime() { - return getDataLong(1); - } - - public void setNewestTime(Long newestTime) { - setDataLong(1, newestTime); - } - - public Integer getApplicationId() { - return getDataInteger(0); - } - - public void setApplicationId(Integer applicationId) { - setDataInteger(0, applicationId); - } - - public Integer getEntryServiceId() { - return getDataInteger(1); - } - - public void setEntryServiceId(Integer entryServiceId) { - setDataInteger(1, entryServiceId); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java deleted file mode 100644 index b4f8f098624a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceEntryTable.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.service; - -import org.skywalking.apm.collector.core.data.CommonTable; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryTable extends CommonTable { - public static final String TABLE = "service_entry"; - public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_ENTRY_SERVICE_ID = "entry_service_id"; - public static final String COLUMN_ENTRY_SERVICE_NAME = "entry_service_name"; - public static final String COLUMN_REGISTER_TIME = "register_time"; - public static final String COLUMN_NEWEST_TIME = "newest_time"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java deleted file mode 100644 index 66da8f261c69..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceMetricTable.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.service; - -import org.skywalking.apm.collector.storage.table.CommonMetricTable; - -/** - * @author peng-yongsheng - */ -public class ServiceMetricTable extends CommonMetricTable { - public static final String TABLE = "service_metric"; - public static final String COLUMN_SERVICE_ID = "service_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java deleted file mode 100644 index afed79994349..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/service/ServiceReferenceMetricTable.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.table.service; - -import org.skywalking.apm.collector.storage.table.CommonMetricTable; - -/** - * @author peng-yongsheng - */ -public class ServiceReferenceMetricTable extends CommonMetricTable { - public static final String TABLE = "service_reference_metric"; - public static final String COLUMN_ENTRY_SERVICE_ID = "entry_service_id"; - public static final String COLUMN_ENTRY_INSTANCE_ID = "entry_instance_id"; - public static final String COLUMN_FRONT_SERVICE_ID = "front_service_id"; - public static final String COLUMN_FRONT_INSTANCE_ID = "front_instance_id"; - public static final String COLUMN_BEHIND_SERVICE_ID = "behind_service_id"; - public static final String COLUMN_BEHIND_INSTANCE_ID = "behind_instance_id"; -} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..b1217c903bd6 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.storage.StorageModule diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 80cd942ae835..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.storage.StorageModule diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java new file mode 100644 index 000000000000..91e48b66e437 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es; + +import java.util.Calendar; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public class DataTTLKeeperTimer { + + private final ModuleManager moduleManager; + private final StorageModuleEsNamingListener namingListener; + private final String selfAddress; + private final int daysBefore; + + public DataTTLKeeperTimer(ModuleManager moduleManager, + StorageModuleEsNamingListener namingListener, String selfAddress, int daysBefore) { + this.moduleManager = moduleManager; + this.namingListener = namingListener; + this.selfAddress = selfAddress; + this.daysBefore = daysBefore; + } + + public void start() { + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::delete, 1, 8, TimeUnit.HOURS); + } + + private void delete() { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + calendar.set(Calendar.DAY_OF_MONTH, -daysBefore); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + + long startTimestamp = calendar.getTimeInMillis(); + + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + long endTimestamp = calendar.getTimeInMillis(); + + deleteJVMRelatedData(startTimestamp, endTimestamp); + deleteTraceRelatedData(startTimestamp, endTimestamp); + } + + private void deleteJVMRelatedData(long startTimestamp, long endTimestamp) { + ICpuMetricPersistenceDAO cpuMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ICpuMetricPersistenceDAO.class); + cpuMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IGCMetricPersistenceDAO gcMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IGCMetricPersistenceDAO.class); + gcMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IMemoryMetricPersistenceDAO memoryMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryMetricPersistenceDAO.class); + memoryMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IMemoryPoolMetricPersistenceDAO memoryPoolMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryPoolMetricPersistenceDAO.class); + memoryPoolMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + } + + private void deleteTraceRelatedData(long startTimestamp, long endTimestamp) { + IGlobalTracePersistenceDAO globalTracePersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTracePersistenceDAO.class); + globalTracePersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IInstanceMetricPersistenceDAO instanceMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceMetricPersistenceDAO.class); + instanceMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IApplicationComponentPersistenceDAO applicationComponentPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentPersistenceDAO.class); + applicationComponentPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IApplicationMappingPersistenceDAO applicationMappingPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingPersistenceDAO.class); + applicationMappingPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IApplicationReferenceMetricPersistenceDAO applicationReferenceMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricPersistenceDAO.class); + applicationReferenceMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + ISegmentCostPersistenceDAO segmentCostPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentCostPersistenceDAO.class); + segmentCostPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + ISegmentPersistenceDAO segmentPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentPersistenceDAO.class); + segmentPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + + IServiceReferenceMetricPersistenceDAO serviceReferencePersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceMetricPersistenceDAO.class); + serviceReferencePersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java new file mode 100644 index 000000000000..ec5da6ae3d97 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es; + +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.storage.StorageModule; + +/** + * @author peng-yongsheng + */ +public class StorageModuleEsNamingListener extends ClusterModuleListener { + + public static final String PATH = "/" + StorageModule.NAME + "/" + StorageModuleEsProvider.NAME; + + @Override public String path() { + return PATH; + } + + @Override public void serverJoinNotify(String serverAddress) { + + } + + @Override public void serverQuitNotify(String serverAddress) { + + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java new file mode 100644 index 000000000000..ad47eeff3e77 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java @@ -0,0 +1,258 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es; + +import java.util.Properties; +import java.util.UUID; +import org.apache.skywalking.apm.collector.client.ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationEsCacheDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.SegmentCostEsUIDAO; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.storage.StorageException; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchStorageInstaller; +import org.apache.skywalking.apm.collector.storage.es.dao.AlertingListEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationComponentEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationComponentEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationEsRegisterDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationMappingEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationMappingEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationReferenceMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationReferenceMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.CpuMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.CpuMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.GCMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.GCMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.GlobalTraceEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.GlobalTraceEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.InstanceEsCacheDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.InstanceEsRegisterDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.InstanceEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.InstanceHeartBeatEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.InstanceMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.InstanceMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.MemoryMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.MemoryMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.SegmentCostEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.SegmentEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.SegmentEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceEntryEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceEntryEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceNameEsCacheDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceNameEsRegisterDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceReferenceEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ServiceReferenceMetricEsPersistenceDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class StorageModuleEsProvider extends ModuleProvider { + + private final Logger logger = LoggerFactory.getLogger(StorageModuleEsProvider.class); + + public static final String NAME = "elasticsearch"; + private static final String CLUSTER_NAME = "cluster_name"; + private static final String CLUSTER_TRANSPORT_SNIFFER = "cluster_transport_sniffer"; + private static final String CLUSTER_NODES = "cluster_nodes"; + private static final String INDEX_SHARDS_NUMBER = "index_shards_number"; + private static final String INDEX_REPLICAS_NUMBER = "index_replicas_number"; + private static final String TIME_TO_LIVE_OF_DATA = "ttl"; + + private ElasticSearchClient elasticSearchClient; + private DataTTLKeeperTimer deleteTimer; + + @Override public String name() { + return NAME; + } + + @Override public Class module() { + return StorageModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + String clusterName = config.getProperty(CLUSTER_NAME); + Boolean clusterTransportSniffer = (Boolean)config.get(CLUSTER_TRANSPORT_SNIFFER); + String clusterNodes = config.getProperty(CLUSTER_NODES); + elasticSearchClient = new ElasticSearchClient(clusterName, clusterTransportSniffer, clusterNodes); + + this.registerServiceImplementation(IBatchDAO.class, new BatchEsDAO(elasticSearchClient)); + registerCacheDAO(); + registerRegisterDAO(); + registerPersistenceDAO(); + registerUiDAO(); + registerAlertingDAO(); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + Integer indexShardsNumber = (Integer)config.get(INDEX_SHARDS_NUMBER); + Integer indexReplicasNumber = (Integer)config.get(INDEX_REPLICAS_NUMBER); + try { + elasticSearchClient.initialize(); + + ElasticSearchStorageInstaller installer = new ElasticSearchStorageInstaller(indexShardsNumber, indexReplicasNumber); + installer.install(elasticSearchClient); + } catch (ClientException | StorageException e) { + logger.error(e.getMessage(), e); + } + + String uuId = UUID.randomUUID().toString(); + ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); + moduleRegisterService.register(StorageModule.NAME, this.name(), new StorageModuleEsRegistration(uuId, 0)); + + StorageModuleEsNamingListener namingListener = new StorageModuleEsNamingListener(); + ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); + moduleListenerService.addListener(namingListener); + + Integer beforeDay = (Integer)config.getOrDefault(TIME_TO_LIVE_OF_DATA, 3); + deleteTimer = new DataTTLKeeperTimer(getManager(), namingListener, uuId + 0, beforeDay); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + deleteTimer.start(); + } + + @Override public String[] requiredModules() { + return new String[] {ClusterModule.NAME}; + } + + private void registerCacheDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IApplicationCacheDAO.class, new ApplicationEsCacheDAO(elasticSearchClient)); + this.registerServiceImplementation(IInstanceCacheDAO.class, new InstanceEsCacheDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceNameCacheDAO.class, new ServiceNameEsCacheDAO(elasticSearchClient)); + } + + private void registerRegisterDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IApplicationRegisterDAO.class, new ApplicationEsRegisterDAO(elasticSearchClient)); + this.registerServiceImplementation(IInstanceRegisterDAO.class, new InstanceEsRegisterDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceNameRegisterDAO.class, new ServiceNameEsRegisterDAO(elasticSearchClient)); + } + + private void registerPersistenceDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(ICpuMetricPersistenceDAO.class, new CpuMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IGCMetricPersistenceDAO.class, new GCMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IMemoryMetricPersistenceDAO.class, new MemoryMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IMemoryPoolMetricPersistenceDAO.class, new MemoryPoolMetricEsPersistenceDAO(elasticSearchClient)); + + this.registerServiceImplementation(IGlobalTracePersistenceDAO.class, new GlobalTraceEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IInstanceMetricPersistenceDAO.class, new InstanceMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationComponentPersistenceDAO.class, new ApplicationComponentEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationMappingPersistenceDAO.class, new ApplicationMappingEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationMetricPersistenceDAO.class, new ApplicationMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationReferenceMetricPersistenceDAO.class, new ApplicationReferenceMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(ISegmentCostPersistenceDAO.class, new SegmentCostEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(ISegmentPersistenceDAO.class, new SegmentEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceEntryPersistenceDAO.class, new ServiceEntryEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceMetricPersistenceDAO.class, new ServiceMetricEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceReferenceMetricPersistenceDAO.class, new ServiceReferenceMetricEsPersistenceDAO(elasticSearchClient)); + + this.registerServiceImplementation(IInstanceHeartBeatPersistenceDAO.class, new InstanceHeartBeatEsPersistenceDAO(elasticSearchClient)); + } + + private void registerUiDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IInstanceUIDAO.class, new InstanceEsUIDAO(elasticSearchClient)); + + this.registerServiceImplementation(ICpuMetricUIDAO.class, new CpuMetricEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IGCMetricUIDAO.class, new GCMetricEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IMemoryMetricUIDAO.class, new MemoryMetricEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IMemoryPoolMetricUIDAO.class, new MemoryPoolMetricEsUIDAO(elasticSearchClient)); + + this.registerServiceImplementation(IGlobalTraceUIDAO.class, new GlobalTraceEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IInstanceMetricUIDAO.class, new InstanceMetricEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(ISegmentCostUIDAO.class, new SegmentCostEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceEntryUIDAO.class, new ServiceEntryEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceEsUIDAO(elasticSearchClient)); + } + + private void registerAlertingDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IAlertingListPersistenceDAO.class, new AlertingListEsPersistenceDAO(elasticSearchClient)); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java new file mode 100644 index 000000000000..454a046a0af2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es; + +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; + +/** + * @author peng-yongsheng + */ +public class StorageModuleEsRegistration extends ModuleRegistration { + + private final String virtualHost; + private final int virtualPort; + + StorageModuleEsRegistration(String virtualHost, int virtualPort) { + this.virtualHost = virtualHost; + this.virtualPort = virtualPort; + } + + @Override public Value buildValue() { + return new Value(this.virtualHost, virtualPort, Const.EMPTY_STRING); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java new file mode 100644 index 000000000000..05fe0776ea0c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.base.dao; + +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.elasticsearch.action.bulk.BulkRequestBuilder; +import org.elasticsearch.action.bulk.BulkResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class BatchEsDAO extends EsDAO implements IBatchDAO { + + private final Logger logger = LoggerFactory.getLogger(BatchEsDAO.class); + + public BatchEsDAO(ElasticSearchClient client) { + super(client); + } + + @Override public void batchPersistence(List batchCollection) { + BulkRequestBuilder bulkRequest = getClient().prepareBulk(); + + logger.debug("bulk data size: {}", batchCollection.size()); + if (CollectionUtils.isNotEmpty(batchCollection)) { + for (int i = 0; i < batchCollection.size(); i++) { + Object builder = batchCollection.get(i); + if (builder instanceof IndexRequestBuilder) { + bulkRequest.add((IndexRequestBuilder)builder); + } + if (builder instanceof UpdateRequestBuilder) { + bulkRequest.add((UpdateRequestBuilder)builder); + } + } + + BulkResponse bulkResponse = bulkRequest.execute().actionGet(); + if (bulkResponse.hasFailures()) { + logger.error(bulkResponse.buildFailureMessage()); + } + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/EsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/EsDAO.java new file mode 100644 index 000000000000..d66ce35b7955 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/dao/EsDAO.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.base.dao; + +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.metrics.max.Max; +import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; +import org.elasticsearch.search.aggregations.metrics.min.Min; +import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.base.dao.AbstractDAO; + +/** + * @author peng-yongsheng + */ +public abstract class EsDAO extends AbstractDAO { + + public EsDAO(ElasticSearchClient client) { + super(client); + } + + public final int getMaxId(String indexName, String columnName) { + ElasticSearchClient client = getClient(); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName); + searchRequestBuilder.setTypes("type"); + searchRequestBuilder.setSize(0); + MaxAggregationBuilder aggregation = AggregationBuilders.max("agg").field(columnName); + searchRequestBuilder.addAggregation(aggregation); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + Max agg = searchResponse.getAggregations().get("agg"); + + int id = (int)agg.getValue(); + if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) { + return 0; + } else { + return id; + } + } + + public final int getMinId(String indexName, String columnName) { + ElasticSearchClient client = getClient(); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName); + searchRequestBuilder.setTypes("type"); + searchRequestBuilder.setSize(0); + MinAggregationBuilder aggregation = AggregationBuilders.min("agg").field(columnName); + searchRequestBuilder.addAggregation(aggregation); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + Min agg = searchResponse.getAggregations().get("agg"); + + int id = (int)agg.getValue(); + if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) { + return 0; + } else { + return id; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java new file mode 100644 index 000000000000..c5bc2570eac9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.base.define; + +import org.apache.skywalking.apm.collector.core.data.ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class ElasticSearchColumnDefine extends ColumnDefine { + public ElasticSearchColumnDefine(String name, String type) { + super(name, type); + } + + public enum Type { + Binary, Boolean, Keyword, Long, Integer, Double, Text + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java similarity index 81% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java index 5d3457916c19..b745d26257e2 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchStorageInstaller.java @@ -16,19 +16,37 @@ * */ -package org.skywalking.apm.collector.storage.es.base.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.base.define; import java.io.IOException; import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.StorageInstaller; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexNotFoundException; -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.StorageInstaller; -import org.skywalking.apm.collector.core.data.ColumnDefine; -import org.skywalking.apm.collector.core.data.TableDefine; +import org.apache.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.core.data.ColumnDefine; +import org.apache.skywalking.apm.collector.core.data.TableDefine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java new file mode 100644 index 000000000000..6744003a01d5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.base.define; + +import org.apache.skywalking.apm.collector.core.data.TableDefine; + +/** + * @author peng-yongsheng + */ +public abstract class ElasticSearchTableDefine extends TableDefine { + + public ElasticSearchTableDefine(String name) { + super(name); + } + + public final String type() { + return "type"; + } + + public abstract int refreshInterval(); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java similarity index 78% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java index 2d8b004c4035..888c74c3cc4e 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/AlertingListEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.alerting.AlertingList; -import org.skywalking.apm.collector.storage.table.alerting.AlertingListTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingList; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingListTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java index e612eefe871d..03759a97e8a7 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsPersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; @@ -25,12 +43,12 @@ import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java similarity index 77% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java index 2afb35ff55e6..cfe0733f6ed3 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java @@ -16,20 +16,38 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java new file mode 100644 index 000000000000..bcc622f8fde6 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import org.elasticsearch.action.get.GetRequestBuilder; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationEsCacheDAO extends EsDAO implements IApplicationCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationEsCacheDAO.class); + + public ApplicationEsCacheDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getApplicationId(String applicationCode) { + ElasticSearchClient client = getClient(); + + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ApplicationTable.TABLE); + searchRequestBuilder.setTypes("type"); + searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); + searchRequestBuilder.setQuery(QueryBuilders.termQuery(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode)); + searchRequestBuilder.setSize(1); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + if (searchResponse.getHits().totalHits > 0) { + SearchHit searchHit = searchResponse.getHits().iterator().next(); + return (int)searchHit.getSource().get(ApplicationTable.COLUMN_APPLICATION_ID); + } + return 0; + } + + @Override public String getApplicationCode(int applicationId) { + logger.debug("get application code, applicationId: {}", applicationId); + ElasticSearchClient client = getClient(); + GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId)); + + GetResponse getResponse = getRequestBuilder.get(); + if (getResponse.isExists()) { + return (String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE); + } + return Const.EMPTY_STRING; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java new file mode 100644 index 000000000000..de12263fce1a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.support.WriteRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationEsRegisterDAO extends EsDAO implements IApplicationRegisterDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationEsRegisterDAO.class); + + public ApplicationEsRegisterDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getMaxApplicationId() { + return getMaxId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + } + + @Override public int getMinApplicationId() { + return getMinId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + } + + @Override public void save(Application application) { + logger.debug("save application register info, application getId: {}, application code: {}", application.getId(), application.getApplicationCode()); + ElasticSearchClient client = getClient(); + Map source = new HashMap<>(); + source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode()); + source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId()); + + IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); + logger.debug("save application register info, application getId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name()); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java index 474dd69142d3..0e5d9cd62b5a 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java index 5deed9e0bc05..957c7289526c 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java @@ -16,20 +16,38 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java similarity index 87% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java index 0d86273207b7..c862875ac137 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMetricEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetric; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetricTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java similarity index 88% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java index 93198bc74047..55c63e431256 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java similarity index 85% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java index 38633f1367ad..4db1b263372f 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java @@ -16,19 +16,37 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java new file mode 100644 index 000000000000..8d28e72ffe4a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class CpuMetricEsPersistenceDAO extends EsDAO implements ICpuMetricPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(CpuMetricEsPersistenceDAO.class); + + public CpuMetricEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public CpuMetric get(String id) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(CpuMetric cpuMetric) { + Map source = new HashMap<>(); + source.put(CpuMetricTable.COLUMN_INSTANCE_ID, cpuMetric.getInstanceId()); + source.put(CpuMetricTable.COLUMN_USAGE_PERCENT, cpuMetric.getUsagePercent()); + source.put(CpuMetricTable.COLUMN_TIME_BUCKET, cpuMetric.getTimeBucket()); + + logger.debug("prepare cpu metric batch insert, getId: {}", cpuMetric.getId()); + return getClient().prepareIndex(CpuMetricTable.TABLE, cpuMetric.getId()).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(CpuMetric cpuMetric) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(CpuMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(CpuMetricTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, CpuMetricTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java new file mode 100644 index 000000000000..1c8313679d1e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; + +/** + * @author peng-yongsheng + */ +public class CpuMetricEsUIDAO extends EsDAO implements ICpuMetricUIDAO { + + public CpuMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getMetric(int instanceId, long timeBucket) { + String id = timeBucket + Const.ID_SPLIT + instanceId; + GetResponse getResponse = getClient().prepareGet(CpuMetricTable.TABLE, id).get(); + + if (getResponse.isExists()) { + return ((Number)getResponse.getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).intValue(); + } + return 0; + } + + @Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + + long timeBucket = startTimeBucket; + do { + timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); + String id = timeBucket + Const.ID_SPLIT + instanceId; + prepareMultiGet.add(CpuMetricTable.TABLE, CpuMetricTable.TABLE_TYPE, id); + } + while (timeBucket <= endTimeBucket); + + JsonArray metrics = new JsonArray(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + double cpuUsed = ((Number)response.getResponse().getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).doubleValue(); + metrics.add((int)(cpuUsed * 100)); + } else { + metrics.add(0); + } + } + return metrics; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java new file mode 100644 index 000000000000..c68e7813d01b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GCMetricEsPersistenceDAO extends EsDAO implements IGCMetricPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(GCMetricEsPersistenceDAO.class); + + public GCMetricEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public GCMetric get(String id) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(GCMetric gcMetric) { + Map source = new HashMap<>(); + source.put(GCMetricTable.COLUMN_INSTANCE_ID, gcMetric.getInstanceId()); + source.put(GCMetricTable.COLUMN_PHRASE, gcMetric.getPhrase()); + source.put(GCMetricTable.COLUMN_COUNT, gcMetric.getCount()); + source.put(GCMetricTable.COLUMN_TIME, gcMetric.getTime()); + source.put(GCMetricTable.COLUMN_TIME_BUCKET, gcMetric.getTimeBucket()); + + return getClient().prepareIndex(GCMetricTable.TABLE, gcMetric.getId()).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(GCMetric gcMetric) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(GCMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(GCMetricTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, GCMetricTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java similarity index 83% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java index d474c4f6ce40..96c7ca1706da 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java @@ -16,10 +16,31 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetItemResponse; import org.elasticsearch.action.get.MultiGetRequestBuilder; @@ -32,13 +53,10 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.metrics.sum.Sum; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable; -import org.skywalking.apm.network.proto.GCPhrase; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.network.proto.GCPhrase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java new file mode 100644 index 000000000000..caaa1c3f5f16 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTrace; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceEsPersistenceDAO extends EsDAO implements IGlobalTracePersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsPersistenceDAO.class); + + public GlobalTraceEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public GlobalTrace get(String id) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(GlobalTrace data) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public IndexRequestBuilder prepareBatchInsert(GlobalTrace data) { + Map source = new HashMap<>(); + source.put(GlobalTraceTable.COLUMN_SEGMENT_ID, data.getSegmentId()); + source.put(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, data.getGlobalTraceId()); + source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + logger.debug("global trace source: {}", source.toString()); + return getClient().prepareIndex(GlobalTraceTable.TABLE, data.getId()).setSource(source); + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(GlobalTraceTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(GlobalTraceTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, GlobalTraceTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java new file mode 100644 index 000000000000..9229d2d0d544 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceEsUIDAO extends EsDAO implements IGlobalTraceUIDAO { + + private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsUIDAO.class); + + public GlobalTraceEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public List getGlobalTraceId(String segmentId) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE); + searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_SEGMENT_ID, segmentId)); + searchRequestBuilder.setSize(10); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List globalTraceIds = new ArrayList<>(); + SearchHit[] searchHits = searchResponse.getHits().getHits(); + for (SearchHit searchHit : searchHits) { + String globalTraceId = (String)searchHit.getSource().get(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID); + logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); + globalTraceIds.add(globalTraceId); + } + return globalTraceIds; + } + + @Override public List getSegmentIds(String globalTraceId) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE); + searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraceId)); + searchRequestBuilder.setSize(10); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List segmentIds = new ArrayList<>(); + SearchHit[] searchHits = searchResponse.getHits().getHits(); + for (SearchHit searchHit : searchHits) { + String segmentId = (String)searchHit.getSource().get(GlobalTraceTable.COLUMN_SEGMENT_ID); + logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); + segmentIds.add(segmentId); + } + return segmentIds; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java new file mode 100644 index 000000000000..d5f3e379afb4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceEsCacheDAO extends EsDAO implements IInstanceCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceEsCacheDAO.class); + + public InstanceEsCacheDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getApplicationId(int instanceId) { + GetResponse response = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(instanceId)).get(); + if (response.isExists()) { + return (int)response.getSource().get(InstanceTable.COLUMN_APPLICATION_ID); + } else { + return 0; + } + } + + @Override public int getInstanceId(int applicationId, String agentUUID) { + ElasticSearchClient client = getClient(); + + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(InstanceTable.TABLE); + searchRequestBuilder.setTypes("type"); + searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); + BoolQueryBuilder builder = QueryBuilders.boolQuery(); + builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId)); + builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_AGENT_UUID, agentUUID)); + searchRequestBuilder.setQuery(builder); + searchRequestBuilder.setSize(1); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + if (searchResponse.getHits().totalHits > 0) { + SearchHit searchHit = searchResponse.getHits().iterator().next(); + return (int)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java new file mode 100644 index 000000000000..adbf2137cffe --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.action.update.UpdateRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceEsRegisterDAO extends EsDAO implements IInstanceRegisterDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceEsRegisterDAO.class); + + public InstanceEsRegisterDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getMaxInstanceId() { + return getMaxId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public int getMinInstanceId() { + return getMinId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public void save(Instance instance) { + logger.debug("save instance register info, application getId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID()); + ElasticSearchClient client = getClient(); + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId()); + source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId()); + source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID()); + source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime()); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime()); + source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo()); + + IndexResponse response = client.prepareIndex(InstanceTable.TABLE, instance.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); + logger.debug("save instance register info, application getId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name()); + } + + @Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) { + ElasticSearchClient client = getClient(); + UpdateRequest updateRequest = new UpdateRequest(); + updateRequest.index(InstanceTable.TABLE); + updateRequest.type("type"); + updateRequest.id(String.valueOf(instanceId)); + updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartbeatTime); + + updateRequest.doc(source); + client.update(updateRequest); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java similarity index 86% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java index 3e0b64639e3a..1a4eef126582 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java @@ -16,12 +16,34 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.LinkedList; import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; import org.elasticsearch.action.get.GetRequestBuilder; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchRequestBuilder; @@ -37,12 +59,8 @@ import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortMode; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java new file mode 100644 index 000000000000..baae618aa827 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceHeartBeatEsPersistenceDAO extends EsDAO implements IInstanceHeartBeatPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatEsPersistenceDAO.class); + + public InstanceHeartBeatEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public Instance get(String id) { + GetResponse getResponse = getClient().prepareGet(InstanceTable.TABLE, id).get(); + if (getResponse.isExists()) { + Instance instance = new Instance(id); + Map source = getResponse.getSource(); + instance.setInstanceId((Integer)source.get(InstanceTable.COLUMN_INSTANCE_ID)); + instance.setHeartBeatTime((Long)source.get(InstanceTable.COLUMN_HEARTBEAT_TIME)); + logger.debug("getId: {} is exists", id); + return instance; + } else { + logger.debug("getId: {} is not exists", id); + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(Instance data) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Instance data) { + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, data.getHeartBeatTime()); + return getClient().prepareUpdate(InstanceTable.TABLE, data.getId()).setDoc(source); + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java similarity index 86% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java index e779f5c7ba59..ad0354fac217 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetric; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java similarity index 83% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java index 75d2ede710c0..457a23c0264d 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java @@ -16,9 +16,30 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetItemResponse; import org.elasticsearch.action.get.MultiGetRequestBuilder; @@ -31,12 +52,9 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.metrics.sum.Sum; import org.elasticsearch.search.sort.SortOrder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java new file mode 100644 index 000000000000..d1cf6a183fae --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetric; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricEsPersistenceDAO extends EsDAO implements IMemoryMetricPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(MemoryMetricEsPersistenceDAO.class); + + public MemoryMetricEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public MemoryMetric get(String id) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(MemoryMetric data) { + Map source = new HashMap<>(); + source.put(MemoryMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); + source.put(MemoryMetricTable.COLUMN_IS_HEAP, data.getIsHeap()); + source.put(MemoryMetricTable.COLUMN_INIT, data.getInit()); + source.put(MemoryMetricTable.COLUMN_MAX, data.getMax()); + source.put(MemoryMetricTable.COLUMN_USED, data.getUsed()); + source.put(MemoryMetricTable.COLUMN_COMMITTED, data.getCommitted()); + source.put(MemoryMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + return getClient().prepareIndex(MemoryMetricTable.TABLE, data.getId()).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(MemoryMetric data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(MemoryMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(MemoryMetricTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, MemoryMetricTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java new file mode 100644 index 000000000000..9d2e5aab665e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricEsUIDAO extends EsDAO implements IMemoryMetricUIDAO { + + public MemoryMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) { + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; + GetResponse getResponse = getClient().prepareGet(MemoryMetricTable.TABLE, id).get(); + + JsonObject metric = new JsonObject(); + if (getResponse.isExists()) { + metric.addProperty("max", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_MAX)).intValue()); + metric.addProperty("init", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_INIT)).intValue()); + metric.addProperty("used", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_USED)).intValue()); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + metric.addProperty("used", 0); + } + return metric; + } + + @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + + int i = 0; + long timeBucket = startTimeBucket; + do { + timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; + prepareMultiGet.add(MemoryMetricTable.TABLE, MemoryMetricTable.TABLE_TYPE, id); + } + while (timeBucket <= endTimeBucket); + + JsonObject metric = new JsonObject(); + JsonArray usedMetric = new JsonArray(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_MAX)).longValue()); + metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_INIT)).longValue()); + usedMetric.add(((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_USED)).longValue()); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + usedMetric.add(0); + } + } + metric.add("used", usedMetric); + return metric; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java new file mode 100644 index 000000000000..bed6c83214c1 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricEsPersistenceDAO extends EsDAO implements IMemoryPoolMetricPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(MemoryPoolMetricEsPersistenceDAO.class); + + public MemoryPoolMetricEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public MemoryPoolMetric get(String id) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(MemoryPoolMetric data) { + Map source = new HashMap<>(); + source.put(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); + source.put(MemoryPoolMetricTable.COLUMN_POOL_TYPE, data.getPoolType()); + source.put(MemoryPoolMetricTable.COLUMN_INIT, data.getInit()); + source.put(MemoryPoolMetricTable.COLUMN_MAX, data.getMax()); + source.put(MemoryPoolMetricTable.COLUMN_USED, data.getUsed()); + source.put(MemoryPoolMetricTable.COLUMN_COMMITTED, data.getCommitted()); + source.put(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + return getClient().prepareIndex(MemoryPoolMetricTable.TABLE, data.getId()).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(MemoryPoolMetric data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(MemoryPoolMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(MemoryPoolMetricTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, MemoryPoolMetricTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java new file mode 100644 index 000000000000..8bf4d8f85860 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricEsUIDAO extends EsDAO implements IMemoryPoolMetricUIDAO { + + public MemoryPoolMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public JsonObject getMetric(int instanceId, long timeBucket, int poolType) { + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; + GetResponse getResponse = getClient().prepareGet(MemoryPoolMetricTable.TABLE, id).get(); + + JsonObject metric = new JsonObject(); + if (getResponse.isExists()) { + metric.addProperty("max", ((Number)getResponse.getSource().get(MemoryPoolMetricTable.COLUMN_MAX)).intValue()); + metric.addProperty("init", ((Number)getResponse.getSource().get(MemoryPoolMetricTable.COLUMN_INIT)).intValue()); + metric.addProperty("used", ((Number)getResponse.getSource().get(MemoryPoolMetricTable.COLUMN_USED)).intValue()); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + metric.addProperty("used", 0); + } + return metric; + } + + @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + + long timeBucket = startTimeBucket; + do { + timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; + prepareMultiGet.add(MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.TABLE_TYPE, id); + } + while (timeBucket <= endTimeBucket); + + JsonObject metric = new JsonObject(); + JsonArray usedMetric = new JsonArray(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_MAX)).longValue()); + metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_INIT)).longValue()); + usedMetric.add(((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_USED)).longValue()); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + usedMetric.add(0); + } + } + metric.add("used", usedMetric); + return metric; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java new file mode 100644 index 000000000000..0f3199e44000 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentCostEsPersistenceDAO extends EsDAO implements ISegmentCostPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentCostEsPersistenceDAO.class); + + public SegmentCostEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public SegmentCost get(String id) { + return null; + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(SegmentCost data) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(SegmentCost data) { + logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId()); + Map source = new HashMap<>(); + source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getSegmentId()); + source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getApplicationId()); + source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getServiceName()); + source.put(SegmentCostTable.COLUMN_COST, data.getCost()); + source.put(SegmentCostTable.COLUMN_START_TIME, data.getStartTime()); + source.put(SegmentCostTable.COLUMN_END_TIME, data.getEndTime()); + source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getIsError()); + source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + logger.debug("segment cost source: {}", source.toString()); + return getClient().prepareIndex(SegmentCostTable.TABLE, data.getId()).setSource(source); + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(SegmentCostTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, SegmentCostTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java similarity index 81% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java index f1eba1c9e661..255bfc01a6d0 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java @@ -16,11 +16,30 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -30,12 +49,11 @@ import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortOrder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java new file mode 100644 index 000000000000..e6ac4ee3e99e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.Segment; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentEsPersistenceDAO extends EsDAO implements ISegmentPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentEsPersistenceDAO.class); + + public SegmentEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public Segment get(String id) { + return null; + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Segment data) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(Segment data) { + Map source = new HashMap<>(); + source.put(SegmentTable.COLUMN_DATA_BINARY, new String(Base64.getEncoder().encode(data.getDataBinary()))); + source.put(SegmentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + logger.debug("segment source: {}", source.toString()); + return getClient().prepareIndex(SegmentTable.TABLE, data.getId()).setSource(source); + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); + long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); + BulkByScrollResponse response = getClient().prepareDelete() + .filter(QueryBuilders.rangeQuery(SegmentTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(SegmentTable.TABLE) + .get(); + + long deleted = response.getDeleted(); + logger.info("Delete {} rows history from {} index.", deleted, SegmentTable.TABLE); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java new file mode 100644 index 000000000000..fdceba21caba --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import com.google.protobuf.InvalidProtocolBufferException; +import java.util.Base64; +import java.util.Map; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.elasticsearch.action.get.GetResponse; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentEsUIDAO extends EsDAO implements ISegmentUIDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentEsUIDAO.class); + + public SegmentEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public TraceSegmentObject load(String segmentId) { + GetResponse response = getClient().prepareGet(SegmentTable.TABLE, segmentId).get(); + Map source = response.getSource(); + String dataBinaryBase64 = (String)source.get(SegmentTable.COLUMN_DATA_BINARY); + if (StringUtils.isNotEmpty(dataBinaryBase64)) { + byte[] dataBinary = Base64.getDecoder().decode(dataBinaryBase64); + try { + return TraceSegmentObject.parseFrom(dataBinary); + } catch (InvalidProtocolBufferException e) { + logger.error(e.getMessage(), e); + } + } + return null; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java new file mode 100644 index 000000000000..b98a3a61505d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryEsPersistenceDAO extends EsDAO implements IServiceEntryPersistenceDAO { + + public ServiceEntryEsPersistenceDAO(ElasticSearchClient client) { + super(client); + } + + @Override public ServiceEntry get(String id) { + GetResponse getResponse = getClient().prepareGet(ServiceEntryTable.TABLE, id).get(); + if (getResponse.isExists()) { + ServiceEntry serviceEntry = new ServiceEntry(id); + Map source = getResponse.getSource(); + serviceEntry.setApplicationId(((Number)source.get(ServiceEntryTable.COLUMN_APPLICATION_ID)).intValue()); + serviceEntry.setEntryServiceId(((Number)source.get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID)).intValue()); + serviceEntry.setEntryServiceName((String)source.get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME)); + serviceEntry.setRegisterTime(((Number)source.get(ServiceEntryTable.COLUMN_REGISTER_TIME)).longValue()); + serviceEntry.setNewestTime(((Number)source.get(ServiceEntryTable.COLUMN_NEWEST_TIME)).longValue()); + return serviceEntry; + } else { + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(ServiceEntry data) { + Map source = new HashMap<>(); + source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getApplicationId()); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getEntryServiceId()); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getEntryServiceName()); + source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getRegisterTime()); + source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getNewestTime()); + return getClient().prepareIndex(ServiceEntryTable.TABLE, data.getId()).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(ServiceEntry data) { + Map source = new HashMap<>(); + source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getApplicationId()); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getEntryServiceId()); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getEntryServiceName()); + source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getRegisterTime()); + source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getNewestTime()); + + return getClient().prepareUpdate(ServiceEntryTable.TABLE, data.getId()).setDoc(source); + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java similarity index 76% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java index 51184774fe63..db1017884e1b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceEntryEsUIDAO.java @@ -16,10 +16,31 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -29,12 +50,9 @@ import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; +import org.apache.skywalking.apm.collector.core.util.StringUtils; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java similarity index 85% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java index 88f505bd3e71..157f4f7594d2 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceMetricEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetric; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceMetric; -import org.skywalking.apm.collector.storage.table.service.ServiceMetricTable; +import org.apache.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java new file mode 100644 index 000000000000..31d15acc765d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.elasticsearch.action.get.GetRequestBuilder; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; + +/** + * @author peng-yongsheng + */ +public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO { + + public ServiceNameEsCacheDAO(ElasticSearchClient client) { + super(client); + } + + @Override public String getServiceName(int serviceId) { + GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId)); + + GetResponse getResponse = getRequestBuilder.get(); + if (getResponse.isExists()) { + String serviceName = (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME); + int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue(); + return applicationId + Const.ID_SPLIT + serviceName; + } + return Const.EMPTY_STRING; + } + + @Override public int getServiceId(int applicationId, String serviceName) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE); + searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId)); + boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName)); + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(1); + + SearchResponse searchResponse = searchRequestBuilder.get(); + if (searchResponse.getHits().totalHits > 0) { + SearchHit searchHit = searchResponse.getHits().iterator().next(); + return (int)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java new file mode 100644 index 000000000000..da6ba17adf5c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.support.WriteRequest; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameEsRegisterDAO extends EsDAO implements IServiceNameRegisterDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameEsRegisterDAO.class); + + public ServiceNameEsRegisterDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getMaxServiceId() { + return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override public int getMinServiceId() { + return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override public void save(ServiceName serviceName) { + logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName()); + ElasticSearchClient client = getClient(); + Map source = new HashMap<>(); + source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId()); + source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId()); + source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName()); + + IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, serviceName.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); + logger.debug("save service name register info, application getId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name()); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java similarity index 84% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java index f48f998922e7..7ca306531e72 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java @@ -16,11 +16,33 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import com.google.gson.JsonObject; import java.util.LinkedHashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -29,12 +51,8 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.metrics.sum.Sum; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java similarity index 87% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java index d0451f1f7613..363e7df11c0b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceMetricEsPersistenceDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.es.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.dao; import java.util.HashMap; import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java new file mode 100644 index 000000000000..a02bb3a4e8ca --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingListTable; + +/** + * @author peng-yongsheng + */ +public class AlertingListEsTableDefine extends ElasticSearchTableDefine { + + public AlertingListEsTableDefine() { + super(AlertingListTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_LAYER, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_LAYER_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_FIRST_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_LAST_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_EXPECTED, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_ACTUAL, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_VALID, ElasticSearchColumnDefine.Type.Boolean.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java new file mode 100644 index 000000000000..858959ab9b96 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentEsTableDefine extends ElasticSearchTableDefine { + + public ApplicationComponentEsTableDefine() { + super(ApplicationComponentTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java new file mode 100644 index 000000000000..ac4286205cc5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationEsTableDefine extends ElasticSearchTableDefine { + + public ApplicationEsTableDefine() { + super(ApplicationTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_APPLICATION_CODE, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java new file mode 100644 index 000000000000..fdd5ea0fd9bb --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingEsTableDefine extends ElasticSearchTableDefine { + + public ApplicationMappingEsTableDefine() { + super(ApplicationMappingTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java similarity index 77% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java index 4cef15ae0687..2ac8bded2172 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ApplicationReferenceMetricEsTableDefine.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.storage.es.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java new file mode 100644 index 000000000000..c591af852bad --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; + +/** + * @author peng-yongsheng + */ +public class CpuMetricEsTableDefine extends ElasticSearchTableDefine { + + public CpuMetricEsTableDefine() { + super(CpuMetricTable.TABLE); + } + + @Override public int refreshInterval() { + return 1; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_USAGE_PERCENT, ElasticSearchColumnDefine.Type.Double.name())); + addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java new file mode 100644 index 000000000000..de4856d4c5ae --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; + +/** + * @author peng-yongsheng + */ +public class GCMetricEsTableDefine extends ElasticSearchTableDefine { + + public GCMetricEsTableDefine() { + super(GCMetricTable.TABLE); + } + + @Override public int refreshInterval() { + return 1; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_PHRASE, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_COUNT, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java new file mode 100644 index 000000000000..af4d2447aef2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceEsTableDefine extends ElasticSearchTableDefine { + + public GlobalTraceEsTableDefine() { + super(GlobalTraceTable.TABLE); + } + + @Override public int refreshInterval() { + return 5; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(GlobalTraceTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(GlobalTraceTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java new file mode 100644 index 000000000000..46a84604b9d4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; + +/** + * @author peng-yongsheng + */ +public class InstanceEsTableDefine extends ElasticSearchTableDefine { + + public InstanceEsTableDefine() { + super(InstanceTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_AGENT_UUID, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_REGISTER_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_HEARTBEAT_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_OS_INFO, ElasticSearchColumnDefine.Type.Keyword.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java new file mode 100644 index 000000000000..c27325224bf7 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricEsTableDefine extends ElasticSearchTableDefine { + + public InstanceMetricEsTableDefine() { + super(InstanceMetricTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + + addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java new file mode 100644 index 000000000000..04b98bfd9478 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricEsTableDefine extends ElasticSearchTableDefine { + + public MemoryMetricEsTableDefine() { + super(MemoryMetricTable.TABLE); + } + + @Override public int refreshInterval() { + return 1; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_IS_HEAP, ElasticSearchColumnDefine.Type.Boolean.name())); + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_INIT, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_MAX, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_USED, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_COMMITTED, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java new file mode 100644 index 000000000000..9f1a30a11909 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricEsTableDefine extends ElasticSearchTableDefine { + + public MemoryPoolMetricEsTableDefine() { + super(MemoryPoolMetricTable.TABLE); + } + + @Override public int refreshInterval() { + return 1; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_POOL_TYPE, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_INIT, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_MAX, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_USED, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_COMMITTED, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java new file mode 100644 index 000000000000..9a6727634020 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; + +/** + * @author peng-yongsheng + */ +public class SegmentCostEsTableDefine extends ElasticSearchTableDefine { + + public SegmentCostEsTableDefine() { + super(SegmentCostTable.TABLE); + } + + @Override public int refreshInterval() { + return 5; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_COST, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_START_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_END_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_IS_ERROR, ElasticSearchColumnDefine.Type.Boolean.name())); + addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java new file mode 100644 index 000000000000..dd37180d7c90 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; + +/** + * @author peng-yongsheng + */ +public class SegmentEsTableDefine extends ElasticSearchTableDefine { + + public SegmentEsTableDefine() { + super(SegmentTable.TABLE); + } + + @Override public int refreshInterval() { + return 10; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(SegmentTable.COLUMN_DATA_BINARY, ElasticSearchColumnDefine.Type.Binary.name())); + addColumn(new ElasticSearchColumnDefine(SegmentTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java new file mode 100644 index 000000000000..c4316c63d103 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryEsTableDefine extends ElasticSearchTableDefine { + + public ServiceEntryEsTableDefine() { + super(ServiceEntryTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); + addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_REGISTER_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_NEWEST_TIME, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java new file mode 100644 index 000000000000..209f6bdcaf91 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricEsTableDefine extends ElasticSearchTableDefine { + + public ServiceMetricEsTableDefine() { + super(ServiceMetricTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); + + addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java new file mode 100644 index 000000000000..04ead071f6f5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; + +/** + * @author peng-yongsheng + */ +public class ServiceNameEsTableDefine extends ElasticSearchTableDefine { + + public ServiceNameEsTableDefine() { + super(ServiceNameTable.TABLE); + } + + @Override public int refreshInterval() { + return 2; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java similarity index 76% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java index 736132721a6a..c9e38bb6f293 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/ServiceReferenceMetricEsTableDefine.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.storage.es.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.es.define; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java deleted file mode 100644 index 196128c8d234..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es; - -import java.util.Calendar; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; - -/** - * @author peng-yongsheng - */ -public class DataTTLKeeperTimer { - - private final ModuleManager moduleManager; - private final StorageModuleEsNamingListener namingListener; - private final String selfAddress; - private final int daysBefore; - - public DataTTLKeeperTimer(ModuleManager moduleManager, - StorageModuleEsNamingListener namingListener, String selfAddress, int daysBefore) { - this.moduleManager = moduleManager; - this.namingListener = namingListener; - this.selfAddress = selfAddress; - this.daysBefore = daysBefore; - } - - public void start() { - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::delete, 1, 8, TimeUnit.HOURS); - } - - private void delete() { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - calendar.set(Calendar.DAY_OF_MONTH, -daysBefore); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - - long startTimestamp = calendar.getTimeInMillis(); - - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - long endTimestamp = calendar.getTimeInMillis(); - - deleteJVMRelatedData(startTimestamp, endTimestamp); - deleteTraceRelatedData(startTimestamp, endTimestamp); - } - - private void deleteJVMRelatedData(long startTimestamp, long endTimestamp) { - ICpuMetricPersistenceDAO cpuMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ICpuMetricPersistenceDAO.class); - cpuMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IGCMetricPersistenceDAO gcMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IGCMetricPersistenceDAO.class); - gcMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IMemoryMetricPersistenceDAO memoryMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryMetricPersistenceDAO.class); - memoryMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IMemoryPoolMetricPersistenceDAO memoryPoolMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryPoolMetricPersistenceDAO.class); - memoryPoolMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - } - - private void deleteTraceRelatedData(long startTimestamp, long endTimestamp) { - IGlobalTracePersistenceDAO globalTracePersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTracePersistenceDAO.class); - globalTracePersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IInstanceMetricPersistenceDAO instanceMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceMetricPersistenceDAO.class); - instanceMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IApplicationComponentPersistenceDAO applicationComponentPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentPersistenceDAO.class); - applicationComponentPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IApplicationMappingPersistenceDAO applicationMappingPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingPersistenceDAO.class); - applicationMappingPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IApplicationReferenceMetricPersistenceDAO applicationReferenceMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricPersistenceDAO.class); - applicationReferenceMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - ISegmentCostPersistenceDAO segmentCostPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentCostPersistenceDAO.class); - segmentCostPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - ISegmentPersistenceDAO segmentPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentPersistenceDAO.class); - segmentPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - - IServiceReferenceMetricPersistenceDAO serviceReferencePersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceMetricPersistenceDAO.class); - serviceReferencePersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java deleted file mode 100644 index f9754d3a6e02..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es; - -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.storage.StorageModule; - -/** - * @author peng-yongsheng - */ -public class StorageModuleEsNamingListener extends ClusterModuleListener { - - public static final String PATH = "/" + StorageModule.NAME + "/" + StorageModuleEsProvider.NAME; - - @Override public String path() { - return PATH; - } - - @Override public void serverJoinNotify(String serverAddress) { - - } - - @Override public void serverQuitNotify(String serverAddress) { - - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java deleted file mode 100644 index e25c10797219..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es; - -import java.util.Properties; -import java.util.UUID; -import org.skywalking.apm.collector.client.ClientException; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.storage.StorageException; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchStorageInstaller; -import org.skywalking.apm.collector.storage.es.dao.AlertingListEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationComponentEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationComponentEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationEsCacheDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationEsRegisterDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationMappingEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationMappingEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationReferenceMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ApplicationReferenceMetricEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.CpuMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.CpuMetricEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.GCMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.GCMetricEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.GlobalTraceEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.GlobalTraceEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.InstanceEsCacheDAO; -import org.skywalking.apm.collector.storage.es.dao.InstanceEsRegisterDAO; -import org.skywalking.apm.collector.storage.es.dao.InstanceEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.InstanceHeartBeatEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.InstanceMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.InstanceMetricEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.MemoryMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.MemoryMetricEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.SegmentCostEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.SegmentCostEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.SegmentEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.SegmentEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceEntryEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceEntryEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceMetricEsPersistenceDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceNameEsCacheDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceNameEsRegisterDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceReferenceEsUIDAO; -import org.skywalking.apm.collector.storage.es.dao.ServiceReferenceMetricEsPersistenceDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class StorageModuleEsProvider extends ModuleProvider { - - private final Logger logger = LoggerFactory.getLogger(StorageModuleEsProvider.class); - - public static final String NAME = "elasticsearch"; - private static final String CLUSTER_NAME = "cluster_name"; - private static final String CLUSTER_TRANSPORT_SNIFFER = "cluster_transport_sniffer"; - private static final String CLUSTER_NODES = "cluster_nodes"; - private static final String INDEX_SHARDS_NUMBER = "index_shards_number"; - private static final String INDEX_REPLICAS_NUMBER = "index_replicas_number"; - private static final String TIME_TO_LIVE_OF_DATA = "ttl"; - - private ElasticSearchClient elasticSearchClient; - private DataTTLKeeperTimer deleteTimer; - - @Override public String name() { - return NAME; - } - - @Override public Class module() { - return StorageModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - String clusterName = config.getProperty(CLUSTER_NAME); - Boolean clusterTransportSniffer = (Boolean)config.get(CLUSTER_TRANSPORT_SNIFFER); - String clusterNodes = config.getProperty(CLUSTER_NODES); - elasticSearchClient = new ElasticSearchClient(clusterName, clusterTransportSniffer, clusterNodes); - - this.registerServiceImplementation(IBatchDAO.class, new BatchEsDAO(elasticSearchClient)); - registerCacheDAO(); - registerRegisterDAO(); - registerPersistenceDAO(); - registerUiDAO(); - registerAlertingDAO(); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - Integer indexShardsNumber = (Integer)config.get(INDEX_SHARDS_NUMBER); - Integer indexReplicasNumber = (Integer)config.get(INDEX_REPLICAS_NUMBER); - try { - elasticSearchClient.initialize(); - - ElasticSearchStorageInstaller installer = new ElasticSearchStorageInstaller(indexShardsNumber, indexReplicasNumber); - installer.install(elasticSearchClient); - } catch (ClientException | StorageException e) { - logger.error(e.getMessage(), e); - } - - String uuId = UUID.randomUUID().toString(); - ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); - moduleRegisterService.register(StorageModule.NAME, this.name(), new StorageModuleEsRegistration(uuId, 0)); - - StorageModuleEsNamingListener namingListener = new StorageModuleEsNamingListener(); - ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); - moduleListenerService.addListener(namingListener); - - Integer beforeDay = (Integer)config.getOrDefault(TIME_TO_LIVE_OF_DATA, 3); - deleteTimer = new DataTTLKeeperTimer(getManager(), namingListener, uuId + 0, beforeDay); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - deleteTimer.start(); - } - - @Override public String[] requiredModules() { - return new String[] {ClusterModule.NAME}; - } - - private void registerCacheDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IApplicationCacheDAO.class, new ApplicationEsCacheDAO(elasticSearchClient)); - this.registerServiceImplementation(IInstanceCacheDAO.class, new InstanceEsCacheDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceNameCacheDAO.class, new ServiceNameEsCacheDAO(elasticSearchClient)); - } - - private void registerRegisterDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IApplicationRegisterDAO.class, new ApplicationEsRegisterDAO(elasticSearchClient)); - this.registerServiceImplementation(IInstanceRegisterDAO.class, new InstanceEsRegisterDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceNameRegisterDAO.class, new ServiceNameEsRegisterDAO(elasticSearchClient)); - } - - private void registerPersistenceDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(ICpuMetricPersistenceDAO.class, new CpuMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IGCMetricPersistenceDAO.class, new GCMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IMemoryMetricPersistenceDAO.class, new MemoryMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IMemoryPoolMetricPersistenceDAO.class, new MemoryPoolMetricEsPersistenceDAO(elasticSearchClient)); - - this.registerServiceImplementation(IGlobalTracePersistenceDAO.class, new GlobalTraceEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IInstanceMetricPersistenceDAO.class, new InstanceMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationComponentPersistenceDAO.class, new ApplicationComponentEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationMappingPersistenceDAO.class, new ApplicationMappingEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationMetricPersistenceDAO.class, new ApplicationMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationReferenceMetricPersistenceDAO.class, new ApplicationReferenceMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(ISegmentCostPersistenceDAO.class, new SegmentCostEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(ISegmentPersistenceDAO.class, new SegmentEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceEntryPersistenceDAO.class, new ServiceEntryEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceMetricPersistenceDAO.class, new ServiceMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceReferenceMetricPersistenceDAO.class, new ServiceReferenceMetricEsPersistenceDAO(elasticSearchClient)); - - this.registerServiceImplementation(IInstanceHeartBeatPersistenceDAO.class, new InstanceHeartBeatEsPersistenceDAO(elasticSearchClient)); - } - - private void registerUiDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IInstanceUIDAO.class, new InstanceEsUIDAO(elasticSearchClient)); - - this.registerServiceImplementation(ICpuMetricUIDAO.class, new CpuMetricEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IGCMetricUIDAO.class, new GCMetricEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IMemoryMetricUIDAO.class, new MemoryMetricEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IMemoryPoolMetricUIDAO.class, new MemoryPoolMetricEsUIDAO(elasticSearchClient)); - - this.registerServiceImplementation(IGlobalTraceUIDAO.class, new GlobalTraceEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IInstanceMetricUIDAO.class, new InstanceMetricEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(ISegmentCostUIDAO.class, new SegmentCostEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceEntryUIDAO.class, new ServiceEntryEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceEsUIDAO(elasticSearchClient)); - } - - private void registerAlertingDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IAlertingListPersistenceDAO.class, new AlertingListEsPersistenceDAO(elasticSearchClient)); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java deleted file mode 100644 index 7bbe5291f58c..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/StorageModuleEsRegistration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; -import org.skywalking.apm.collector.core.util.Const; - -/** - * @author peng-yongsheng - */ -public class StorageModuleEsRegistration extends ModuleRegistration { - - private final String virtualHost; - private final int virtualPort; - - StorageModuleEsRegistration(String virtualHost, int virtualPort) { - this.virtualHost = virtualHost; - this.virtualPort = virtualPort; - } - - @Override public Value buildValue() { - return new Value(this.virtualHost, virtualPort, Const.EMPTY_STRING); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java deleted file mode 100644 index 22dea6107d31..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/BatchEsDAO.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.base.dao; - -import java.util.List; -import org.elasticsearch.action.bulk.BulkRequestBuilder; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class BatchEsDAO extends EsDAO implements IBatchDAO { - - private final Logger logger = LoggerFactory.getLogger(BatchEsDAO.class); - - public BatchEsDAO(ElasticSearchClient client) { - super(client); - } - - @Override public void batchPersistence(List batchCollection) { - BulkRequestBuilder bulkRequest = getClient().prepareBulk(); - - logger.debug("bulk data size: {}", batchCollection.size()); - if (CollectionUtils.isNotEmpty(batchCollection)) { - for (int i = 0; i < batchCollection.size(); i++) { - Object builder = batchCollection.get(i); - if (builder instanceof IndexRequestBuilder) { - bulkRequest.add((IndexRequestBuilder)builder); - } - if (builder instanceof UpdateRequestBuilder) { - bulkRequest.add((UpdateRequestBuilder)builder); - } - } - - BulkResponse bulkResponse = bulkRequest.execute().actionGet(); - if (bulkResponse.hasFailures()) { - logger.error(bulkResponse.buildFailureMessage()); - } - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/EsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/EsDAO.java deleted file mode 100644 index 912020473164..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/dao/EsDAO.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.base.dao; - -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.metrics.max.Max; -import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.min.Min; -import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.base.dao.AbstractDAO; - -/** - * @author peng-yongsheng - */ -public abstract class EsDAO extends AbstractDAO { - - public EsDAO(ElasticSearchClient client) { - super(client); - } - - public final int getMaxId(String indexName, String columnName) { - ElasticSearchClient client = getClient(); - SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName); - searchRequestBuilder.setTypes("type"); - searchRequestBuilder.setSize(0); - MaxAggregationBuilder aggregation = AggregationBuilders.max("agg").field(columnName); - searchRequestBuilder.addAggregation(aggregation); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - Max agg = searchResponse.getAggregations().get("agg"); - - int id = (int)agg.getValue(); - if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) { - return 0; - } else { - return id; - } - } - - public final int getMinId(String indexName, String columnName) { - ElasticSearchClient client = getClient(); - SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName); - searchRequestBuilder.setTypes("type"); - searchRequestBuilder.setSize(0); - MinAggregationBuilder aggregation = AggregationBuilders.min("agg").field(columnName); - searchRequestBuilder.addAggregation(aggregation); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - Min agg = searchResponse.getAggregations().get("agg"); - - int id = (int)agg.getValue(); - if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) { - return 0; - } else { - return id; - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java deleted file mode 100644 index 71631f9a1000..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchColumnDefine.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.base.define; - -import org.skywalking.apm.collector.core.data.ColumnDefine; - -/** - * @author peng-yongsheng - */ -public class ElasticSearchColumnDefine extends ColumnDefine { - public ElasticSearchColumnDefine(String name, String type) { - super(name, type); - } - - public enum Type { - Binary, Boolean, Keyword, Long, Integer, Double, Text - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java deleted file mode 100644 index cefbac451176..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/base/define/ElasticSearchTableDefine.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.base.define; - -import org.skywalking.apm.collector.core.data.TableDefine; - -/** - * @author peng-yongsheng - */ -public abstract class ElasticSearchTableDefine extends TableDefine { - - public ElasticSearchTableDefine(String name) { - super(name); - } - - public final String type() { - return "type"; - } - - public abstract int refreshInterval(); -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java deleted file mode 100644 index dba7841bf2ca..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import org.elasticsearch.action.get.GetRequestBuilder; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.ApplicationTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationEsCacheDAO extends EsDAO implements IApplicationCacheDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationEsCacheDAO.class); - - public ApplicationEsCacheDAO(ElasticSearchClient client) { - super(client); - } - - @Override public int getApplicationId(String applicationCode) { - ElasticSearchClient client = getClient(); - - SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ApplicationTable.TABLE); - searchRequestBuilder.setTypes("type"); - searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); - searchRequestBuilder.setQuery(QueryBuilders.termQuery(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode)); - searchRequestBuilder.setSize(1); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - if (searchResponse.getHits().totalHits > 0) { - SearchHit searchHit = searchResponse.getHits().iterator().next(); - return (int)searchHit.getSource().get(ApplicationTable.COLUMN_APPLICATION_ID); - } - return 0; - } - - @Override public String getApplicationCode(int applicationId) { - logger.debug("get application code, applicationId: {}", applicationId); - ElasticSearchClient client = getClient(); - GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId)); - - GetResponse getResponse = getRequestBuilder.get(); - if (getResponse.isExists()) { - return (String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE); - } - return Const.EMPTY_STRING; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java deleted file mode 100644 index 440a9db619a3..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsRegisterDAO.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.support.WriteRequest; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.skywalking.apm.collector.storage.table.register.ApplicationTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationEsRegisterDAO extends EsDAO implements IApplicationRegisterDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationEsRegisterDAO.class); - - public ApplicationEsRegisterDAO(ElasticSearchClient client) { - super(client); - } - - @Override public int getMaxApplicationId() { - return getMaxId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); - } - - @Override public int getMinApplicationId() { - return getMinId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); - } - - @Override public void save(Application application) { - logger.debug("save application register info, application getId: {}, application code: {}", application.getId(), application.getApplicationCode()); - ElasticSearchClient client = getClient(); - Map source = new HashMap<>(); - source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode()); - source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId()); - - IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); - logger.debug("save application register info, application getId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name()); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java deleted file mode 100644 index 02689574de82..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsPersistenceDAO.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetric; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class CpuMetricEsPersistenceDAO extends EsDAO implements ICpuMetricPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(CpuMetricEsPersistenceDAO.class); - - public CpuMetricEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public CpuMetric get(String id) { - return null; - } - - @Override public IndexRequestBuilder prepareBatchInsert(CpuMetric cpuMetric) { - Map source = new HashMap<>(); - source.put(CpuMetricTable.COLUMN_INSTANCE_ID, cpuMetric.getInstanceId()); - source.put(CpuMetricTable.COLUMN_USAGE_PERCENT, cpuMetric.getUsagePercent()); - source.put(CpuMetricTable.COLUMN_TIME_BUCKET, cpuMetric.getTimeBucket()); - - logger.debug("prepare cpu metric batch insert, getId: {}", cpuMetric.getId()); - return getClient().prepareIndex(CpuMetricTable.TABLE, cpuMetric.getId()).setSource(source); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(CpuMetric cpuMetric) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(CpuMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(CpuMetricTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, CpuMetricTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java deleted file mode 100644 index afc67105f981..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import com.google.gson.JsonArray; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; - -/** - * @author peng-yongsheng - */ -public class CpuMetricEsUIDAO extends EsDAO implements ICpuMetricUIDAO { - - public CpuMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public int getMetric(int instanceId, long timeBucket) { - String id = timeBucket + Const.ID_SPLIT + instanceId; - GetResponse getResponse = getClient().prepareGet(CpuMetricTable.TABLE, id).get(); - - if (getResponse.isExists()) { - return ((Number)getResponse.getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).intValue(); - } - return 0; - } - - @Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); - - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId; - prepareMultiGet.add(CpuMetricTable.TABLE, CpuMetricTable.TABLE_TYPE, id); - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - MultiGetResponse multiGetResponse = prepareMultiGet.get(); - for (MultiGetItemResponse response : multiGetResponse.getResponses()) { - if (response.getResponse().isExists()) { - double cpuUsed = ((Number)response.getResponse().getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).doubleValue(); - metrics.add((int)(cpuUsed * 100)); - } else { - metrics.add(0); - } - } - return metrics; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java deleted file mode 100644 index cb7e31bedad2..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GCMetricEsPersistenceDAO.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.GCMetric; -import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GCMetricEsPersistenceDAO extends EsDAO implements IGCMetricPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(GCMetricEsPersistenceDAO.class); - - public GCMetricEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public GCMetric get(String id) { - return null; - } - - @Override public IndexRequestBuilder prepareBatchInsert(GCMetric gcMetric) { - Map source = new HashMap<>(); - source.put(GCMetricTable.COLUMN_INSTANCE_ID, gcMetric.getInstanceId()); - source.put(GCMetricTable.COLUMN_PHRASE, gcMetric.getPhrase()); - source.put(GCMetricTable.COLUMN_COUNT, gcMetric.getCount()); - source.put(GCMetricTable.COLUMN_TIME, gcMetric.getTime()); - source.put(GCMetricTable.COLUMN_TIME_BUCKET, gcMetric.getTimeBucket()); - - return getClient().prepareIndex(GCMetricTable.TABLE, gcMetric.getId()).setSource(source); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(GCMetric gcMetric) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(GCMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(GCMetricTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, GCMetricTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java deleted file mode 100644 index eef139c0dc0d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsPersistenceDAO.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.global.GlobalTrace; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GlobalTraceEsPersistenceDAO extends EsDAO implements IGlobalTracePersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsPersistenceDAO.class); - - public GlobalTraceEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public GlobalTrace get(String id) { - throw new UnexpectedException("There is no need to merge stream data with database data."); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(GlobalTrace data) { - throw new UnexpectedException("There is no need to merge stream data with database data."); - } - - @Override public IndexRequestBuilder prepareBatchInsert(GlobalTrace data) { - Map source = new HashMap<>(); - source.put(GlobalTraceTable.COLUMN_SEGMENT_ID, data.getSegmentId()); - source.put(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, data.getGlobalTraceId()); - source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - logger.debug("global trace source: {}", source.toString()); - return getClient().prepareIndex(GlobalTraceTable.TABLE, data.getId()).setSource(source); - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(GlobalTraceTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(GlobalTraceTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, GlobalTraceTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java deleted file mode 100644 index 64950c7d928e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.ArrayList; -import java.util.List; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GlobalTraceEsUIDAO extends EsDAO implements IGlobalTraceUIDAO { - - private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsUIDAO.class); - - public GlobalTraceEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public List getGlobalTraceId(String segmentId) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE); - searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_SEGMENT_ID, segmentId)); - searchRequestBuilder.setSize(10); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - - List globalTraceIds = new ArrayList<>(); - SearchHit[] searchHits = searchResponse.getHits().getHits(); - for (SearchHit searchHit : searchHits) { - String globalTraceId = (String)searchHit.getSource().get(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID); - logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); - globalTraceIds.add(globalTraceId); - } - return globalTraceIds; - } - - @Override public List getSegmentIds(String globalTraceId) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE); - searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraceId)); - searchRequestBuilder.setSize(10); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - - List segmentIds = new ArrayList<>(); - SearchHit[] searchHits = searchResponse.getHits().getHits(); - for (SearchHit searchHit : searchHits) { - String segmentId = (String)searchHit.getSource().get(GlobalTraceTable.COLUMN_SEGMENT_ID); - logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); - segmentIds.add(segmentId); - } - return segmentIds; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java deleted file mode 100644 index d75dd46a0bda..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceEsCacheDAO extends EsDAO implements IInstanceCacheDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceEsCacheDAO.class); - - public InstanceEsCacheDAO(ElasticSearchClient client) { - super(client); - } - - @Override public int getApplicationId(int instanceId) { - GetResponse response = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(instanceId)).get(); - if (response.isExists()) { - return (int)response.getSource().get(InstanceTable.COLUMN_APPLICATION_ID); - } else { - return 0; - } - } - - @Override public int getInstanceId(int applicationId, String agentUUID) { - ElasticSearchClient client = getClient(); - - SearchRequestBuilder searchRequestBuilder = client.prepareSearch(InstanceTable.TABLE); - searchRequestBuilder.setTypes("type"); - searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); - BoolQueryBuilder builder = QueryBuilders.boolQuery(); - builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId)); - builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_AGENT_UUID, agentUUID)); - searchRequestBuilder.setQuery(builder); - searchRequestBuilder.setSize(1); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - if (searchResponse.getHits().totalHits > 0) { - SearchHit searchHit = searchResponse.getHits().iterator().next(); - return (int)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID); - } - return 0; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java deleted file mode 100644 index 3d0a069a7d98..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsRegisterDAO.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.action.update.UpdateRequest; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceEsRegisterDAO extends EsDAO implements IInstanceRegisterDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceEsRegisterDAO.class); - - public InstanceEsRegisterDAO(ElasticSearchClient client) { - super(client); - } - - @Override public int getMaxInstanceId() { - return getMaxId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); - } - - @Override public int getMinInstanceId() { - return getMinId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); - } - - @Override public void save(Instance instance) { - logger.debug("save instance register info, application getId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID()); - ElasticSearchClient client = getClient(); - Map source = new HashMap<>(); - source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId()); - source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId()); - source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID()); - source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime()); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime()); - source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo()); - - IndexResponse response = client.prepareIndex(InstanceTable.TABLE, instance.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); - logger.debug("save instance register info, application getId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name()); - } - - @Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) { - ElasticSearchClient client = getClient(); - UpdateRequest updateRequest = new UpdateRequest(); - updateRequest.index(InstanceTable.TABLE); - updateRequest.type("type"); - updateRequest.id(String.valueOf(instanceId)); - updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - - Map source = new HashMap<>(); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartbeatTime); - - updateRequest.doc(source); - client.update(updateRequest); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java deleted file mode 100644 index 1b222c83c9db..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceHeartBeatEsPersistenceDAO.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceHeartBeatEsPersistenceDAO extends EsDAO implements IInstanceHeartBeatPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatEsPersistenceDAO.class); - - public InstanceHeartBeatEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public Instance get(String id) { - GetResponse getResponse = getClient().prepareGet(InstanceTable.TABLE, id).get(); - if (getResponse.isExists()) { - Instance instance = new Instance(id); - Map source = getResponse.getSource(); - instance.setInstanceId((Integer)source.get(InstanceTable.COLUMN_INSTANCE_ID)); - instance.setHeartBeatTime((Long)source.get(InstanceTable.COLUMN_HEARTBEAT_TIME)); - logger.debug("getId: {} is exists", id); - return instance; - } else { - logger.debug("getId: {} is not exists", id); - return null; - } - } - - @Override public IndexRequestBuilder prepareBatchInsert(Instance data) { - throw new UnexpectedException("There is no need to merge stream data with database data."); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(Instance data) { - Map source = new HashMap<>(); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, data.getHeartBeatTime()); - return getClient().prepareUpdate(InstanceTable.TABLE, data.getId()).setDoc(source); - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java deleted file mode 100644 index 95b3598fd3da..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsPersistenceDAO.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetric; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricEsPersistenceDAO extends EsDAO implements IMemoryMetricPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(MemoryMetricEsPersistenceDAO.class); - - public MemoryMetricEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public MemoryMetric get(String id) { - return null; - } - - @Override public IndexRequestBuilder prepareBatchInsert(MemoryMetric data) { - Map source = new HashMap<>(); - source.put(MemoryMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); - source.put(MemoryMetricTable.COLUMN_IS_HEAP, data.getIsHeap()); - source.put(MemoryMetricTable.COLUMN_INIT, data.getInit()); - source.put(MemoryMetricTable.COLUMN_MAX, data.getMax()); - source.put(MemoryMetricTable.COLUMN_USED, data.getUsed()); - source.put(MemoryMetricTable.COLUMN_COMMITTED, data.getCommitted()); - source.put(MemoryMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - return getClient().prepareIndex(MemoryMetricTable.TABLE, data.getId()).setSource(source); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(MemoryMetric data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(MemoryMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(MemoryMetricTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, MemoryMetricTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java deleted file mode 100644 index 443625320382..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricEsUIDAO extends EsDAO implements IMemoryMetricUIDAO { - - public MemoryMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) { - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - GetResponse getResponse = getClient().prepareGet(MemoryMetricTable.TABLE, id).get(); - - JsonObject metric = new JsonObject(); - if (getResponse.isExists()) { - metric.addProperty("max", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_MAX)).intValue()); - metric.addProperty("init", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_INIT)).intValue()); - metric.addProperty("used", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_USED)).intValue()); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - metric.addProperty("used", 0); - } - return metric; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) { - MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); - - int i = 0; - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - prepareMultiGet.add(MemoryMetricTable.TABLE, MemoryMetricTable.TABLE_TYPE, id); - } - while (timeBucket <= endTimeBucket); - - JsonObject metric = new JsonObject(); - JsonArray usedMetric = new JsonArray(); - MultiGetResponse multiGetResponse = prepareMultiGet.get(); - for (MultiGetItemResponse response : multiGetResponse.getResponses()) { - if (response.getResponse().isExists()) { - metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_MAX)).longValue()); - metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_INIT)).longValue()); - usedMetric.add(((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_USED)).longValue()); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - usedMetric.add(0); - } - } - metric.add("used", usedMetric); - return metric; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java deleted file mode 100644 index 7bb077abdd3e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsPersistenceDAO.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricEsPersistenceDAO extends EsDAO implements IMemoryPoolMetricPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(MemoryPoolMetricEsPersistenceDAO.class); - - public MemoryPoolMetricEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public MemoryPoolMetric get(String id) { - return null; - } - - @Override public IndexRequestBuilder prepareBatchInsert(MemoryPoolMetric data) { - Map source = new HashMap<>(); - source.put(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); - source.put(MemoryPoolMetricTable.COLUMN_POOL_TYPE, data.getPoolType()); - source.put(MemoryPoolMetricTable.COLUMN_INIT, data.getInit()); - source.put(MemoryPoolMetricTable.COLUMN_MAX, data.getMax()); - source.put(MemoryPoolMetricTable.COLUMN_USED, data.getUsed()); - source.put(MemoryPoolMetricTable.COLUMN_COMMITTED, data.getCommitted()); - source.put(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - return getClient().prepareIndex(MemoryPoolMetricTable.TABLE, data.getId()).setSource(source); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(MemoryPoolMetric data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(MemoryPoolMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(MemoryPoolMetricTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, MemoryPoolMetricTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java deleted file mode 100644 index 259babf89c16..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricEsUIDAO extends EsDAO implements IMemoryPoolMetricUIDAO { - - public MemoryPoolMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket, int poolType) { - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; - GetResponse getResponse = getClient().prepareGet(MemoryPoolMetricTable.TABLE, id).get(); - - JsonObject metric = new JsonObject(); - if (getResponse.isExists()) { - metric.addProperty("max", ((Number)getResponse.getSource().get(MemoryPoolMetricTable.COLUMN_MAX)).intValue()); - metric.addProperty("init", ((Number)getResponse.getSource().get(MemoryPoolMetricTable.COLUMN_INIT)).intValue()); - metric.addProperty("used", ((Number)getResponse.getSource().get(MemoryPoolMetricTable.COLUMN_USED)).intValue()); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - metric.addProperty("used", 0); - } - return metric; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType) { - MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); - - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; - prepareMultiGet.add(MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.TABLE_TYPE, id); - } - while (timeBucket <= endTimeBucket); - - JsonObject metric = new JsonObject(); - JsonArray usedMetric = new JsonArray(); - MultiGetResponse multiGetResponse = prepareMultiGet.get(); - for (MultiGetItemResponse response : multiGetResponse.getResponses()) { - if (response.getResponse().isExists()) { - metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_MAX)).longValue()); - metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_INIT)).longValue()); - usedMetric.add(((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_USED)).longValue()); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - usedMetric.add(0); - } - } - metric.add("used", usedMetric); - return metric; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java deleted file mode 100644 index ef9d831be1bb..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentCostEsPersistenceDAO extends EsDAO implements ISegmentCostPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(SegmentCostEsPersistenceDAO.class); - - public SegmentCostEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public SegmentCost get(String id) { - return null; - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(SegmentCost data) { - return null; - } - - @Override public IndexRequestBuilder prepareBatchInsert(SegmentCost data) { - logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId()); - Map source = new HashMap<>(); - source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getSegmentId()); - source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getApplicationId()); - source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getServiceName()); - source.put(SegmentCostTable.COLUMN_COST, data.getCost()); - source.put(SegmentCostTable.COLUMN_START_TIME, data.getStartTime()); - source.put(SegmentCostTable.COLUMN_END_TIME, data.getEndTime()); - source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getIsError()); - source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - logger.debug("segment cost source: {}", source.toString()); - return getClient().prepareIndex(SegmentCostTable.TABLE, data.getId()).setSource(source); - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(SegmentCostTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, SegmentCostTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java deleted file mode 100644 index 57ef48bf83d7..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsPersistenceDAO.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.segment.Segment; -import org.skywalking.apm.collector.storage.table.segment.SegmentTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentEsPersistenceDAO extends EsDAO implements ISegmentPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(SegmentEsPersistenceDAO.class); - - public SegmentEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public Segment get(String id) { - return null; - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(Segment data) { - return null; - } - - @Override public IndexRequestBuilder prepareBatchInsert(Segment data) { - Map source = new HashMap<>(); - source.put(SegmentTable.COLUMN_DATA_BINARY, new String(Base64.getEncoder().encode(data.getDataBinary()))); - source.put(SegmentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - logger.debug("segment source: {}", source.toString()); - return getClient().prepareIndex(SegmentTable.TABLE, data.getId()).setSource(source); - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); - long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); - BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(SegmentTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(SegmentTable.TABLE) - .get(); - - long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, SegmentTable.TABLE); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java deleted file mode 100644 index 5da1435bb281..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import com.google.protobuf.InvalidProtocolBufferException; -import java.util.Base64; -import java.util.Map; -import org.elasticsearch.action.get.GetResponse; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.segment.SegmentTable; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentEsUIDAO extends EsDAO implements ISegmentUIDAO { - - private final Logger logger = LoggerFactory.getLogger(SegmentEsUIDAO.class); - - public SegmentEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public TraceSegmentObject load(String segmentId) { - GetResponse response = getClient().prepareGet(SegmentTable.TABLE, segmentId).get(); - Map source = response.getSource(); - String dataBinaryBase64 = (String)source.get(SegmentTable.COLUMN_DATA_BINARY); - if (StringUtils.isNotEmpty(dataBinaryBase64)) { - byte[] dataBinary = Base64.getDecoder().decode(dataBinaryBase64); - try { - return TraceSegmentObject.parseFrom(dataBinary); - } catch (InvalidProtocolBufferException e) { - logger.error(e.getMessage(), e); - } - } - return null; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java deleted file mode 100644 index 0a97b326bc2d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsPersistenceDAO.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.update.UpdateRequestBuilder; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryEsPersistenceDAO extends EsDAO implements IServiceEntryPersistenceDAO { - - public ServiceEntryEsPersistenceDAO(ElasticSearchClient client) { - super(client); - } - - @Override public ServiceEntry get(String id) { - GetResponse getResponse = getClient().prepareGet(ServiceEntryTable.TABLE, id).get(); - if (getResponse.isExists()) { - ServiceEntry serviceEntry = new ServiceEntry(id); - Map source = getResponse.getSource(); - serviceEntry.setApplicationId(((Number)source.get(ServiceEntryTable.COLUMN_APPLICATION_ID)).intValue()); - serviceEntry.setEntryServiceId(((Number)source.get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID)).intValue()); - serviceEntry.setEntryServiceName((String)source.get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME)); - serviceEntry.setRegisterTime(((Number)source.get(ServiceEntryTable.COLUMN_REGISTER_TIME)).longValue()); - serviceEntry.setNewestTime(((Number)source.get(ServiceEntryTable.COLUMN_NEWEST_TIME)).longValue()); - return serviceEntry; - } else { - return null; - } - } - - @Override public IndexRequestBuilder prepareBatchInsert(ServiceEntry data) { - Map source = new HashMap<>(); - source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getApplicationId()); - source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getEntryServiceId()); - source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getEntryServiceName()); - source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getRegisterTime()); - source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getNewestTime()); - return getClient().prepareIndex(ServiceEntryTable.TABLE, data.getId()).setSource(source); - } - - @Override public UpdateRequestBuilder prepareBatchUpdate(ServiceEntry data) { - Map source = new HashMap<>(); - source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getApplicationId()); - source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getEntryServiceId()); - source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getEntryServiceName()); - source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getRegisterTime()); - source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getNewestTime()); - - return getClient().prepareUpdate(ServiceEntryTable.TABLE, data.getId()).setDoc(source); - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java deleted file mode 100644 index 10f672893171..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import org.elasticsearch.action.get.GetRequestBuilder; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; - -/** - * @author peng-yongsheng - */ -public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO { - - public ServiceNameEsCacheDAO(ElasticSearchClient client) { - super(client); - } - - @Override public String getServiceName(int serviceId) { - GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId)); - - GetResponse getResponse = getRequestBuilder.get(); - if (getResponse.isExists()) { - String serviceName = (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME); - int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue(); - return applicationId + Const.ID_SPLIT + serviceName; - } - return Const.EMPTY_STRING; - } - - @Override public int getServiceId(int applicationId, String serviceName) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE); - searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - - BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); - boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId)); - boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName)); - searchRequestBuilder.setQuery(boolQuery); - searchRequestBuilder.setSize(1); - - SearchResponse searchResponse = searchRequestBuilder.get(); - if (searchResponse.getHits().totalHits > 0) { - SearchHit searchHit = searchResponse.getHits().iterator().next(); - return (int)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID); - } - return 0; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java deleted file mode 100644 index 5657c5788177..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsRegisterDAO.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.dao; - -import java.util.HashMap; -import java.util.Map; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.support.WriteRequest; -import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; -import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceNameEsRegisterDAO extends EsDAO implements IServiceNameRegisterDAO { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameEsRegisterDAO.class); - - public ServiceNameEsRegisterDAO(ElasticSearchClient client) { - super(client); - } - - @Override public int getMaxServiceId() { - return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); - } - - @Override public int getMinServiceId() { - return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); - } - - @Override public void save(ServiceName serviceName) { - logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName()); - ElasticSearchClient client = getClient(); - Map source = new HashMap<>(); - source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId()); - source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId()); - source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName()); - - IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, serviceName.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); - logger.debug("save service name register info, application getId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name()); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java deleted file mode 100644 index 1b41bc58f798..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/AlertingListEsTableDefine.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.alerting.AlertingListTable; - -/** - * @author peng-yongsheng - */ -public class AlertingListEsTableDefine extends ElasticSearchTableDefine { - - public AlertingListEsTableDefine() { - super(AlertingListTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_LAYER, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_LAYER_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_FIRST_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_LAST_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_EXPECTED, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_ACTUAL, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(AlertingListTable.COLUMN_VALID, ElasticSearchColumnDefine.Type.Boolean.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java deleted file mode 100644 index f103d3937515..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationComponentEsTableDefine.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentEsTableDefine extends ElasticSearchTableDefine { - - public ApplicationComponentEsTableDefine() { - super(ApplicationComponentTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java deleted file mode 100644 index 6eb9e0cc426b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationEsTableDefine.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.register.ApplicationTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationEsTableDefine extends ElasticSearchTableDefine { - - public ApplicationEsTableDefine() { - super(ApplicationTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_APPLICATION_CODE, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java deleted file mode 100644 index b8a4b41e4130..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ApplicationMappingEsTableDefine.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingEsTableDefine extends ElasticSearchTableDefine { - - public ApplicationMappingEsTableDefine() { - super(ApplicationMappingTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java deleted file mode 100644 index e46ca787c5a1..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/CpuMetricEsTableDefine.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; - -/** - * @author peng-yongsheng - */ -public class CpuMetricEsTableDefine extends ElasticSearchTableDefine { - - public CpuMetricEsTableDefine() { - super(CpuMetricTable.TABLE); - } - - @Override public int refreshInterval() { - return 1; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_USAGE_PERCENT, ElasticSearchColumnDefine.Type.Double.name())); - addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java deleted file mode 100644 index 5bd77bbffa52..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GCMetricEsTableDefine.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable; - -/** - * @author peng-yongsheng - */ -public class GCMetricEsTableDefine extends ElasticSearchTableDefine { - - public GCMetricEsTableDefine() { - super(GCMetricTable.TABLE); - } - - @Override public int refreshInterval() { - return 1; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_PHRASE, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_COUNT, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java deleted file mode 100644 index 95d98949934b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/GlobalTraceEsTableDefine.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; - -/** - * @author peng-yongsheng - */ -public class GlobalTraceEsTableDefine extends ElasticSearchTableDefine { - - public GlobalTraceEsTableDefine() { - super(GlobalTraceTable.TABLE); - } - - @Override public int refreshInterval() { - return 5; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(GlobalTraceTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(GlobalTraceTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java deleted file mode 100644 index 22d7bee4dc36..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceEsTableDefine.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; - -/** - * @author peng-yongsheng - */ -public class InstanceEsTableDefine extends ElasticSearchTableDefine { - - public InstanceEsTableDefine() { - super(InstanceTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_AGENT_UUID, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_REGISTER_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_HEARTBEAT_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceTable.COLUMN_OS_INFO, ElasticSearchColumnDefine.Type.Keyword.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java deleted file mode 100644 index 35c19401c2ed..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/InstanceMetricEsTableDefine.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricEsTableDefine extends ElasticSearchTableDefine { - - public InstanceMetricEsTableDefine() { - super(InstanceMetricTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - - addColumn(new ElasticSearchColumnDefine(InstanceMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java deleted file mode 100644 index c33b6ecccd4d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryMetricEsTableDefine.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricEsTableDefine extends ElasticSearchTableDefine { - - public MemoryMetricEsTableDefine() { - super(MemoryMetricTable.TABLE); - } - - @Override public int refreshInterval() { - return 1; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_IS_HEAP, ElasticSearchColumnDefine.Type.Boolean.name())); - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_INIT, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_MAX, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_USED, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_COMMITTED, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java deleted file mode 100644 index 38aeca6090aa..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/MemoryPoolMetricEsTableDefine.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricEsTableDefine extends ElasticSearchTableDefine { - - public MemoryPoolMetricEsTableDefine() { - super(MemoryPoolMetricTable.TABLE); - } - - @Override public int refreshInterval() { - return 1; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_POOL_TYPE, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_INIT, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_MAX, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_USED, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_COMMITTED, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java deleted file mode 100644 index 2b9891753c72..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; - -/** - * @author peng-yongsheng - */ -public class SegmentCostEsTableDefine extends ElasticSearchTableDefine { - - public SegmentCostEsTableDefine() { - super(SegmentCostTable.TABLE); - } - - @Override public int refreshInterval() { - return 5; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_COST, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_START_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_END_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_IS_ERROR, ElasticSearchColumnDefine.Type.Boolean.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java deleted file mode 100644 index 4c0f05f561c9..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/SegmentEsTableDefine.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.segment.SegmentTable; - -/** - * @author peng-yongsheng - */ -public class SegmentEsTableDefine extends ElasticSearchTableDefine { - - public SegmentEsTableDefine() { - super(SegmentTable.TABLE); - } - - @Override public int refreshInterval() { - return 10; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(SegmentTable.COLUMN_DATA_BINARY, ElasticSearchColumnDefine.Type.Binary.name())); - addColumn(new ElasticSearchColumnDefine(SegmentTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java deleted file mode 100644 index da12a224ece2..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceEntryEsTableDefine.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryEsTableDefine extends ElasticSearchTableDefine { - - public ServiceEntryEsTableDefine() { - super(ServiceEntryTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); - addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_REGISTER_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceEntryTable.COLUMN_NEWEST_TIME, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java deleted file mode 100644 index 1be92db5a455..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceMetricEsTableDefine.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.service.ServiceMetricTable; - -/** - * @author peng-yongsheng - */ -public class ServiceMetricEsTableDefine extends ElasticSearchTableDefine { - - public ServiceMetricEsTableDefine() { - super(ServiceMetricTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, ElasticSearchColumnDefine.Type.Long.name())); - - addColumn(new ElasticSearchColumnDefine(ServiceMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java deleted file mode 100644 index 571bf531690a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/define/ServiceNameEsTableDefine.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.es.define; - -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; - -/** - * @author peng-yongsheng - */ -public class ServiceNameEsTableDefine extends ElasticSearchTableDefine { - - public ServiceNameEsTableDefine() { - super(ServiceNameTable.TABLE); - } - - @Override public int refreshInterval() { - return 2; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define index 22d0931bee89..b69eb5648c5c 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define @@ -1,18 +1,18 @@ -org.skywalking.apm.collector.storage.es.define.ApplicationEsTableDefine -org.skywalking.apm.collector.storage.es.define.InstanceEsTableDefine -org.skywalking.apm.collector.storage.es.define.ServiceNameEsTableDefine -org.skywalking.apm.collector.storage.es.define.CpuMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.GCMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.MemoryMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.MemoryPoolMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.GlobalTraceEsTableDefine -org.skywalking.apm.collector.storage.es.define.InstanceMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.ApplicationComponentEsTableDefine -org.skywalking.apm.collector.storage.es.define.ApplicationMappingEsTableDefine -org.skywalking.apm.collector.storage.es.define.ApplicationReferenceMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.SegmentCostEsTableDefine -org.skywalking.apm.collector.storage.es.define.SegmentEsTableDefine -org.skywalking.apm.collector.storage.es.define.ServiceEntryEsTableDefine -org.skywalking.apm.collector.storage.es.define.ServiceMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.ServiceReferenceMetricEsTableDefine -org.skywalking.apm.collector.storage.es.define.AlertingListEsTableDefine \ No newline at end of file +org.apache.skywalking.apm.collector.storage.es.define.ApplicationEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.InstanceEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ServiceNameEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.CpuMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.GCMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.MemoryMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.MemoryPoolMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.GlobalTraceEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.InstanceMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ApplicationComponentEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ApplicationMappingEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ApplicationReferenceMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.SegmentCostEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.SegmentEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ServiceEntryEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ServiceMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.ServiceReferenceMetricEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.AlertingListEsTableDefine diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..136e90904b13 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.storage.es.StorageModuleEsProvider diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index ecaae1d83743..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.storage.es.StorageModuleEsProvider diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java new file mode 100644 index 000000000000..3e8da886e380 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller; +import org.apache.skywalking.apm.collector.storage.h2.dao.AlertingListH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.GCMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceH2CacheDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceEntryH2PersistenceDAO; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.storage.StorageException; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationComponentH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationComponentH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationH2CacheDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationH2RegisterDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationMappingH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationMappingH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationReferenceMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationReferenceMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.CpuMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.CpuMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.GCMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceH2RegisterDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceHeartBeatH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.MemoryMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.MemoryMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentCostH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentCostH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceEntryH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceNameH2CacheDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceNameH2RegisterDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceReferenceH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceReferenceMetricH2PersistenceDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class StorageModuleH2Provider extends ModuleProvider { + + private final Logger logger = LoggerFactory.getLogger(StorageModuleH2Provider.class); + + private static final String URL = "url"; + private static final String USER_NAME = "user_name"; + private static final String PASSWORD = "password"; + + private H2Client h2Client; + + @Override public String name() { + return "h2"; + } + + @Override public Class module() { + return StorageModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + String url = config.getProperty(URL); + String userName = config.getProperty(USER_NAME); + String password = config.getProperty(PASSWORD); + h2Client = new H2Client(url, userName, password); + + this.registerServiceImplementation(IBatchDAO.class, new BatchH2DAO(h2Client)); + registerCacheDAO(); + registerRegisterDAO(); + registerPersistenceDAO(); + registerUiDAO(); + registerAlertingDAO(); + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + try { + h2Client.initialize(); + + H2StorageInstaller installer = new H2StorageInstaller(); + installer.install(h2Client); + } catch (H2ClientException | StorageException e) { + logger.error(e.getMessage(), e); + } + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[0]; + } + + private void registerCacheDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IApplicationCacheDAO.class, new ApplicationH2CacheDAO(h2Client)); + this.registerServiceImplementation(IInstanceCacheDAO.class, new InstanceH2CacheDAO(h2Client)); + this.registerServiceImplementation(IServiceNameCacheDAO.class, new ServiceNameH2CacheDAO(h2Client)); + } + + private void registerRegisterDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IApplicationRegisterDAO.class, new ApplicationH2RegisterDAO(h2Client)); + this.registerServiceImplementation(IInstanceRegisterDAO.class, new InstanceH2RegisterDAO(h2Client)); + this.registerServiceImplementation(IServiceNameRegisterDAO.class, new ServiceNameH2RegisterDAO(h2Client)); + } + + private void registerPersistenceDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(ICpuMetricPersistenceDAO.class, new CpuMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IGCMetricPersistenceDAO.class, new GCMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IMemoryMetricPersistenceDAO.class, new MemoryMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IMemoryPoolMetricPersistenceDAO.class, new MemoryPoolMetricH2PersistenceDAO(h2Client)); + + this.registerServiceImplementation(IGlobalTracePersistenceDAO.class, new GlobalTraceH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IInstanceMetricPersistenceDAO.class, new InstanceMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IApplicationComponentPersistenceDAO.class, new ApplicationComponentH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IApplicationMappingPersistenceDAO.class, new ApplicationMappingH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IApplicationMetricPersistenceDAO.class, new ApplicationMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IApplicationReferenceMetricPersistenceDAO.class, new ApplicationReferenceMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(ISegmentCostPersistenceDAO.class, new SegmentCostH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(ISegmentPersistenceDAO.class, new SegmentH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IServiceEntryPersistenceDAO.class, new ServiceEntryH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IServiceMetricPersistenceDAO.class, new ServiceMetricH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(IServiceReferenceMetricPersistenceDAO.class, new ServiceReferenceMetricH2PersistenceDAO(h2Client)); + + this.registerServiceImplementation(IInstanceHeartBeatPersistenceDAO.class, new InstanceHeartBeatH2PersistenceDAO(h2Client)); + } + + private void registerUiDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IInstanceUIDAO.class, new InstanceH2UIDAO(h2Client)); + + this.registerServiceImplementation(ICpuMetricUIDAO.class, new CpuMetricH2UIDAO(h2Client)); + this.registerServiceImplementation(IGCMetricUIDAO.class, new GCMetricH2UIDAO(h2Client)); + this.registerServiceImplementation(IMemoryMetricUIDAO.class, new MemoryMetricH2UIDAO(h2Client)); + this.registerServiceImplementation(IMemoryPoolMetricUIDAO.class, new MemoryPoolMetricH2UIDAO(h2Client)); + + this.registerServiceImplementation(IGlobalTraceUIDAO.class, new GlobalTraceH2UIDAO(h2Client)); + this.registerServiceImplementation(IInstanceMetricUIDAO.class, new InstanceMetricH2UIDAO(h2Client)); + this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentH2UIDAO(h2Client)); + this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingH2UIDAO(h2Client)); + this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricH2UIDAO(h2Client)); + this.registerServiceImplementation(ISegmentCostUIDAO.class, new SegmentCostH2UIDAO(h2Client)); + this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentH2UIDAO(h2Client)); + this.registerServiceImplementation(IServiceEntryUIDAO.class, new ServiceEntryH2UIDAO(h2Client)); + this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceH2UIDAO(h2Client)); + } + + private void registerAlertingDAO() throws ServiceNotProvidedException { + this.registerServiceImplementation(IAlertingListPersistenceDAO.class, new AlertingListH2PersistenceDAO(h2Client)); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java new file mode 100644 index 000000000000..9d005fef3f71 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.base.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class BatchH2DAO extends H2DAO implements IBatchDAO { + + private final Logger logger = LoggerFactory.getLogger(BatchH2DAO.class); + + public BatchH2DAO(H2Client client) { + super(client); + } + + @Override + public void batchPersistence(List batchCollection) { + if (batchCollection != null && batchCollection.size() > 0) { + logger.debug("the batch collection size is {}", batchCollection.size()); + Connection conn; + final Map batchSqls = new HashMap<>(); + try { + conn = getClient().getConnection(); + conn.setAutoCommit(true); + PreparedStatement ps; + for (Object entity : batchCollection) { + H2SqlEntity e = getH2SqlEntity(entity); + String sql = e.getSql(); + if (batchSqls.containsKey(sql)) { + ps = batchSqls.get(sql); + } else { + ps = conn.prepareStatement(sql); + batchSqls.put(sql, ps); + } + + Object[] params = e.getParams(); + if (params != null) { + logger.debug("the sql is {}, params size is {}, params: {}", e.getSql(), params.length, params); + for (int i = 0; i < params.length; i++) { + ps.setObject(i + 1, params[i]); + } + } + ps.addBatch(); + } + + for (String k : batchSqls.keySet()) { + batchSqls.get(k).executeBatch(); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + batchSqls.clear(); + } + } + + private H2SqlEntity getH2SqlEntity(Object entity) { + if (entity instanceof H2SqlEntity) { + return (H2SqlEntity)entity; + } + return null; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java new file mode 100644 index 000000000000..db26cee1bb92 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.base.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.dao.AbstractDAO; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public abstract class H2DAO extends AbstractDAO { + + private final Logger logger = LoggerFactory.getLogger(H2DAO.class); + + public H2DAO(H2Client client) { + super(client); + } + + protected final int getMaxId(String tableName, String columnName) { + String sql = "select max(" + columnName + ") from " + tableName; + return getIntValueBySQL(sql); + } + + protected final int getMinId(String tableName, String columnName) { + String sql = "select min(" + columnName + ") from " + tableName; + return getIntValueBySQL(sql); + } + + private int getIntValueBySQL(String sql) { + H2Client client = getClient(); + try (ResultSet rs = client.executeQuery(sql, null)) { + if (rs.next()) { + int id = rs.getInt(1); + if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) { + return 0; + } else { + return id; + } + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java new file mode 100644 index 000000000000..8a24ef7ea5e6 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.base.define; + +import org.apache.skywalking.apm.collector.core.data.ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class H2ColumnDefine extends ColumnDefine { + + public H2ColumnDefine(String name, String type) { + super(name, type); + } + + public enum Type { + Boolean, Varchar, Int, Bigint, BINARY, Double + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java new file mode 100644 index 000000000000..02ac96af8121 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.base.define; + +/** + * @author clevertension + */ +public class H2SqlEntity { + private String sql; + private Object[] params; + + public String getSql() { + return sql; + } + + public void setSql(String sql) { + this.sql = sql; + } + + public Object[] getParams() { + return params; + } + + public void setParams(Object[] params) { + this.params = params; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java new file mode 100644 index 000000000000..44e4f78aa676 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.base.define; + +import org.apache.skywalking.apm.collector.client.Client; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.StorageException; +import org.apache.skywalking.apm.collector.storage.StorageInstallException; +import org.apache.skywalking.apm.collector.storage.StorageInstaller; +import org.apache.skywalking.apm.collector.core.data.TableDefine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class H2StorageInstaller extends StorageInstaller { + + private final Logger logger = LoggerFactory.getLogger(H2StorageInstaller.class); + + @Override protected void defineFilter(List tableDefines) { + int size = tableDefines.size(); + for (int i = size - 1; i >= 0; i--) { + if (!(tableDefines.get(i) instanceof H2TableDefine)) { + tableDefines.remove(i); + } + } + } + + @Override protected boolean isExists(Client client, TableDefine tableDefine) throws StorageException { + H2Client h2Client = (H2Client)client; + ResultSet rs = null; + try { + logger.info("check if table {} exist ", tableDefine.getName()); + rs = h2Client.getConnection().getMetaData().getTables(null, null, tableDefine.getName().toUpperCase(), null); + if (rs.next()) { + return true; + } + } catch (SQLException | H2ClientException e) { + throw new StorageInstallException(e.getMessage(), e); + } finally { + try { + if (rs != null) { + rs.close(); + } + } catch (SQLException e) { + throw new StorageInstallException(e.getMessage(), e); + } + } + return false; + } + + @Override protected boolean deleteTable(Client client, TableDefine tableDefine) throws StorageException { + H2Client h2Client = (H2Client)client; + try { + h2Client.execute("drop table if exists " + tableDefine.getName()); + return true; + } catch (H2ClientException e) { + throw new StorageInstallException(e.getMessage(), e); + } + } + + @Override protected boolean createTable(Client client, TableDefine tableDefine) throws StorageException { + H2Client h2Client = (H2Client)client; + H2TableDefine h2TableDefine = (H2TableDefine)tableDefine; + + StringBuilder sqlBuilder = new StringBuilder(); + sqlBuilder.append("CREATE TABLE ").append(h2TableDefine.getName()).append(" ("); + + h2TableDefine.getColumnDefines().forEach(columnDefine -> { + H2ColumnDefine h2ColumnDefine = (H2ColumnDefine)columnDefine; + if (h2ColumnDefine.getType().equals(H2ColumnDefine.Type.Varchar.name())) { + sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append("(255),"); + } else { + sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append(","); + } + }); + //remove last comma + sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length()); + sqlBuilder.append(")"); + try { + logger.info("create h2 table with sql {}", sqlBuilder); + h2Client.execute(sqlBuilder.toString()); + } catch (H2ClientException e) { + throw new StorageInstallException(e.getMessage(), e); + } + return true; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java new file mode 100644 index 000000000000..b5c3a39d51db --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.base.define; + +import org.apache.skywalking.apm.collector.core.data.TableDefine; + +/** + * @author peng-yongsheng + */ +public abstract class H2TableDefine extends TableDefine { + + public H2TableDefine(String name) { + super(name); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java similarity index 76% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java index f08c538e8a0d..7c1fa0b87595 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/AlertingListH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.alerting.AlertingList; -import org.skywalking.apm.collector.storage.table.alerting.AlertingListTable; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingList; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingListTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java new file mode 100644 index 000000000000..c333f73809ec --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationComponentH2PersistenceDAO extends H2DAO implements IApplicationComponentPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(ApplicationComponentH2PersistenceDAO.class); + private static final String GET_SQL = "select * from {0} where {1} = ?"; + + public ApplicationComponentH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override + public ApplicationComponent get(String id) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SQL, ApplicationComponentTable.TABLE, ApplicationComponentTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + ApplicationComponent applicationComponent = new ApplicationComponent(id); + applicationComponent.setComponentId(rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID)); + applicationComponent.setPeerId(rs.getInt(ApplicationComponentTable.COLUMN_PEER_ID)); + applicationComponent.setTimeBucket(rs.getLong(ApplicationComponentTable.COLUMN_TIME_BUCKET)); + return applicationComponent; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override + public H2SqlEntity prepareBatchInsert(ApplicationComponent data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(ApplicationComponentTable.COLUMN_ID, data.getId()); + source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, data.getComponentId()); + source.put(ApplicationComponentTable.COLUMN_PEER_ID, data.getPeerId()); + source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + String sql = SqlBuilder.buildBatchInsertSql(ApplicationComponentTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override + public H2SqlEntity prepareBatchUpdate(ApplicationComponent data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, data.getComponentId()); + source.put(ApplicationComponentTable.COLUMN_PEER_ID, data.getPeerId()); + source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + String sql = SqlBuilder.buildBatchUpdateSql(ApplicationComponentTable.TABLE, source.keySet(), ApplicationComponentTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(data.getId()); + entity.setParams(values.toArray(new Object[0])); + return entity; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java new file mode 100644 index 000000000000..5a528e211fe5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationComponentH2UIDAO extends H2DAO implements IApplicationComponentUIDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationComponentH2UIDAO.class); + private static final String AGGREGATE_COMPONENT_SQL = "select {0}, {1} from {2} where {3} >= ? and {3} <= ? group by {0}, {1} limit 100"; + + public ApplicationComponentH2UIDAO(H2Client client) { + super(client); + } + + @Override public JsonArray load(long startTime, long endTime) { + JsonArray applicationComponentArray = new JsonArray(); + applicationComponentArray.addAll(aggregationComponent(startTime, endTime)); + return applicationComponentArray; + } + + private JsonArray aggregationComponent(long startTime, long endTime) { + H2Client client = getClient(); + + JsonArray applicationComponentArray = new JsonArray(); + String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_PEER_ID, + ApplicationComponentTable.TABLE, ApplicationComponentTable.COLUMN_TIME_BUCKET); + Object[] params = new Object[] {startTime, endTime}; + try (ResultSet rs = client.executeQuery(sql, params)) { + while (rs.next()) { + int peerId = rs.getInt(ApplicationComponentTable.COLUMN_PEER_ID); + int componentId = rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID); + JsonObject applicationComponentObj = new JsonObject(); + applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_COMPONENT_ID, componentId); + applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_PEER_ID, peerId); + applicationComponentArray.add(applicationComponentObj); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return applicationComponentArray; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java new file mode 100644 index 000000000000..ae8522f36c07 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationH2CacheDAO.class); + private static final String GET_APPLICATION_ID_OR_CODE_SQL = "select {0} from {1} where {2} = ?"; + + public ApplicationH2CacheDAO(H2Client client) { + super(client); + } + + @Override + public int getApplicationId(String applicationCode) { + logger.info("get the application getId with application code = {}", applicationCode); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_ID, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_CODE); + + Object[] params = new Object[] {applicationCode}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(1); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } + + @Override public String getApplicationCode(int applicationId) { + logger.debug("get application code, applicationId: {}", applicationId); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + Object[] params = new Object[] {applicationId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getString(1); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return Const.EMPTY_STRING; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java new file mode 100644 index 000000000000..e28be555ffc1 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationH2RegisterDAO extends H2DAO implements IApplicationRegisterDAO { + private final Logger logger = LoggerFactory.getLogger(ApplicationH2RegisterDAO.class); + + public ApplicationH2RegisterDAO(H2Client client) { + super(client); + } + + @Override + public int getMaxApplicationId() { + return getMaxId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + } + + @Override + public int getMinApplicationId() { + return getMinId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + } + + @Override + public void save(Application application) { + H2Client client = getClient(); + + Map source = new HashMap<>(); + source.put(ApplicationTable.COLUMN_ID, application.getId()); + source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode()); + source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId()); + + String sql = SqlBuilder.buildBatchInsertSql(ApplicationTable.TABLE, source.keySet()); + Object[] params = source.values().toArray(new Object[0]); + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java new file mode 100644 index 000000000000..81d52699e53a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationMappingH2PersistenceDAO extends H2DAO implements IApplicationMappingPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationMappingH2PersistenceDAO.class); + private static final String GET_SQL = "select * from {0} where {1} = ?"; + + public ApplicationMappingH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public ApplicationMapping get(String id) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SQL, ApplicationMappingTable.TABLE, ApplicationMappingTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + ApplicationMapping applicationMapping = new ApplicationMapping(id); + applicationMapping.setApplicationId(rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID)); + applicationMapping.setAddressId(rs.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID)); + applicationMapping.setTimeBucket(rs.getLong(ApplicationMappingTable.COLUMN_TIME_BUCKET)); + return applicationMapping; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(ApplicationMapping applicationMapping) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(ApplicationMappingTable.COLUMN_ID, applicationMapping.getId()); + source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationMapping.getApplicationId()); + source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, applicationMapping.getAddressId()); + source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, applicationMapping.getTimeBucket()); + String sql = SqlBuilder.buildBatchInsertSql(ApplicationMappingTable.TABLE, source.keySet()); + entity.setSql(sql); + + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(ApplicationMapping applicationMapping) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationMapping.getApplicationId()); + source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, applicationMapping.getAddressId()); + source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, applicationMapping.getTimeBucket()); + String sql = SqlBuilder.buildBatchUpdateSql(ApplicationMappingTable.TABLE, source.keySet(), ApplicationMappingTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(applicationMapping.getId()); + entity.setParams(values.toArray(new Object[0])); + return entity; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java new file mode 100644 index 000000000000..38174fbef392 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationMappingH2UIDAO extends H2DAO implements IApplicationMappingUIDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationMappingH2UIDAO.class); + private static final String APPLICATION_MAPPING_SQL = "select {0}, {1} from {2} where {3} >= ? and {3} <= ? group by {0}, {1} limit 100"; + + public ApplicationMappingH2UIDAO(H2Client client) { + super(client); + } + + @Override public JsonArray load(long startTime, long endTime) { + H2Client client = getClient(); + JsonArray applicationMappingArray = new JsonArray(); + String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID, + ApplicationMappingTable.COLUMN_ADDRESS_ID, ApplicationMappingTable.TABLE, ApplicationMappingTable.COLUMN_TIME_BUCKET); + + Object[] params = new Object[] {startTime, endTime}; + try (ResultSet rs = client.executeQuery(sql, params)) { + while (rs.next()) { + int applicationId = rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID); + int addressId = rs.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID); + JsonObject applicationMappingObj = new JsonObject(); + applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationId); + applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_ADDRESS_ID, addressId); + applicationMappingArray.add(applicationMappingObj); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + logger.debug("node mapping data: {}", applicationMappingArray.toString()); + return applicationMappingArray; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java similarity index 85% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java index 4a5911b9be5d..ae3b4a5d9840 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMetricH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetric; -import org.skywalking.apm.collector.storage.table.application.ApplicationMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java similarity index 87% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java index e7593bc1d0bd..db012455a739 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java similarity index 80% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java index da43a4e33ac7..95c41ac6fda1 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import com.google.gson.JsonArray; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java new file mode 100644 index 000000000000..b61ece2a705d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class CpuMetricH2PersistenceDAO extends H2DAO implements ICpuMetricPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(CpuMetricH2PersistenceDAO.class); + + public CpuMetricH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public CpuMetric get(String id) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(CpuMetric data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(CpuMetricTable.COLUMN_ID, data.getId()); + source.put(CpuMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); + source.put(CpuMetricTable.COLUMN_USAGE_PERCENT, data.getUsagePercent()); + source.put(CpuMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + logger.debug("prepare cpu metric batch insert, getId: {}", data.getId()); + String sql = SqlBuilder.buildBatchInsertSql(CpuMetricTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(CpuMetric data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java new file mode 100644 index 000000000000..b93dd246efbc --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.gson.JsonArray; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class CpuMetricH2UIDAO extends H2DAO implements ICpuMetricUIDAO { + private final Logger logger = LoggerFactory.getLogger(CpuMetricH2UIDAO.class); + private static final String GET_CPU_METRIC_SQL = "select * from {0} where {1} = ?"; + + public CpuMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override public int getMetric(int instanceId, long timeBucket) { + String id = timeBucket + Const.ID_SPLIT + instanceId; + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(CpuMetricTable.COLUMN_USAGE_PERCENT); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } + + @Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID); + + long timeBucket = startTimeBucket; + List idList = new ArrayList<>(); + do { + timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); + String id = timeBucket + Const.ID_SPLIT + instanceId; + idList.add(id); + } + while (timeBucket <= endTimeBucket); + + JsonArray metrics = new JsonArray(); + idList.forEach(id -> { + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + double cpuUsed = rs.getDouble(CpuMetricTable.COLUMN_USAGE_PERCENT); + metrics.add((int)(cpuUsed * 100)); + } else { + metrics.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + return metrics; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java new file mode 100644 index 000000000000..60ad1eabaf8f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric; + +/** + * @author peng-yongsheng, clevertension + */ +public class GCMetricH2PersistenceDAO extends H2DAO implements IGCMetricPersistenceDAO { + + public GCMetricH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public GCMetric get(String id) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(GCMetric data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(GCMetricTable.COLUMN_ID, data.getId()); + source.put(GCMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); + source.put(GCMetricTable.COLUMN_PHRASE, data.getPhrase()); + source.put(GCMetricTable.COLUMN_COUNT, data.getCount()); + source.put(GCMetricTable.COLUMN_TIME, data.getTime()); + source.put(GCMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + String sql = SqlBuilder.buildBatchInsertSql(GCMetricTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(GCMetric data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java similarity index 80% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java index 7fde1cd15940..35cf9c9ec651 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -24,15 +42,15 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable; -import org.skywalking.apm.network.proto.GCPhrase; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.network.proto.GCPhrase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java new file mode 100644 index 000000000000..ff3e74ed6022 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTrace; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class GlobalTraceH2PersistenceDAO extends H2DAO implements IGlobalTracePersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2PersistenceDAO.class); + + public GlobalTraceH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public GlobalTrace get(String id) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public H2SqlEntity prepareBatchUpdate(GlobalTrace data) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public H2SqlEntity prepareBatchInsert(GlobalTrace data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(GlobalTraceTable.COLUMN_ID, data.getId()); + source.put(GlobalTraceTable.COLUMN_SEGMENT_ID, data.getSegmentId()); + source.put(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, data.getGlobalTraceId()); + source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + logger.debug("global trace source: {}", source.toString()); + + String sql = SqlBuilder.buildBatchInsertSql(GlobalTraceTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java new file mode 100644 index 000000000000..9904a57dcf82 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class GlobalTraceH2UIDAO extends H2DAO implements IGlobalTraceUIDAO { + + private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2UIDAO.class); + + private static final String GET_GLOBAL_TRACE_ID_SQL = "select {0} from {1} where {2} = ? limit 10"; + private static final String GET_SEGMENT_IDS_SQL = "select {0} from {1} where {2} = ? limit 10"; + + public GlobalTraceH2UIDAO(H2Client client) { + super(client); + } + + @Override public List getGlobalTraceId(String segmentId) { + List globalTraceIds = new ArrayList<>(); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, + GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_SEGMENT_ID); + Object[] params = new Object[] {segmentId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + while (rs.next()) { + String globalTraceId = rs.getString(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID); + logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); + globalTraceIds.add(globalTraceId); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return globalTraceIds; + } + + @Override public List getSegmentIds(String globalTraceId) { + List segmentIds = new ArrayList<>(); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID, + GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID); + Object[] params = new Object[] {globalTraceId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + while (rs.next()) { + String segmentId = rs.getString(GlobalTraceTable.COLUMN_SEGMENT_ID); + logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); + segmentIds.add(segmentId); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return segmentIds; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java new file mode 100644 index 000000000000..460b13f8037f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceH2CacheDAO extends H2DAO implements IInstanceCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceH2CacheDAO.class); + + private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?"; + private static final String GET_INSTANCE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?"; + + public InstanceH2CacheDAO(H2Client client) { + super(client); + } + + @Override public int getApplicationId(int instanceId) { + logger.info("get the application getId with application getId = {}", instanceId); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + Object[] params = new Object[] {instanceId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } + + @Override public int getInstanceId(int applicationId, String agentUUID) { + logger.info("get the application getId with application getId = {}, agentUUID = {}", applicationId, agentUUID); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, + InstanceTable.COLUMN_AGENT_UUID); + Object[] params = new Object[] {applicationId, agentUUID}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java new file mode 100644 index 000000000000..a204f940dc42 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class InstanceH2RegisterDAO extends H2DAO implements IInstanceRegisterDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceH2RegisterDAO.class); + + public InstanceH2RegisterDAO(H2Client client) { + super(client); + } + + private static final String UPDATE_HEARTBEAT_TIME_SQL = "update {0} set {1} = ? where {2} = ?"; + + @Override public int getMaxInstanceId() { + return getMaxId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public int getMinInstanceId() { + return getMinId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public void save(Instance instance) { + H2Client client = getClient(); + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_ID, instance.getId()); + source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId()); + source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId()); + source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID()); + source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime()); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime()); + source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo()); + String sql = SqlBuilder.buildBatchInsertSql(InstanceTable.TABLE, source.keySet()); + Object[] params = source.values().toArray(new Object[0]); + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } + + @Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, + InstanceTable.COLUMN_ID); + Object[] params = new Object[] {heartbeatTime, instanceId}; + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java similarity index 82% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java index a73762d72eab..adde68951003 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -24,14 +42,14 @@ import java.sql.SQLException; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java new file mode 100644 index 000000000000..cdf16ef704be --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class InstanceHeartBeatH2PersistenceDAO extends H2DAO implements IInstanceHeartBeatPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatH2PersistenceDAO.class); + + public InstanceHeartBeatH2PersistenceDAO(H2Client client) { + super(client); + } + + private static final String GET_INSTANCE_HEARTBEAT_SQL = "select * from {0} where {1} = ?"; + + @Override public Instance get(String id) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + Instance instance = new Instance(id); + instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID)); + instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME)); + return instance; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Instance data) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public H2SqlEntity prepareBatchUpdate(Instance data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, data.getHeartBeatTime()); + String sql = SqlBuilder.buildBatchUpdateSql(InstanceTable.TABLE, source.keySet(), InstanceTable.COLUMN_INSTANCE_ID); + entity.setSql(sql); + List params = new ArrayList<>(source.values()); + params.add(data.getId()); + entity.setParams(params.toArray(new Object[0])); + return entity; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java similarity index 84% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java index 895254fc5118..fa2bc71cae34 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetric; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java similarity index 83% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java index 7390a99c3083..1a5007843813 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import com.google.gson.JsonArray; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java new file mode 100644 index 000000000000..c47d6a4f4ea6 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; + +/** + * @author peng-yongsheng, clevertension + */ +public class MemoryMetricH2PersistenceDAO extends H2DAO implements IMemoryMetricPersistenceDAO { + + public MemoryMetricH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public MemoryMetric get(String id) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(MemoryMetric data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(MemoryMetricTable.COLUMN_ID, data.getId()); + source.put(MemoryMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); + source.put(MemoryMetricTable.COLUMN_IS_HEAP, data.getIsHeap()); + source.put(MemoryMetricTable.COLUMN_INIT, data.getInit()); + source.put(MemoryMetricTable.COLUMN_MAX, data.getMax()); + source.put(MemoryMetricTable.COLUMN_USED, data.getUsed()); + source.put(MemoryMetricTable.COLUMN_COMMITTED, data.getCommitted()); + source.put(MemoryMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + String sql = SqlBuilder.buildBatchInsertSql(MemoryMetricTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(MemoryMetric data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java new file mode 100644 index 000000000000..c8286db1e9d5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author clevertension + */ +public class MemoryMetricH2UIDAO extends H2DAO implements IMemoryMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(MemoryMetricH2UIDAO.class); + private static final String GET_MEMORY_METRIC_SQL = "select * from {0} where {1} =?"; + + public MemoryMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) { + H2Client client = getClient(); + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; + String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID); + Object[] params = new Object[] {id}; + JsonObject metric = new JsonObject(); + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + metric.addProperty("max", rs.getInt(MemoryMetricTable.COLUMN_MAX)); + metric.addProperty("init", rs.getInt(MemoryMetricTable.COLUMN_INIT)); + metric.addProperty("used", rs.getInt(MemoryMetricTable.COLUMN_USED)); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + metric.addProperty("used", 0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return metric; + } + + @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID); + List idList = new ArrayList<>(); + long timeBucket = startTimeBucket; + do { + timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; + idList.add(id); + } + while (timeBucket <= endTimeBucket); + + JsonObject metric = new JsonObject(); + JsonArray usedMetric = new JsonArray(); + + idList.forEach(id -> { + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + metric.addProperty("max", rs.getLong(MemoryMetricTable.COLUMN_MAX)); + metric.addProperty("init", rs.getLong(MemoryMetricTable.COLUMN_INIT)); + usedMetric.add(rs.getLong(MemoryMetricTable.COLUMN_USED)); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + usedMetric.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + metric.add("used", usedMetric); + return metric; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java new file mode 100644 index 000000000000..8a33a2c8cb34 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; + +/** + * @author peng-yongsheng, clevertension + */ +public class MemoryPoolMetricH2PersistenceDAO extends H2DAO implements IMemoryPoolMetricPersistenceDAO { + + public MemoryPoolMetricH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public MemoryPoolMetric get(String id) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(MemoryPoolMetric data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(MemoryPoolMetricTable.COLUMN_ID, data.getId()); + source.put(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); + source.put(MemoryPoolMetricTable.COLUMN_POOL_TYPE, data.getPoolType()); + source.put(MemoryPoolMetricTable.COLUMN_INIT, data.getInit()); + source.put(MemoryPoolMetricTable.COLUMN_MAX, data.getMax()); + source.put(MemoryPoolMetricTable.COLUMN_USED, data.getUsed()); + source.put(MemoryPoolMetricTable.COLUMN_COMMITTED, data.getCommitted()); + source.put(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + + String sql = SqlBuilder.buildBatchInsertSql(MemoryPoolMetricTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(MemoryPoolMetric data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java new file mode 100644 index 000000000000..6efdfede8d0d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author clevertension + */ +public class MemoryPoolMetricH2UIDAO extends H2DAO implements IMemoryPoolMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(MemoryPoolMetricH2UIDAO.class); + private static final String GET_MEMORY_POOL_METRIC_SQL = "select * from {0} where {1} = ?"; + + public MemoryPoolMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override public JsonObject getMetric(int instanceId, long timeBucket, int poolType) { + H2Client client = getClient(); + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; + String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.COLUMN_ID); + Object[] params = new Object[] {id}; + JsonObject metric = new JsonObject(); + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + metric.addProperty("max", rs.getInt(MemoryPoolMetricTable.COLUMN_MAX)); + metric.addProperty("init", rs.getInt(MemoryPoolMetricTable.COLUMN_INIT)); + metric.addProperty("used", rs.getInt(MemoryPoolMetricTable.COLUMN_USED)); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + metric.addProperty("used", 0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return metric; + } + + @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.COLUMN_ID); + List idList = new ArrayList<>(); + long timeBucket = startTimeBucket; + do { + timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); + String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; + idList.add(id); + } + while (timeBucket <= endTimeBucket); + + JsonObject metric = new JsonObject(); + JsonArray usedMetric = new JsonArray(); + + idList.forEach(id -> { + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + metric.addProperty("max", rs.getLong(MemoryPoolMetricTable.COLUMN_MAX)); + metric.addProperty("init", rs.getLong(MemoryPoolMetricTable.COLUMN_INIT)); + usedMetric.add(rs.getLong(MemoryPoolMetricTable.COLUMN_USED)); + } else { + metric.addProperty("max", 0); + metric.addProperty("init", 0); + usedMetric.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + metric.add("used", usedMetric); + return metric; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java new file mode 100644 index 000000000000..e6c77c01433c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class SegmentCostH2PersistenceDAO extends H2DAO implements ISegmentCostPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentCostH2PersistenceDAO.class); + + public SegmentCostH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public SegmentCost get(String id) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(SegmentCost data) { + logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId()); + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(SegmentCostTable.COLUMN_ID, data.getId()); + source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getSegmentId()); + source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getApplicationId()); + source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getServiceName()); + source.put(SegmentCostTable.COLUMN_COST, data.getCost()); + source.put(SegmentCostTable.COLUMN_START_TIME, data.getStartTime()); + source.put(SegmentCostTable.COLUMN_END_TIME, data.getEndTime()); + source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getIsError()); + source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + logger.debug("segment cost source: {}", source.toString()); + + String sql = SqlBuilder.buildBatchInsertSql(SegmentCostTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(SegmentCost data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java similarity index 81% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java index 45012698c942..3f8a4e6627d4 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -24,15 +42,15 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; import org.elasticsearch.search.sort.SortOrder; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java new file mode 100644 index 000000000000..944443942341 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.segment.Segment; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class SegmentH2PersistenceDAO extends H2DAO implements ISegmentPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentH2PersistenceDAO.class); + + public SegmentH2PersistenceDAO(H2Client client) { + super(client); + } + + @Override public Segment get(String id) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Segment data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(SegmentTable.COLUMN_ID, data.getId()); + source.put(SegmentTable.COLUMN_DATA_BINARY, data.getDataBinary()); + source.put(SegmentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + logger.debug("segment source: {}", source.toString()); + + String sql = SqlBuilder.buildBatchInsertSql(SegmentTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(Segment data) { + return null; + } + + @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java new file mode 100644 index 000000000000..16be1fce08e9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.protobuf.InvalidProtocolBufferException; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class SegmentH2UIDAO extends H2DAO implements ISegmentUIDAO { + private final Logger logger = LoggerFactory.getLogger(SegmentH2UIDAO.class); + private static final String GET_SEGMENT_SQL = "select {0} from {1} where {2} = ?"; + + public SegmentH2UIDAO(H2Client client) { + super(client); + } + + @Override public TraceSegmentObject load(String segmentId) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY, + SegmentTable.TABLE, SegmentTable.COLUMN_ID); + Object[] params = new Object[] {segmentId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY); + try { + return TraceSegmentObject.parseFrom(dataBinary); + } catch (InvalidProtocolBufferException e) { + logger.error(e.getMessage(), e); + } + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java index 16f59b0845f8..794875d1660e 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.service.ServiceEntry; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntry; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java new file mode 100644 index 000000000000..07c57ad0bbea --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryH2UIDAO extends H2DAO implements IServiceEntryUIDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceEntryH2UIDAO.class); + private static final String GET_SERVICE_ENTRY_SQL = "select * from {0} where {1} >= ? and {2} <= ?"; + + public ServiceEntryH2UIDAO(H2Client client) { + super(client); + } + + @Override public JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from, + int size) { + H2Client client = getClient(); + String sql = GET_SERVICE_ENTRY_SQL; + List params = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add(ServiceEntryTable.TABLE); + columns.add(ServiceEntryTable.COLUMN_NEWEST_TIME); + columns.add(ServiceEntryTable.COLUMN_REGISTER_TIME); + params.add(startTime); + params.add(endTime); + int paramIndex = 2; + if (applicationId != 0) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} = ?"; + params.add(applicationId); + columns.add(ServiceEntryTable.COLUMN_APPLICATION_ID); + } + if (StringUtils.isNotEmpty(entryServiceName)) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} = ?"; + params.add(entryServiceName); + columns.add(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME); + } + sql = sql + " limit " + from + "," + size; + sql = SqlBuilder.buildSql(sql, columns); + Object[] p = params.toArray(new Object[0]); + JsonArray serviceArray = new JsonArray(); + JsonObject response = new JsonObject(); + int index = 0; + try (ResultSet rs = client.executeQuery(sql, p)) { + while (rs.next()) { + int appId = rs.getInt(ServiceEntryTable.COLUMN_APPLICATION_ID); + int entryServiceId = rs.getInt(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID); + String entryServiceName1 = rs.getString(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME); + + JsonObject row = new JsonObject(); + row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID), entryServiceId); + row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME), entryServiceName1); + row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_APPLICATION_ID), appId); + serviceArray.add(row); + index++; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + response.addProperty("total", index); + response.add("array", serviceArray); + + return response; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java similarity index 84% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java index 0f93bca324e3..b57f2aa09e18 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceMetricH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.service.ServiceMetric; -import org.skywalking.apm.collector.storage.table.service.ServiceMetricTable; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java new file mode 100644 index 000000000000..bb87c12d17f9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameH2CacheDAO.class); + + private static final String GET_SERVICE_NAME_SQL = "select {0},{1} from {2} where {3} = ?"; + private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1"; + + public ServiceNameH2CacheDAO(H2Client client) { + super(client); + } + + @Override public String getServiceName(int serviceId) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME, + ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + Object[] params = new Object[] {serviceId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + String serviceName = rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME); + int applicationId = rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID); + return applicationId + Const.ID_SPLIT + serviceName; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return Const.EMPTY_STRING; + } + + @Override public int getServiceId(int applicationId, String serviceName) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID, + ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME); + Object[] params = new Object[] {applicationId, serviceName}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java new file mode 100644 index 000000000000..a944b3d99307 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ServiceNameH2RegisterDAO extends H2DAO implements IServiceNameRegisterDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameH2RegisterDAO.class); + + public ServiceNameH2RegisterDAO(H2Client client) { + super(client); + } + + @Override + public int getMaxServiceId() { + return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override + public int getMinServiceId() { + return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override + public void save(ServiceName serviceName) { + logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName()); + H2Client client = getClient(); + Map source = new HashMap<>(); + source.put(ServiceNameTable.COLUMN_ID, serviceName.getId()); + source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId()); + source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId()); + source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName()); + + String sql = SqlBuilder.buildBatchInsertSql(ServiceNameTable.TABLE, source.keySet()); + Object[] params = source.values().toArray(new Object[0]); + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java similarity index 78% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java index 25eed8aab81d..f69fc8fc850a 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java @@ -16,21 +16,39 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import com.google.gson.JsonObject; import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedHashMap; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java similarity index 86% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java index 38c514cd69d4..cdc3e57020bd 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceMetricH2PersistenceDAO.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.collector.storage.h2.dao; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.dao; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,14 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java new file mode 100644 index 000000000000..f59234eefe0d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.alerting.AlertingListTable; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; + +/** + * @author peng-yongsheng + */ +public class AlertingListH2TableDefine extends H2TableDefine { + + public AlertingListH2TableDefine() { + super(AlertingListTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_LAYER, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_LAYER_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_FIRST_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_LAST_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_EXPECTED, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_ACTUAL, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_VALID, H2ColumnDefine.Type.Boolean.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java new file mode 100644 index 000000000000..ee32c0e510a4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class ApplicationComponentH2TableDefine extends H2TableDefine { + + public ApplicationComponentH2TableDefine() { + super(ApplicationComponentTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java new file mode 100644 index 000000000000..75892fbab18e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; + +/** + * @author peng-yongsheng + */ +public class ApplicationH2TableDefine extends H2TableDefine { + + public ApplicationH2TableDefine() { + super(ApplicationTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_APPLICATION_CODE, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java new file mode 100644 index 000000000000..109b983d01a9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class ApplicationMappingH2TableDefine extends H2TableDefine { + + public ApplicationMappingH2TableDefine() { + super(ApplicationMappingTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java similarity index 76% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java index 45758e2e7838..fb7ef96d8100 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ApplicationReferenceMetricH2TableDefine.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.storage.h2.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java new file mode 100644 index 000000000000..ac831cd23d67 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; + +/** + * @author peng-yongsheng + */ +public class CpuMetricH2TableDefine extends H2TableDefine { + + public CpuMetricH2TableDefine() { + super(CpuMetricTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_USAGE_PERCENT, H2ColumnDefine.Type.Double.name())); + addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java new file mode 100644 index 000000000000..cef8d7910627 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class GCMetricH2TableDefine extends H2TableDefine { + + public GCMetricH2TableDefine() { + super(GCMetricTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_PHRASE, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_COUNT, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java new file mode 100644 index 000000000000..958081301052 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceH2TableDefine extends H2TableDefine { + + public GlobalTraceH2TableDefine() { + super(GlobalTraceTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java new file mode 100644 index 000000000000..25f4b0d85556 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class InstanceH2TableDefine extends H2TableDefine { + + public InstanceH2TableDefine() { + super(InstanceTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_AGENT_UUID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_REGISTER_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_HEARTBEAT_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceTable.COLUMN_OS_INFO, H2ColumnDefine.Type.Varchar.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java new file mode 100644 index 000000000000..6a3806d034c9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricH2TableDefine extends H2TableDefine { + + public InstanceMetricH2TableDefine() { + super(InstanceMetricTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); + + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + + addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java new file mode 100644 index 000000000000..0b60078a1f44 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricH2TableDefine extends H2TableDefine { + + public MemoryMetricH2TableDefine() { + super(MemoryMetricTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_IS_HEAP, H2ColumnDefine.Type.Boolean.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_INIT, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_MAX, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_USED, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_COMMITTED, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java new file mode 100644 index 000000000000..131a511853a5 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; + +/** + * @author peng-yongsheng + */ +public class MemoryPoolMetricH2TableDefine extends H2TableDefine { + + public MemoryPoolMetricH2TableDefine() { + super(MemoryPoolMetricTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_POOL_TYPE, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_INIT, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_MAX, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_USED, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_COMMITTED, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java new file mode 100644 index 000000000000..50a4f0cb65ec --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; + +/** + * @author peng-yongsheng + */ +public class SegmentCostH2TableDefine extends H2TableDefine { + + public SegmentCostH2TableDefine() { + super(SegmentCostTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_COST, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_START_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_END_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_IS_ERROR, H2ColumnDefine.Type.Boolean.name())); + addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java new file mode 100644 index 000000000000..f9522f8766f1 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; + +/** + * @author peng-yongsheng + */ +public class SegmentH2TableDefine extends H2TableDefine { + + public SegmentH2TableDefine() { + super(SegmentTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(SegmentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentTable.COLUMN_DATA_BINARY, H2ColumnDefine.Type.BINARY.name())); + addColumn(new H2ColumnDefine(SegmentTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java new file mode 100644 index 000000000000..bd2448af7fb2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryH2TableDefine extends H2TableDefine { + + public ServiceEntryH2TableDefine() { + super(ServiceEntryTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_REGISTER_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_NEWEST_TIME, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java new file mode 100644 index 000000000000..7cfe5410ae9b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricH2TableDefine extends H2TableDefine { + + public ServiceMetricH2TableDefine() { + super(ServiceMetricTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_SERVICE_ID, H2ColumnDefine.Type.Int.name())); + + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); + + addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java new file mode 100644 index 000000000000..c465921bf6ec --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; + +/** + * @author peng-yongsheng + */ +public class ServiceNameH2TableDefine extends H2TableDefine { + + public ServiceNameH2TableDefine() { + super(ServiceNameTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, H2ColumnDefine.Type.Int.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java index 0c570829c3ca..45bbed664c6d 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/ServiceReferenceMetricH2TableDefine.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.collector.storage.h2.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.storage.h2.define; -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java deleted file mode 100644 index e3d9f1f09010..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2; - -import java.util.Properties; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.storage.StorageException; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.skywalking.apm.collector.storage.dao.IAlertingListPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller; -import org.skywalking.apm.collector.storage.h2.dao.AlertingListH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationComponentH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationComponentH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationH2CacheDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationH2RegisterDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationMappingH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationMappingH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationReferenceMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ApplicationReferenceMetricH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.CpuMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.CpuMetricH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.GCMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.GCMetricH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.InstanceH2CacheDAO; -import org.skywalking.apm.collector.storage.h2.dao.InstanceH2RegisterDAO; -import org.skywalking.apm.collector.storage.h2.dao.InstanceH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.InstanceHeartBeatH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.InstanceMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.InstanceMetricH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.MemoryMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.MemoryMetricH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.SegmentCostH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.SegmentCostH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.SegmentH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.SegmentH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceEntryH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceEntryH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceMetricH2PersistenceDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceNameH2CacheDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceNameH2RegisterDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceReferenceH2UIDAO; -import org.skywalking.apm.collector.storage.h2.dao.ServiceReferenceMetricH2PersistenceDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class StorageModuleH2Provider extends ModuleProvider { - - private final Logger logger = LoggerFactory.getLogger(StorageModuleH2Provider.class); - - private static final String URL = "url"; - private static final String USER_NAME = "user_name"; - private static final String PASSWORD = "password"; - - private H2Client h2Client; - - @Override public String name() { - return "h2"; - } - - @Override public Class module() { - return StorageModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - String url = config.getProperty(URL); - String userName = config.getProperty(USER_NAME); - String password = config.getProperty(PASSWORD); - h2Client = new H2Client(url, userName, password); - - this.registerServiceImplementation(IBatchDAO.class, new BatchH2DAO(h2Client)); - registerCacheDAO(); - registerRegisterDAO(); - registerPersistenceDAO(); - registerUiDAO(); - registerAlertingDAO(); - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - try { - h2Client.initialize(); - - H2StorageInstaller installer = new H2StorageInstaller(); - installer.install(h2Client); - } catch (H2ClientException | StorageException e) { - logger.error(e.getMessage(), e); - } - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[0]; - } - - private void registerCacheDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IApplicationCacheDAO.class, new ApplicationH2CacheDAO(h2Client)); - this.registerServiceImplementation(IInstanceCacheDAO.class, new InstanceH2CacheDAO(h2Client)); - this.registerServiceImplementation(IServiceNameCacheDAO.class, new ServiceNameH2CacheDAO(h2Client)); - } - - private void registerRegisterDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IApplicationRegisterDAO.class, new ApplicationH2RegisterDAO(h2Client)); - this.registerServiceImplementation(IInstanceRegisterDAO.class, new InstanceH2RegisterDAO(h2Client)); - this.registerServiceImplementation(IServiceNameRegisterDAO.class, new ServiceNameH2RegisterDAO(h2Client)); - } - - private void registerPersistenceDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(ICpuMetricPersistenceDAO.class, new CpuMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IGCMetricPersistenceDAO.class, new GCMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IMemoryMetricPersistenceDAO.class, new MemoryMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IMemoryPoolMetricPersistenceDAO.class, new MemoryPoolMetricH2PersistenceDAO(h2Client)); - - this.registerServiceImplementation(IGlobalTracePersistenceDAO.class, new GlobalTraceH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IInstanceMetricPersistenceDAO.class, new InstanceMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IApplicationComponentPersistenceDAO.class, new ApplicationComponentH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IApplicationMappingPersistenceDAO.class, new ApplicationMappingH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IApplicationMetricPersistenceDAO.class, new ApplicationMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IApplicationReferenceMetricPersistenceDAO.class, new ApplicationReferenceMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(ISegmentCostPersistenceDAO.class, new SegmentCostH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(ISegmentPersistenceDAO.class, new SegmentH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IServiceEntryPersistenceDAO.class, new ServiceEntryH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IServiceMetricPersistenceDAO.class, new ServiceMetricH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(IServiceReferenceMetricPersistenceDAO.class, new ServiceReferenceMetricH2PersistenceDAO(h2Client)); - - this.registerServiceImplementation(IInstanceHeartBeatPersistenceDAO.class, new InstanceHeartBeatH2PersistenceDAO(h2Client)); - } - - private void registerUiDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IInstanceUIDAO.class, new InstanceH2UIDAO(h2Client)); - - this.registerServiceImplementation(ICpuMetricUIDAO.class, new CpuMetricH2UIDAO(h2Client)); - this.registerServiceImplementation(IGCMetricUIDAO.class, new GCMetricH2UIDAO(h2Client)); - this.registerServiceImplementation(IMemoryMetricUIDAO.class, new MemoryMetricH2UIDAO(h2Client)); - this.registerServiceImplementation(IMemoryPoolMetricUIDAO.class, new MemoryPoolMetricH2UIDAO(h2Client)); - - this.registerServiceImplementation(IGlobalTraceUIDAO.class, new GlobalTraceH2UIDAO(h2Client)); - this.registerServiceImplementation(IInstanceMetricUIDAO.class, new InstanceMetricH2UIDAO(h2Client)); - this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentH2UIDAO(h2Client)); - this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingH2UIDAO(h2Client)); - this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricH2UIDAO(h2Client)); - this.registerServiceImplementation(ISegmentCostUIDAO.class, new SegmentCostH2UIDAO(h2Client)); - this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentH2UIDAO(h2Client)); - this.registerServiceImplementation(IServiceEntryUIDAO.class, new ServiceEntryH2UIDAO(h2Client)); - this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceH2UIDAO(h2Client)); - } - - private void registerAlertingDAO() throws ServiceNotProvidedException { - this.registerServiceImplementation(IAlertingListPersistenceDAO.class, new AlertingListH2PersistenceDAO(h2Client)); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java deleted file mode 100644 index 61204bdbce4e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/BatchH2DAO.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.base.dao; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class BatchH2DAO extends H2DAO implements IBatchDAO { - - private final Logger logger = LoggerFactory.getLogger(BatchH2DAO.class); - - public BatchH2DAO(H2Client client) { - super(client); - } - - @Override - public void batchPersistence(List batchCollection) { - if (batchCollection != null && batchCollection.size() > 0) { - logger.debug("the batch collection size is {}", batchCollection.size()); - Connection conn; - final Map batchSqls = new HashMap<>(); - try { - conn = getClient().getConnection(); - conn.setAutoCommit(true); - PreparedStatement ps; - for (Object entity : batchCollection) { - H2SqlEntity e = getH2SqlEntity(entity); - String sql = e.getSql(); - if (batchSqls.containsKey(sql)) { - ps = batchSqls.get(sql); - } else { - ps = conn.prepareStatement(sql); - batchSqls.put(sql, ps); - } - - Object[] params = e.getParams(); - if (params != null) { - logger.debug("the sql is {}, params size is {}, params: {}", e.getSql(), params.length, params); - for (int i = 0; i < params.length; i++) { - ps.setObject(i + 1, params[i]); - } - } - ps.addBatch(); - } - - for (String k : batchSqls.keySet()) { - batchSqls.get(k).executeBatch(); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - batchSqls.clear(); - } - } - - private H2SqlEntity getH2SqlEntity(Object entity) { - if (entity instanceof H2SqlEntity) { - return (H2SqlEntity)entity; - } - return null; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java deleted file mode 100644 index b72c8e88c158..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/dao/H2DAO.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.base.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.dao.AbstractDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public abstract class H2DAO extends AbstractDAO { - - private final Logger logger = LoggerFactory.getLogger(H2DAO.class); - - public H2DAO(H2Client client) { - super(client); - } - - protected final int getMaxId(String tableName, String columnName) { - String sql = "select max(" + columnName + ") from " + tableName; - return getIntValueBySQL(sql); - } - - protected final int getMinId(String tableName, String columnName) { - String sql = "select min(" + columnName + ") from " + tableName; - return getIntValueBySQL(sql); - } - - private int getIntValueBySQL(String sql) { - H2Client client = getClient(); - try (ResultSet rs = client.executeQuery(sql, null)) { - if (rs.next()) { - int id = rs.getInt(1); - if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) { - return 0; - } else { - return id; - } - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java deleted file mode 100644 index a944919c6550..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2ColumnDefine.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.base.define; - -import org.skywalking.apm.collector.core.data.ColumnDefine; - -/** - * @author peng-yongsheng - */ -public class H2ColumnDefine extends ColumnDefine { - - public H2ColumnDefine(String name, String type) { - super(name, type); - } - - public enum Type { - Boolean, Varchar, Int, Bigint, BINARY, Double - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java deleted file mode 100644 index fe8c08e3960e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2SqlEntity.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.base.define; - -/** - * @author clevertension - */ -public class H2SqlEntity { - private String sql; - private Object[] params; - - public String getSql() { - return sql; - } - - public void setSql(String sql) { - this.sql = sql; - } - - public Object[] getParams() { - return params; - } - - public void setParams(Object[] params) { - this.params = params; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java deleted file mode 100644 index 088d77166afa..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2StorageInstaller.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.base.define; - -import org.skywalking.apm.collector.client.Client; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.StorageException; -import org.skywalking.apm.collector.storage.StorageInstallException; -import org.skywalking.apm.collector.storage.StorageInstaller; -import org.skywalking.apm.collector.core.data.TableDefine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -/** - * @author peng-yongsheng - */ -public class H2StorageInstaller extends StorageInstaller { - - private final Logger logger = LoggerFactory.getLogger(H2StorageInstaller.class); - - @Override protected void defineFilter(List tableDefines) { - int size = tableDefines.size(); - for (int i = size - 1; i >= 0; i--) { - if (!(tableDefines.get(i) instanceof H2TableDefine)) { - tableDefines.remove(i); - } - } - } - - @Override protected boolean isExists(Client client, TableDefine tableDefine) throws StorageException { - H2Client h2Client = (H2Client)client; - ResultSet rs = null; - try { - logger.info("check if table {} exist ", tableDefine.getName()); - rs = h2Client.getConnection().getMetaData().getTables(null, null, tableDefine.getName().toUpperCase(), null); - if (rs.next()) { - return true; - } - } catch (SQLException | H2ClientException e) { - throw new StorageInstallException(e.getMessage(), e); - } finally { - try { - if (rs != null) { - rs.close(); - } - } catch (SQLException e) { - throw new StorageInstallException(e.getMessage(), e); - } - } - return false; - } - - @Override protected boolean deleteTable(Client client, TableDefine tableDefine) throws StorageException { - H2Client h2Client = (H2Client)client; - try { - h2Client.execute("drop table if exists " + tableDefine.getName()); - return true; - } catch (H2ClientException e) { - throw new StorageInstallException(e.getMessage(), e); - } - } - - @Override protected boolean createTable(Client client, TableDefine tableDefine) throws StorageException { - H2Client h2Client = (H2Client)client; - H2TableDefine h2TableDefine = (H2TableDefine)tableDefine; - - StringBuilder sqlBuilder = new StringBuilder(); - sqlBuilder.append("CREATE TABLE ").append(h2TableDefine.getName()).append(" ("); - - h2TableDefine.getColumnDefines().forEach(columnDefine -> { - H2ColumnDefine h2ColumnDefine = (H2ColumnDefine)columnDefine; - if (h2ColumnDefine.getType().equals(H2ColumnDefine.Type.Varchar.name())) { - sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append("(255),"); - } else { - sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append(","); - } - }); - //remove last comma - sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length()); - sqlBuilder.append(")"); - try { - logger.info("create h2 table with sql {}", sqlBuilder); - h2Client.execute(sqlBuilder.toString()); - } catch (H2ClientException e) { - throw new StorageInstallException(e.getMessage(), e); - } - return true; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java deleted file mode 100644 index cd1b378d8a98..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/base/define/H2TableDefine.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.base.define; - -import org.skywalking.apm.collector.core.data.TableDefine; - -/** - * @author peng-yongsheng - */ -public abstract class H2TableDefine extends TableDefine { - - public H2TableDefine(String name) { - super(name); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java deleted file mode 100644 index 92605f6ee7cc..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2PersistenceDAO.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponent; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ApplicationComponentH2PersistenceDAO extends H2DAO implements IApplicationComponentPersistenceDAO { - private final Logger logger = LoggerFactory.getLogger(ApplicationComponentH2PersistenceDAO.class); - private static final String GET_SQL = "select * from {0} where {1} = ?"; - - public ApplicationComponentH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override - public ApplicationComponent get(String id) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SQL, ApplicationComponentTable.TABLE, ApplicationComponentTable.COLUMN_ID); - Object[] params = new Object[] {id}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - ApplicationComponent applicationComponent = new ApplicationComponent(id); - applicationComponent.setComponentId(rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID)); - applicationComponent.setPeerId(rs.getInt(ApplicationComponentTable.COLUMN_PEER_ID)); - applicationComponent.setTimeBucket(rs.getLong(ApplicationComponentTable.COLUMN_TIME_BUCKET)); - return applicationComponent; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return null; - } - - @Override - public H2SqlEntity prepareBatchInsert(ApplicationComponent data) { - Map source = new HashMap<>(); - H2SqlEntity entity = new H2SqlEntity(); - source.put(ApplicationComponentTable.COLUMN_ID, data.getId()); - source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, data.getComponentId()); - source.put(ApplicationComponentTable.COLUMN_PEER_ID, data.getPeerId()); - source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - String sql = SqlBuilder.buildBatchInsertSql(ApplicationComponentTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override - public H2SqlEntity prepareBatchUpdate(ApplicationComponent data) { - Map source = new HashMap<>(); - H2SqlEntity entity = new H2SqlEntity(); - source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, data.getComponentId()); - source.put(ApplicationComponentTable.COLUMN_PEER_ID, data.getPeerId()); - source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - String sql = SqlBuilder.buildBatchUpdateSql(ApplicationComponentTable.TABLE, source.keySet(), ApplicationComponentTable.COLUMN_ID); - entity.setSql(sql); - List values = new ArrayList<>(source.values()); - values.add(data.getId()); - entity.setParams(values.toArray(new Object[0])); - return entity; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java deleted file mode 100644 index 2de305cead68..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ApplicationComponentH2UIDAO extends H2DAO implements IApplicationComponentUIDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationComponentH2UIDAO.class); - private static final String AGGREGATE_COMPONENT_SQL = "select {0}, {1} from {2} where {3} >= ? and {3} <= ? group by {0}, {1} limit 100"; - - public ApplicationComponentH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonArray load(long startTime, long endTime) { - JsonArray applicationComponentArray = new JsonArray(); - applicationComponentArray.addAll(aggregationComponent(startTime, endTime)); - return applicationComponentArray; - } - - private JsonArray aggregationComponent(long startTime, long endTime) { - H2Client client = getClient(); - - JsonArray applicationComponentArray = new JsonArray(); - String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_PEER_ID, - ApplicationComponentTable.TABLE, ApplicationComponentTable.COLUMN_TIME_BUCKET); - Object[] params = new Object[] {startTime, endTime}; - try (ResultSet rs = client.executeQuery(sql, params)) { - while (rs.next()) { - int peerId = rs.getInt(ApplicationComponentTable.COLUMN_PEER_ID); - int componentId = rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID); - JsonObject applicationComponentObj = new JsonObject(); - applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_COMPONENT_ID, componentId); - applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_PEER_ID, peerId); - applicationComponentArray.add(applicationComponentObj); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return applicationComponentArray; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java deleted file mode 100644 index 75bf3e7803ec..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.ApplicationTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationH2CacheDAO.class); - private static final String GET_APPLICATION_ID_OR_CODE_SQL = "select {0} from {1} where {2} = ?"; - - public ApplicationH2CacheDAO(H2Client client) { - super(client); - } - - @Override - public int getApplicationId(String applicationCode) { - logger.info("get the application getId with application code = {}", applicationCode); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_ID, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_CODE); - - Object[] params = new Object[] {applicationCode}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getInt(1); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } - - @Override public String getApplicationCode(int applicationId) { - logger.debug("get application code, applicationId: {}", applicationId); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); - Object[] params = new Object[] {applicationId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getString(1); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return Const.EMPTY_STRING; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java deleted file mode 100644 index c447e496abed..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2RegisterDAO.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationRegisterDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.Application; -import org.skywalking.apm.collector.storage.table.register.ApplicationTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ApplicationH2RegisterDAO extends H2DAO implements IApplicationRegisterDAO { - private final Logger logger = LoggerFactory.getLogger(ApplicationH2RegisterDAO.class); - - public ApplicationH2RegisterDAO(H2Client client) { - super(client); - } - - @Override - public int getMaxApplicationId() { - return getMaxId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); - } - - @Override - public int getMinApplicationId() { - return getMinId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); - } - - @Override - public void save(Application application) { - H2Client client = getClient(); - - Map source = new HashMap<>(); - source.put(ApplicationTable.COLUMN_ID, application.getId()); - source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode()); - source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId()); - - String sql = SqlBuilder.buildBatchInsertSql(ApplicationTable.TABLE, source.keySet()); - Object[] params = source.values().toArray(new Object[0]); - try { - client.execute(sql, params); - } catch (H2ClientException e) { - logger.error(e.getMessage(), e); - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java deleted file mode 100644 index ff7e4851f9a5..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2PersistenceDAO.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.application.ApplicationMapping; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ApplicationMappingH2PersistenceDAO extends H2DAO implements IApplicationMappingPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationMappingH2PersistenceDAO.class); - private static final String GET_SQL = "select * from {0} where {1} = ?"; - - public ApplicationMappingH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public ApplicationMapping get(String id) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SQL, ApplicationMappingTable.TABLE, ApplicationMappingTable.COLUMN_ID); - Object[] params = new Object[] {id}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - ApplicationMapping applicationMapping = new ApplicationMapping(id); - applicationMapping.setApplicationId(rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID)); - applicationMapping.setAddressId(rs.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID)); - applicationMapping.setTimeBucket(rs.getLong(ApplicationMappingTable.COLUMN_TIME_BUCKET)); - return applicationMapping; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(ApplicationMapping applicationMapping) { - Map source = new HashMap<>(); - H2SqlEntity entity = new H2SqlEntity(); - source.put(ApplicationMappingTable.COLUMN_ID, applicationMapping.getId()); - source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationMapping.getApplicationId()); - source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, applicationMapping.getAddressId()); - source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, applicationMapping.getTimeBucket()); - String sql = SqlBuilder.buildBatchInsertSql(ApplicationMappingTable.TABLE, source.keySet()); - entity.setSql(sql); - - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(ApplicationMapping applicationMapping) { - Map source = new HashMap<>(); - H2SqlEntity entity = new H2SqlEntity(); - source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationMapping.getApplicationId()); - source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, applicationMapping.getAddressId()); - source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, applicationMapping.getTimeBucket()); - String sql = SqlBuilder.buildBatchUpdateSql(ApplicationMappingTable.TABLE, source.keySet(), ApplicationMappingTable.COLUMN_ID); - entity.setSql(sql); - List values = new ArrayList<>(source.values()); - values.add(applicationMapping.getId()); - entity.setParams(values.toArray(new Object[0])); - return entity; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java deleted file mode 100644 index 61eaa8aa7ed3..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ApplicationMappingH2UIDAO extends H2DAO implements IApplicationMappingUIDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationMappingH2UIDAO.class); - private static final String APPLICATION_MAPPING_SQL = "select {0}, {1} from {2} where {3} >= ? and {3} <= ? group by {0}, {1} limit 100"; - - public ApplicationMappingH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonArray load(long startTime, long endTime) { - H2Client client = getClient(); - JsonArray applicationMappingArray = new JsonArray(); - String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID, - ApplicationMappingTable.COLUMN_ADDRESS_ID, ApplicationMappingTable.TABLE, ApplicationMappingTable.COLUMN_TIME_BUCKET); - - Object[] params = new Object[] {startTime, endTime}; - try (ResultSet rs = client.executeQuery(sql, params)) { - while (rs.next()) { - int applicationId = rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID); - int addressId = rs.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID); - JsonObject applicationMappingObj = new JsonObject(); - applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationId); - applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_ADDRESS_ID, addressId); - applicationMappingArray.add(applicationMappingObj); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - logger.debug("node mapping data: {}", applicationMappingArray.toString()); - return applicationMappingArray; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java deleted file mode 100644 index c75a0574fd87..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2PersistenceDAO.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.ICpuMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetric; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class CpuMetricH2PersistenceDAO extends H2DAO implements ICpuMetricPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(CpuMetricH2PersistenceDAO.class); - - public CpuMetricH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public CpuMetric get(String id) { - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(CpuMetric data) { - H2SqlEntity entity = new H2SqlEntity(); - Map source = new HashMap<>(); - source.put(CpuMetricTable.COLUMN_ID, data.getId()); - source.put(CpuMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); - source.put(CpuMetricTable.COLUMN_USAGE_PERCENT, data.getUsagePercent()); - source.put(CpuMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - logger.debug("prepare cpu metric batch insert, getId: {}", data.getId()); - String sql = SqlBuilder.buildBatchInsertSql(CpuMetricTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(CpuMetric data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java deleted file mode 100644 index cec3cd3a21af..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class CpuMetricH2UIDAO extends H2DAO implements ICpuMetricUIDAO { - private final Logger logger = LoggerFactory.getLogger(CpuMetricH2UIDAO.class); - private static final String GET_CPU_METRIC_SQL = "select * from {0} where {1} = ?"; - - public CpuMetricH2UIDAO(H2Client client) { - super(client); - } - - @Override public int getMetric(int instanceId, long timeBucket) { - String id = timeBucket + Const.ID_SPLIT + instanceId; - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID); - Object[] params = new Object[] {id}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getInt(CpuMetricTable.COLUMN_USAGE_PERCENT); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } - - @Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID); - - long timeBucket = startTimeBucket; - List idList = new ArrayList<>(); - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId; - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - idList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { - if (rs.next()) { - double cpuUsed = rs.getDouble(CpuMetricTable.COLUMN_USAGE_PERCENT); - metrics.add((int)(cpuUsed * 100)); - } else { - metrics.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - - return metrics; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java deleted file mode 100644 index 37effa819157..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GCMetricH2PersistenceDAO.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IGCMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.jvm.GCMetric; -import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable; - -/** - * @author peng-yongsheng, clevertension - */ -public class GCMetricH2PersistenceDAO extends H2DAO implements IGCMetricPersistenceDAO { - - public GCMetricH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public GCMetric get(String id) { - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(GCMetric data) { - H2SqlEntity entity = new H2SqlEntity(); - Map source = new HashMap<>(); - source.put(GCMetricTable.COLUMN_ID, data.getId()); - source.put(GCMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); - source.put(GCMetricTable.COLUMN_PHRASE, data.getPhrase()); - source.put(GCMetricTable.COLUMN_COUNT, data.getCount()); - source.put(GCMetricTable.COLUMN_TIME, data.getTime()); - source.put(GCMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - String sql = SqlBuilder.buildBatchInsertSql(GCMetricTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(GCMetric data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java deleted file mode 100644 index 44fc3f06cb46..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2PersistenceDAO.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.global.GlobalTrace; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class GlobalTraceH2PersistenceDAO extends H2DAO implements IGlobalTracePersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2PersistenceDAO.class); - - public GlobalTraceH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public GlobalTrace get(String id) { - throw new UnexpectedException("There is no need to merge stream data with database data."); - } - - @Override public H2SqlEntity prepareBatchUpdate(GlobalTrace data) { - throw new UnexpectedException("There is no need to merge stream data with database data."); - } - - @Override public H2SqlEntity prepareBatchInsert(GlobalTrace data) { - Map source = new HashMap<>(); - H2SqlEntity entity = new H2SqlEntity(); - source.put(GlobalTraceTable.COLUMN_ID, data.getId()); - source.put(GlobalTraceTable.COLUMN_SEGMENT_ID, data.getSegmentId()); - source.put(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, data.getGlobalTraceId()); - source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - logger.debug("global trace source: {}", source.toString()); - - String sql = SqlBuilder.buildBatchInsertSql(GlobalTraceTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java deleted file mode 100644 index cdaac0f26d8e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class GlobalTraceH2UIDAO extends H2DAO implements IGlobalTraceUIDAO { - - private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2UIDAO.class); - - private static final String GET_GLOBAL_TRACE_ID_SQL = "select {0} from {1} where {2} = ? limit 10"; - private static final String GET_SEGMENT_IDS_SQL = "select {0} from {1} where {2} = ? limit 10"; - - public GlobalTraceH2UIDAO(H2Client client) { - super(client); - } - - @Override public List getGlobalTraceId(String segmentId) { - List globalTraceIds = new ArrayList<>(); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, - GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_SEGMENT_ID); - Object[] params = new Object[] {segmentId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - while (rs.next()) { - String globalTraceId = rs.getString(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID); - logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); - globalTraceIds.add(globalTraceId); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return globalTraceIds; - } - - @Override public List getSegmentIds(String globalTraceId) { - List segmentIds = new ArrayList<>(); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID, - GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID); - Object[] params = new Object[] {globalTraceId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - while (rs.next()) { - String segmentId = rs.getString(GlobalTraceTable.COLUMN_SEGMENT_ID); - logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId); - segmentIds.add(segmentId); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return segmentIds; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java deleted file mode 100644 index 0192fa1be21d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceH2CacheDAO extends H2DAO implements IInstanceCacheDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceH2CacheDAO.class); - - private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?"; - private static final String GET_INSTANCE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?"; - - public InstanceH2CacheDAO(H2Client client) { - super(client); - } - - @Override public int getApplicationId(int instanceId) { - logger.info("get the application getId with application getId = {}", instanceId); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); - Object[] params = new Object[] {instanceId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } - - @Override public int getInstanceId(int applicationId, String agentUUID) { - logger.info("get the application getId with application getId = {}, agentUUID = {}", applicationId, agentUUID); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, - InstanceTable.COLUMN_AGENT_UUID); - Object[] params = new Object[] {applicationId, agentUUID}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java deleted file mode 100644 index c719ba50445a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2RegisterDAO.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IInstanceRegisterDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class InstanceH2RegisterDAO extends H2DAO implements IInstanceRegisterDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceH2RegisterDAO.class); - - public InstanceH2RegisterDAO(H2Client client) { - super(client); - } - - private static final String UPDATE_HEARTBEAT_TIME_SQL = "update {0} set {1} = ? where {2} = ?"; - - @Override public int getMaxInstanceId() { - return getMaxId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); - } - - @Override public int getMinInstanceId() { - return getMinId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); - } - - @Override public void save(Instance instance) { - H2Client client = getClient(); - Map source = new HashMap<>(); - source.put(InstanceTable.COLUMN_ID, instance.getId()); - source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId()); - source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId()); - source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID()); - source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime()); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime()); - source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo()); - String sql = SqlBuilder.buildBatchInsertSql(InstanceTable.TABLE, source.keySet()); - Object[] params = source.values().toArray(new Object[0]); - try { - client.execute(sql, params); - } catch (H2ClientException e) { - logger.error(e.getMessage(), e); - } - } - - @Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, - InstanceTable.COLUMN_ID); - Object[] params = new Object[] {heartbeatTime, instanceId}; - try { - client.execute(sql, params); - } catch (H2ClientException e) { - logger.error(e.getMessage(), e); - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java deleted file mode 100644 index 0b2db5bec157..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceHeartBeatH2PersistenceDAO.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class InstanceHeartBeatH2PersistenceDAO extends H2DAO implements IInstanceHeartBeatPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatH2PersistenceDAO.class); - - public InstanceHeartBeatH2PersistenceDAO(H2Client client) { - super(client); - } - - private static final String GET_INSTANCE_HEARTBEAT_SQL = "select * from {0} where {1} = ?"; - - @Override public Instance get(String id) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); - Object[] params = new Object[] {id}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - Instance instance = new Instance(id); - instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID)); - instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME)); - return instance; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(Instance data) { - throw new UnexpectedException("There is no need to merge stream data with database data."); - } - - @Override public H2SqlEntity prepareBatchUpdate(Instance data) { - H2SqlEntity entity = new H2SqlEntity(); - Map source = new HashMap<>(); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, data.getHeartBeatTime()); - String sql = SqlBuilder.buildBatchUpdateSql(InstanceTable.TABLE, source.keySet(), InstanceTable.COLUMN_INSTANCE_ID); - entity.setSql(sql); - List params = new ArrayList<>(source.values()); - params.add(data.getId()); - entity.setParams(params.toArray(new Object[0])); - return entity; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java deleted file mode 100644 index a70569f66829..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2PersistenceDAO.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetric; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; - -/** - * @author peng-yongsheng, clevertension - */ -public class MemoryMetricH2PersistenceDAO extends H2DAO implements IMemoryMetricPersistenceDAO { - - public MemoryMetricH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public MemoryMetric get(String id) { - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(MemoryMetric data) { - H2SqlEntity entity = new H2SqlEntity(); - Map source = new HashMap<>(); - source.put(MemoryMetricTable.COLUMN_ID, data.getId()); - source.put(MemoryMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); - source.put(MemoryMetricTable.COLUMN_IS_HEAP, data.getIsHeap()); - source.put(MemoryMetricTable.COLUMN_INIT, data.getInit()); - source.put(MemoryMetricTable.COLUMN_MAX, data.getMax()); - source.put(MemoryMetricTable.COLUMN_USED, data.getUsed()); - source.put(MemoryMetricTable.COLUMN_COMMITTED, data.getCommitted()); - source.put(MemoryMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - String sql = SqlBuilder.buildBatchInsertSql(MemoryMetricTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(MemoryMetric data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java deleted file mode 100644 index eb796880592e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author clevertension - */ -public class MemoryMetricH2UIDAO extends H2DAO implements IMemoryMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(MemoryMetricH2UIDAO.class); - private static final String GET_MEMORY_METRIC_SQL = "select * from {0} where {1} =?"; - - public MemoryMetricH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) { - H2Client client = getClient(); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID); - Object[] params = new Object[] {id}; - JsonObject metric = new JsonObject(); - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - metric.addProperty("max", rs.getInt(MemoryMetricTable.COLUMN_MAX)); - metric.addProperty("init", rs.getInt(MemoryMetricTable.COLUMN_INIT)); - metric.addProperty("used", rs.getInt(MemoryMetricTable.COLUMN_USED)); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - metric.addProperty("used", 0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return metric; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID); - List idList = new ArrayList<>(); - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonObject metric = new JsonObject(); - JsonArray usedMetric = new JsonArray(); - - idList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { - if (rs.next()) { - metric.addProperty("max", rs.getLong(MemoryMetricTable.COLUMN_MAX)); - metric.addProperty("init", rs.getLong(MemoryMetricTable.COLUMN_INIT)); - usedMetric.add(rs.getLong(MemoryMetricTable.COLUMN_USED)); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - usedMetric.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - - metric.add("used", usedMetric); - return metric; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java deleted file mode 100644 index a89f0ebac92a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2PersistenceDAO.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetric; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; - -/** - * @author peng-yongsheng, clevertension - */ -public class MemoryPoolMetricH2PersistenceDAO extends H2DAO implements IMemoryPoolMetricPersistenceDAO { - - public MemoryPoolMetricH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public MemoryPoolMetric get(String id) { - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(MemoryPoolMetric data) { - H2SqlEntity entity = new H2SqlEntity(); - Map source = new HashMap<>(); - source.put(MemoryPoolMetricTable.COLUMN_ID, data.getId()); - source.put(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, data.getInstanceId()); - source.put(MemoryPoolMetricTable.COLUMN_POOL_TYPE, data.getPoolType()); - source.put(MemoryPoolMetricTable.COLUMN_INIT, data.getInit()); - source.put(MemoryPoolMetricTable.COLUMN_MAX, data.getMax()); - source.put(MemoryPoolMetricTable.COLUMN_USED, data.getUsed()); - source.put(MemoryPoolMetricTable.COLUMN_COMMITTED, data.getCommitted()); - source.put(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - - String sql = SqlBuilder.buildBatchInsertSql(MemoryPoolMetricTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(MemoryPoolMetric data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java deleted file mode 100644 index 5e261c499eba..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author clevertension - */ -public class MemoryPoolMetricH2UIDAO extends H2DAO implements IMemoryPoolMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(MemoryPoolMetricH2UIDAO.class); - private static final String GET_MEMORY_POOL_METRIC_SQL = "select * from {0} where {1} = ?"; - - public MemoryPoolMetricH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket, int poolType) { - H2Client client = getClient(); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; - String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.COLUMN_ID); - Object[] params = new Object[] {id}; - JsonObject metric = new JsonObject(); - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - metric.addProperty("max", rs.getInt(MemoryPoolMetricTable.COLUMN_MAX)); - metric.addProperty("init", rs.getInt(MemoryPoolMetricTable.COLUMN_INIT)); - metric.addProperty("used", rs.getInt(MemoryPoolMetricTable.COLUMN_USED)); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - metric.addProperty("used", 0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return metric; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.COLUMN_ID); - List idList = new ArrayList<>(); - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonObject metric = new JsonObject(); - JsonArray usedMetric = new JsonArray(); - - idList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { - if (rs.next()) { - metric.addProperty("max", rs.getLong(MemoryPoolMetricTable.COLUMN_MAX)); - metric.addProperty("init", rs.getLong(MemoryPoolMetricTable.COLUMN_INIT)); - usedMetric.add(rs.getLong(MemoryPoolMetricTable.COLUMN_USED)); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - usedMetric.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - - metric.add("used", usedMetric); - return metric; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java deleted file mode 100644 index a71982f4c58b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class SegmentCostH2PersistenceDAO extends H2DAO implements ISegmentCostPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(SegmentCostH2PersistenceDAO.class); - - public SegmentCostH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public SegmentCost get(String id) { - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(SegmentCost data) { - logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId()); - H2SqlEntity entity = new H2SqlEntity(); - Map source = new HashMap<>(); - source.put(SegmentCostTable.COLUMN_ID, data.getId()); - source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getSegmentId()); - source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getApplicationId()); - source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getServiceName()); - source.put(SegmentCostTable.COLUMN_COST, data.getCost()); - source.put(SegmentCostTable.COLUMN_START_TIME, data.getStartTime()); - source.put(SegmentCostTable.COLUMN_END_TIME, data.getEndTime()); - source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getIsError()); - source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - logger.debug("segment cost source: {}", source.toString()); - - String sql = SqlBuilder.buildBatchInsertSql(SegmentCostTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(SegmentCost data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java deleted file mode 100644 index 8a2ec233327a..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2PersistenceDAO.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.skywalking.apm.collector.storage.table.segment.Segment; -import org.skywalking.apm.collector.storage.table.segment.SegmentTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class SegmentH2PersistenceDAO extends H2DAO implements ISegmentPersistenceDAO { - - private final Logger logger = LoggerFactory.getLogger(SegmentH2PersistenceDAO.class); - - public SegmentH2PersistenceDAO(H2Client client) { - super(client); - } - - @Override public Segment get(String id) { - return null; - } - - @Override public H2SqlEntity prepareBatchInsert(Segment data) { - Map source = new HashMap<>(); - H2SqlEntity entity = new H2SqlEntity(); - source.put(SegmentTable.COLUMN_ID, data.getId()); - source.put(SegmentTable.COLUMN_DATA_BINARY, data.getDataBinary()); - source.put(SegmentTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); - logger.debug("segment source: {}", source.toString()); - - String sql = SqlBuilder.buildBatchInsertSql(SegmentTable.TABLE, source.keySet()); - entity.setSql(sql); - entity.setParams(source.values().toArray(new Object[0])); - return entity; - } - - @Override public H2SqlEntity prepareBatchUpdate(Segment data) { - return null; - } - - @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java deleted file mode 100644 index 61dd5d873cd1..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.protobuf.InvalidProtocolBufferException; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.segment.SegmentTable; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class SegmentH2UIDAO extends H2DAO implements ISegmentUIDAO { - private final Logger logger = LoggerFactory.getLogger(SegmentH2UIDAO.class); - private static final String GET_SEGMENT_SQL = "select {0} from {1} where {2} = ?"; - - public SegmentH2UIDAO(H2Client client) { - super(client); - } - - @Override public TraceSegmentObject load(String segmentId) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY, - SegmentTable.TABLE, SegmentTable.COLUMN_ID); - Object[] params = new Object[] {segmentId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY); - try { - return TraceSegmentObject.parseFrom(dataBinary); - } catch (InvalidProtocolBufferException e) { - logger.error(e.getMessage(), e); - } - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return null; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java deleted file mode 100644 index e2fc1fad52f9..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2UIDAO.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryH2UIDAO extends H2DAO implements IServiceEntryUIDAO { - - private final Logger logger = LoggerFactory.getLogger(ServiceEntryH2UIDAO.class); - private static final String GET_SERVICE_ENTRY_SQL = "select * from {0} where {1} >= ? and {2} <= ?"; - - public ServiceEntryH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from, - int size) { - H2Client client = getClient(); - String sql = GET_SERVICE_ENTRY_SQL; - List params = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add(ServiceEntryTable.TABLE); - columns.add(ServiceEntryTable.COLUMN_NEWEST_TIME); - columns.add(ServiceEntryTable.COLUMN_REGISTER_TIME); - params.add(startTime); - params.add(endTime); - int paramIndex = 2; - if (applicationId != 0) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} = ?"; - params.add(applicationId); - columns.add(ServiceEntryTable.COLUMN_APPLICATION_ID); - } - if (StringUtils.isNotEmpty(entryServiceName)) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} = ?"; - params.add(entryServiceName); - columns.add(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME); - } - sql = sql + " limit " + from + "," + size; - sql = SqlBuilder.buildSql(sql, columns); - Object[] p = params.toArray(new Object[0]); - JsonArray serviceArray = new JsonArray(); - JsonObject response = new JsonObject(); - int index = 0; - try (ResultSet rs = client.executeQuery(sql, p)) { - while (rs.next()) { - int appId = rs.getInt(ServiceEntryTable.COLUMN_APPLICATION_ID); - int entryServiceId = rs.getInt(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID); - String entryServiceName1 = rs.getString(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME); - - JsonObject row = new JsonObject(); - row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID), entryServiceId); - row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME), entryServiceName1); - row.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceEntryTable.COLUMN_APPLICATION_ID), appId); - serviceArray.add(row); - index++; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - response.addProperty("total", index); - response.add("array", serviceArray); - - return response; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java deleted file mode 100644 index bb4777cc4921..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameH2CacheDAO.class); - - private static final String GET_SERVICE_NAME_SQL = "select {0},{1} from {2} where {3} = ?"; - private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1"; - - public ServiceNameH2CacheDAO(H2Client client) { - super(client); - } - - @Override public String getServiceName(int serviceId) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME, - ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); - Object[] params = new Object[] {serviceId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - String serviceName = rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME); - int applicationId = rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID); - return applicationId + Const.ID_SPLIT + serviceName; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return Const.EMPTY_STRING; - } - - @Override public int getServiceId(int applicationId, String serviceName) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID, - ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME); - Object[] params = new Object[] {applicationId, serviceName}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java deleted file mode 100644 index 8c5c2eaf822e..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2RegisterDAO.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.dao; - -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.collector.client.h2.H2Client; -import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.skywalking.apm.collector.storage.dao.IServiceNameRegisterDAO; -import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.skywalking.apm.collector.storage.table.register.ServiceName; -import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ServiceNameH2RegisterDAO extends H2DAO implements IServiceNameRegisterDAO { - - private final Logger logger = LoggerFactory.getLogger(ServiceNameH2RegisterDAO.class); - - public ServiceNameH2RegisterDAO(H2Client client) { - super(client); - } - - @Override - public int getMaxServiceId() { - return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); - } - - @Override - public int getMinServiceId() { - return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); - } - - @Override - public void save(ServiceName serviceName) { - logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName()); - H2Client client = getClient(); - Map source = new HashMap<>(); - source.put(ServiceNameTable.COLUMN_ID, serviceName.getId()); - source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId()); - source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId()); - source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName()); - - String sql = SqlBuilder.buildBatchInsertSql(ServiceNameTable.TABLE, source.keySet()); - Object[] params = source.values().toArray(new Object[0]); - try { - client.execute(sql, params); - } catch (H2ClientException e) { - logger.error(e.getMessage(), e); - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java deleted file mode 100644 index 5ffa8d9acbad..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/AlertingListH2TableDefine.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.alerting.AlertingListTable; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; - -/** - * @author peng-yongsheng - */ -public class AlertingListH2TableDefine extends H2TableDefine { - - public AlertingListH2TableDefine() { - super(AlertingListTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_LAYER, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_LAYER_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_FIRST_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_LAST_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_EXPECTED, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_ACTUAL, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(AlertingListTable.COLUMN_VALID, H2ColumnDefine.Type.Boolean.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java deleted file mode 100644 index 26bf3b4a8ba0..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationComponentH2TableDefine.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationComponentH2TableDefine extends H2TableDefine { - - public ApplicationComponentH2TableDefine() { - super(ApplicationComponentTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java deleted file mode 100644 index a43fc76f370b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationH2TableDefine.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.register.ApplicationTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationH2TableDefine extends H2TableDefine { - - public ApplicationH2TableDefine() { - super(ApplicationTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_APPLICATION_CODE, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java deleted file mode 100644 index 1b722832c0bc..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ApplicationMappingH2TableDefine.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; - -/** - * @author peng-yongsheng - */ -public class ApplicationMappingH2TableDefine extends H2TableDefine { - - public ApplicationMappingH2TableDefine() { - super(ApplicationMappingTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java deleted file mode 100644 index 52f5fc14bb19..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/CpuMetricH2TableDefine.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; - -/** - * @author peng-yongsheng - */ -public class CpuMetricH2TableDefine extends H2TableDefine { - - public CpuMetricH2TableDefine() { - super(CpuMetricTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_USAGE_PERCENT, H2ColumnDefine.Type.Double.name())); - addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java deleted file mode 100644 index 6b28fa590503..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GCMetricH2TableDefine.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.jvm.GCMetricTable; - -/** - * @author peng-yongsheng - */ -public class GCMetricH2TableDefine extends H2TableDefine { - - public GCMetricH2TableDefine() { - super(GCMetricTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_PHRASE, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_COUNT, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java deleted file mode 100644 index b41b5145abe7..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/GlobalTraceH2TableDefine.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; - -/** - * @author peng-yongsheng - */ -public class GlobalTraceH2TableDefine extends H2TableDefine { - - public GlobalTraceH2TableDefine() { - super(GlobalTraceTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(GlobalTraceTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java deleted file mode 100644 index dff2a5e3a008..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceH2TableDefine.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.register.InstanceTable; - -/** - * @author peng-yongsheng - */ -public class InstanceH2TableDefine extends H2TableDefine { - - public InstanceH2TableDefine() { - super(InstanceTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_AGENT_UUID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_REGISTER_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_HEARTBEAT_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceTable.COLUMN_OS_INFO, H2ColumnDefine.Type.Varchar.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java deleted file mode 100644 index de805e16a63d..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/InstanceMetricH2TableDefine.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricH2TableDefine extends H2TableDefine { - - public InstanceMetricH2TableDefine() { - super(InstanceMetricTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); - - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - - addColumn(new H2ColumnDefine(InstanceMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java deleted file mode 100644 index cb802c12c050..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryMetricH2TableDefine.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricH2TableDefine extends H2TableDefine { - - public MemoryMetricH2TableDefine() { - super(MemoryMetricTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_IS_HEAP, H2ColumnDefine.Type.Boolean.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_INIT, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_MAX, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_USED, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_COMMITTED, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java deleted file mode 100644 index b612d93e7c7b..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/MemoryPoolMetricH2TableDefine.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; - -/** - * @author peng-yongsheng - */ -public class MemoryPoolMetricH2TableDefine extends H2TableDefine { - - public MemoryPoolMetricH2TableDefine() { - super(MemoryPoolMetricTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_POOL_TYPE, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_INIT, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_MAX, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_USED, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_COMMITTED, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java deleted file mode 100644 index e3a289afb042..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; - -/** - * @author peng-yongsheng - */ -public class SegmentCostH2TableDefine extends H2TableDefine { - - public SegmentCostH2TableDefine() { - super(SegmentCostTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_COST, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_START_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_END_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_IS_ERROR, H2ColumnDefine.Type.Boolean.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java deleted file mode 100644 index d303841d5371..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/SegmentH2TableDefine.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.segment.SegmentTable; - -/** - * @author peng-yongsheng - */ -public class SegmentH2TableDefine extends H2TableDefine { - - public SegmentH2TableDefine() { - super(SegmentTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(SegmentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentTable.COLUMN_DATA_BINARY, H2ColumnDefine.Type.BINARY.name())); - addColumn(new H2ColumnDefine(SegmentTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java deleted file mode 100644 index 4fadf515dcbd..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceEntryH2TableDefine.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; - -/** - * @author peng-yongsheng - */ -public class ServiceEntryH2TableDefine extends H2TableDefine { - - public ServiceEntryH2TableDefine() { - super(ServiceEntryTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_REGISTER_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceEntryTable.COLUMN_NEWEST_TIME, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java deleted file mode 100644 index b2fd9a7be457..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceMetricH2TableDefine.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.service.ServiceMetricTable; - -/** - * @author peng-yongsheng - */ -public class ServiceMetricH2TableDefine extends H2TableDefine { - - public ServiceMetricH2TableDefine() { - super(ServiceMetricTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_SERVICE_ID, H2ColumnDefine.Type.Int.name())); - - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_CALLS, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_MQ_TRANSACTION_ERROR_DURATION_SUM, H2ColumnDefine.Type.Bigint.name())); - - addColumn(new H2ColumnDefine(ServiceMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java deleted file mode 100644 index a8d0d9ac6dd5..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/define/ServiceNameH2TableDefine.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.storage.h2.define; - -import org.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; - -/** - * @author peng-yongsheng - */ -public class ServiceNameH2TableDefine extends H2TableDefine { - - public ServiceNameH2TableDefine() { - super(ServiceNameTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, H2ColumnDefine.Type.Int.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define index 833365ed3edc..931ffdea8d69 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define @@ -1,18 +1,18 @@ -org.skywalking.apm.collector.storage.h2.define.ApplicationH2TableDefine -org.skywalking.apm.collector.storage.h2.define.InstanceH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ServiceNameH2TableDefine -org.skywalking.apm.collector.storage.h2.define.CpuMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.GCMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.MemoryMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.MemoryPoolMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.GlobalTraceH2TableDefine -org.skywalking.apm.collector.storage.h2.define.InstanceMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ApplicationComponentH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ApplicationMappingH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ApplicationReferenceMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.SegmentCostH2TableDefine -org.skywalking.apm.collector.storage.h2.define.SegmentH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ServiceEntryH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ServiceMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.ServiceReferenceMetricH2TableDefine -org.skywalking.apm.collector.storage.h2.define.AlertingListH2TableDefine \ No newline at end of file +org.apache.skywalking.apm.collector.storage.h2.define.ApplicationH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.InstanceH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ServiceNameH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.CpuMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.GCMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.MemoryMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.MemoryPoolMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.GlobalTraceH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.InstanceMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ApplicationComponentH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ApplicationMappingH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ApplicationReferenceMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.SegmentCostH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.SegmentH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ServiceEntryH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ServiceMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.ServiceReferenceMetricH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.AlertingListH2TableDefine diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..6f47e23bd0d8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.storage.h2.StorageModuleH2Provider diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index 2bcb4c184dc0..000000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.storage.h2.StorageModuleH2Provider diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/timer/PersistenceTimer.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/timer/PersistenceTimer.java new file mode 100644 index 000000000000..7ae4abfca6c5 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/timer/PersistenceTimer.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.timer; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class PersistenceTimer { + + private final Logger logger = LoggerFactory.getLogger(PersistenceTimer.class); + + public void start(ModuleManager moduleManager, List persistenceWorkers) { + logger.info("persistence timer start"); + //TODO timer value config +// final long timeInterval = EsConfig.Es.Persistence.Timer.VALUE * 1000; + final long timeInterval = 3; + IBatchDAO batchDAO = moduleManager.find(StorageModule.NAME).getService(IBatchDAO.class); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> extractDataAndSave(batchDAO, persistenceWorkers), 1, timeInterval, TimeUnit.SECONDS); + } + + private void extractDataAndSave(IBatchDAO batchDAO, List persistenceWorkers) { + try { + List batchAllCollection = new ArrayList<>(); + persistenceWorkers.forEach((PersistenceWorker worker) -> { + logger.debug("extract {} worker data and save", worker.getClass().getName()); + try { + worker.flushAndSwitch(); + List batchCollection = worker.buildBatchCollection(); + logger.debug("extract {} worker data size: {}", worker.getClass().getName(), batchCollection.size()); + batchAllCollection.addAll(batchCollection); + } catch (WorkerException e) { + logger.error(e.getMessage(), e); + } + }); + + batchDAO.batchPersistence(batchAllCollection); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } finally { + logger.debug("persistence data save finish"); + } + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java new file mode 100644 index 000000000000..2456d8d076db --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; + +/** + * The AbstractLocalAsyncWorker implementations represent workers, + * which receive local asynchronous message. + * + * @author peng-yongsheng + * @since v3.0-2017 + */ +public abstract class AbstractLocalAsyncWorker extends AbstractWorker { + + public AbstractLocalAsyncWorker(ModuleManager moduleManager) { + super(moduleManager); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java new file mode 100644 index 000000000000..2f83d45eea2c --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.apache.skywalking.apm.collector.queue.service.QueueCreatorService; + +/** + * @author peng-yongsheng + */ +public abstract class AbstractLocalAsyncWorkerProvider> extends AbstractWorkerProvider { + + public abstract int queueSize(); + + private final QueueCreatorService queueCreatorService; + + public AbstractLocalAsyncWorkerProvider(ModuleManager moduleManager, + QueueCreatorService queueCreatorService) { + super(moduleManager); + this.queueCreatorService = queueCreatorService; + } + + @Override + public final WorkerRef create(WorkerCreateListener workerCreateListener) { + WORKER_TYPE localAsyncWorker = workerInstance(getModuleManager()); + workerCreateListener.addWorker(localAsyncWorker); + + LocalAsyncWorkerRef localAsyncWorkerRef = new LocalAsyncWorkerRef<>(localAsyncWorker); + QueueEventHandler queueEventHandler = queueCreatorService.create(queueSize(), localAsyncWorkerRef); + localAsyncWorkerRef.setQueueEventHandler(queueEventHandler); + return localAsyncWorkerRef; + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java new file mode 100644 index 000000000000..1a96bafe060b --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.Selector; + +/** + * The AbstractRemoteWorker implementations represent workers, + * which receive remote messages. + *

+ * Usually, the implementations are doing persistent, or aggregate works. + * + * @author peng-yongsheng + * @since v3.0-2017 + */ +public abstract class AbstractRemoteWorker extends AbstractWorker { + + public AbstractRemoteWorker(ModuleManager moduleManager) { + super(moduleManager); + } + + public abstract Selector selector(); +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java new file mode 100644 index 000000000000..c2a75fe7a000 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; + +/** + * The AbstractRemoteWorkerProvider implementations represent providers, + * which create instance of cluster workers whose implemented {@link AbstractRemoteWorker}. + *

+ * + * @author peng-yongsheng + * @since v3.0-2017 + */ +public abstract class AbstractRemoteWorkerProvider> extends AbstractWorkerProvider { + + private final RemoteSenderService remoteSenderService; + private final int graphId; + + public AbstractRemoteWorkerProvider(ModuleManager moduleManager, RemoteSenderService remoteSenderService, + int graphId) { + super(moduleManager); + this.remoteSenderService = remoteSenderService; + this.graphId = graphId; + } + + /** + * Create the worker instance into akka system, the akka system will control the cluster worker life cycle. + * + * @return The created worker reference. See {@link RemoteWorkerRef} worker instance, when the worker provider not + * find then Throw this Exception. + */ + @Override final public RemoteWorkerRef create(WorkerCreateListener workerCreateListener) { + WORKER_TYPE remoteWorker = workerInstance(getModuleManager()); + workerCreateListener.addWorker(remoteWorker); + return new RemoteWorkerRef<>(remoteWorker, remoteSenderService, graphId); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorker.java new file mode 100644 index 000000000000..7f24a376f84d --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorker.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.graph.Next; +import org.apache.skywalking.apm.collector.core.graph.NodeProcessor; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public abstract class AbstractWorker implements NodeProcessor { + + private final Logger logger = LoggerFactory.getLogger(AbstractWorker.class); + + private final ModuleManager moduleManager; + + public AbstractWorker(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + public final ModuleManager getModuleManager() { + return moduleManager; + } + + private Next next; + + /** + * The data process logic in this method. + * + * @param message Cast the message object to a expect subclass. + * @throws WorkerException Don't handle the exception, throw it. + */ + protected abstract void onWork(INPUT message) throws WorkerException; + + @Override public final void process(INPUT input, Next next) { + this.next = next; + try { + onWork(input); + } catch (WorkerException e) { + logger.error(e.getMessage(), e); + } + } + + protected final void onNext(OUTPUT message) { + next.execute(message); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java new file mode 100644 index 000000000000..ab1d17b92a37 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; + +/** + * @author peng-yongsheng + */ +public abstract class AbstractWorkerProvider> implements Provider { + + private final ModuleManager moduleManager; + + public AbstractWorkerProvider(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + public final ModuleManager getModuleManager() { + return moduleManager; + } + + public abstract WORKER_TYPE workerInstance(ModuleManager moduleManager); +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java new file mode 100644 index 000000000000..024eacf6f248 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.CollectorException; +import org.apache.skywalking.apm.collector.core.graph.NodeProcessor; +import org.apache.skywalking.apm.collector.queue.base.QueueEventHandler; +import org.apache.skywalking.apm.collector.queue.base.QueueExecutor; + +/** + * @author peng-yongsheng + */ +public class LocalAsyncWorkerRef extends WorkerRef implements QueueExecutor { + + private QueueEventHandler queueEventHandler; + + LocalAsyncWorkerRef(NodeProcessor destinationHandler) { + super(destinationHandler); + } + + public void setQueueEventHandler(QueueEventHandler queueEventHandler) { + this.queueEventHandler = queueEventHandler; + } + + @Override public void execute(INPUT input) throws CollectorException { + out(input); + } + + @Override protected void in(INPUT input) { + queueEventHandler.tell(input); + } + + @Override protected void out(INPUT input) { + super.out(input); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/Provider.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/Provider.java new file mode 100644 index 000000000000..93c378f4eb45 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/Provider.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +/** + * @author peng-yongsheng + */ +public interface Provider { + + WorkerRef create(WorkerCreateListener workerCreateListener) throws ProviderNotFoundException; +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java new file mode 100644 index 000000000000..b9a2a31992df --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +public class ProviderNotFoundException extends Exception { + public ProviderNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java new file mode 100644 index 000000000000..701b224ec174 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.remote.service.RemoteSenderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class RemoteWorkerRef extends WorkerRef { + + private final Logger logger = LoggerFactory.getLogger(RemoteWorkerRef.class); + + private final AbstractRemoteWorker remoteWorker; + private final RemoteSenderService remoteSenderService; + private final int graphId; + + RemoteWorkerRef(AbstractRemoteWorker remoteWorker, RemoteSenderService remoteSenderService, + int graphId) { + super(remoteWorker); + this.remoteWorker = remoteWorker; + this.remoteSenderService = remoteSenderService; + this.graphId = graphId; + } + + @Override protected void in(INPUT message) { + try { + RemoteSenderService.Mode mode = remoteSenderService.send(this.graphId, this.remoteWorker.id(), message, this.remoteWorker.selector()); + if (mode.equals(RemoteSenderService.Mode.Local)) { + out(message); + } + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + } + + @Override protected void out(INPUT input) { + super.out(input); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java new file mode 100644 index 000000000000..7b4a7d764c07 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +public class UsedRoleNameException extends Exception { + public UsedRoleNameException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java new file mode 100644 index 000000000000..35ce5fc681eb --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; + +/** + * @author peng-yongsheng + */ +public class WorkerCreateListener { + + private final List persistenceWorkers; + + public WorkerCreateListener() { + this.persistenceWorkers = new ArrayList<>(); + } + + public void addWorker(AbstractWorker worker) { + if (worker instanceof PersistenceWorker) { + persistenceWorkers.add((PersistenceWorker)worker); + } + } + + public List getPersistenceWorkers() { + return persistenceWorkers; + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerException.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerException.java new file mode 100644 index 000000000000..88a64e356130 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerException.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.CollectorException; + +/** + * Defines a general exception a worker can throw when it + * encounters difficulty. + * + * @author peng-yongsheng + * @since v3.1-2017 + */ +public class WorkerException extends CollectorException { + + public WorkerException(String message) { + super(message); + } + + public WorkerException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java new file mode 100644 index 000000000000..31a886d18516 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +/** + * This exception is raised when worker fails to process job during "call" or "ask" + * + * @author peng-yongsheng + * @since v3.1-2017 + */ +public class WorkerInvokeException extends WorkerException { + + public WorkerInvokeException(String message) { + super(message); + } + + public WorkerInvokeException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java new file mode 100644 index 000000000000..878224461898 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +public class WorkerNotFoundException extends WorkerException { + public WorkerNotFoundException(String message) { + super(message); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerRef.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerRef.java new file mode 100644 index 000000000000..c8a93300d378 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/base/WorkerRef.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.base; + +import org.apache.skywalking.apm.collector.core.graph.NodeProcessor; +import org.apache.skywalking.apm.collector.core.graph.WayToNode; + +/** + * @author peng-yongsheng + */ +public abstract class WorkerRef extends WayToNode { + WorkerRef(NodeProcessor destinationHandler) { + super(destinationHandler); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java new file mode 100644 index 000000000000..2a3126a442ce --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.impl; + +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.apache.skywalking.apm.collector.stream.worker.impl.data.DataCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public abstract class AggregationWorker extends AbstractLocalAsyncWorker { + + private final Logger logger = LoggerFactory.getLogger(AggregationWorker.class); + + private DataCache dataCache; + private int messageNum; + + public AggregationWorker(ModuleManager moduleManager) { + super(moduleManager); + this.dataCache = new DataCache<>(); + } + + @SuppressWarnings("unchecked") + protected OUTPUT transform(INPUT message) { + return (OUTPUT)message; + } + + @Override protected final void onWork(INPUT message) throws WorkerException { + OUTPUT output = transform(message); + messageNum++; + aggregate(output); + + if (messageNum >= 100) { + sendToNext(); + messageNum = 0; + } + if (output.isEndOfBatch()) { + sendToNext(); + } + } + + private void sendToNext() throws WorkerException { + dataCache.switchPointer(); + while (dataCache.getLast().isWriting()) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + throw new WorkerException(e.getMessage(), e); + } + } + dataCache.getLast().collection().forEach((String id, OUTPUT data) -> { + logger.debug(data.toString()); + onNext(data); + }); + dataCache.finishReadingLast(); + } + + private void aggregate(OUTPUT message) { + dataCache.writing(); + if (dataCache.containsKey(message.getId())) { + dataCache.get(message.getId()).mergeData(message); + } else { + dataCache.put(message.getId(), message); + } + dataCache.finishWriting(); + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java new file mode 100644 index 000000000000..01e8a79585a3 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.impl; + +/** + * @author peng-yongsheng + */ +public class FlushAndSwitch { +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java similarity index 75% rename from apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java rename to apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java index 9d94ca4cbcc0..a909ee91bd02 100644 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/PersistenceWorker.java @@ -16,20 +16,38 @@ * */ -package org.skywalking.apm.collector.stream.worker.impl; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.impl; import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.skywalking.apm.collector.stream.worker.impl.data.DataCache; +import org.apache.skywalking.apm.collector.core.data.Data; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.apache.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; +import org.apache.skywalking.apm.collector.stream.worker.base.WorkerException; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.collector.stream.worker.impl.data.DataCache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCache.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCache.java new file mode 100644 index 000000000000..c20f15fdb41b --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCache.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.impl.data; + +import org.apache.skywalking.apm.collector.core.cache.Window; +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public class DataCache extends Window> { + + private DataCollection lockedDataCollection; + + @Override public DataCollection collectionInstance() { + return new DataCollection<>(); + } + + public boolean containsKey(String id) { + return lockedDataCollection.containsKey(id); + } + + public Data get(String id) { + return lockedDataCollection.get(id); + } + + public void put(String id, DATA_IMPL data) { + lockedDataCollection.put(id, data); + } + + public void writing() { + lockedDataCollection = getCurrentAndWriting(); + } + + public int currentCollectionSize() { + return getCurrent().size(); + } + + public void finishWriting() { + lockedDataCollection.finishWriting(); + lockedDataCollection = null; + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java new file mode 100644 index 000000000000..7a8b065a0831 --- /dev/null +++ b/apm-collector/apm-collector-stream/src/main/java/org/apache/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.stream.worker.impl.data; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.skywalking.apm.collector.core.cache.Collection; +import org.apache.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public class DataCollection implements Collection> { + private Map data; + private volatile boolean writing; + private volatile boolean reading; + + DataCollection() { + this.data = new ConcurrentHashMap<>(); + this.writing = false; + this.reading = false; + } + + public void finishWriting() { + writing = false; + } + + @Override public void writing() { + writing = true; + } + + @Override public boolean isWriting() { + return writing; + } + + @Override public void finishReading() { + reading = false; + } + + @Override public void reading() { + reading = true; + } + + @Override public boolean isReading() { + return reading; + } + + boolean containsKey(String key) { + return data.containsKey(key); + } + + void put(String key, DATA_IMPL value) { + data.put(key, value); + } + + public DATA_IMPL get(String key) { + return data.get(key); + } + + @Override public int size() { + return data.size(); + } + + @Override public void clear() { + data.clear(); + } + + public Map collection() { + return data; + } +} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/timer/PersistenceTimer.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/timer/PersistenceTimer.java deleted file mode 100644 index a186cc5b5e51..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/timer/PersistenceTimer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.timer; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.base.dao.IBatchDAO; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class PersistenceTimer { - - private final Logger logger = LoggerFactory.getLogger(PersistenceTimer.class); - - public void start(ModuleManager moduleManager, List persistenceWorkers) { - logger.info("persistence timer start"); - //TODO timer value config -// final long timeInterval = EsConfig.Es.Persistence.Timer.VALUE * 1000; - final long timeInterval = 3; - IBatchDAO batchDAO = moduleManager.find(StorageModule.NAME).getService(IBatchDAO.class); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> extractDataAndSave(batchDAO, persistenceWorkers), 1, timeInterval, TimeUnit.SECONDS); - } - - private void extractDataAndSave(IBatchDAO batchDAO, List persistenceWorkers) { - try { - List batchAllCollection = new ArrayList<>(); - persistenceWorkers.forEach((PersistenceWorker worker) -> { - logger.debug("extract {} worker data and save", worker.getClass().getName()); - try { - worker.flushAndSwitch(); - List batchCollection = worker.buildBatchCollection(); - logger.debug("extract {} worker data size: {}", worker.getClass().getName(), batchCollection.size()); - batchAllCollection.addAll(batchCollection); - } catch (WorkerException e) { - logger.error(e.getMessage(), e); - } - }); - - batchDAO.batchPersistence(batchAllCollection); - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } finally { - logger.debug("persistence data save finish"); - } - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java deleted file mode 100644 index 6f43832d7c8a..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorker.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.module.ModuleManager; - -/** - * The AbstractLocalAsyncWorker implementations represent workers, - * which receive local asynchronous message. - * - * @author peng-yongsheng - * @since v3.0-2017 - */ -public abstract class AbstractLocalAsyncWorker extends AbstractWorker { - - public AbstractLocalAsyncWorker(ModuleManager moduleManager) { - super(moduleManager); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java deleted file mode 100644 index 817f76b558aa..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractLocalAsyncWorkerProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.service.QueueCreatorService; - -/** - * @author peng-yongsheng - */ -public abstract class AbstractLocalAsyncWorkerProvider> extends AbstractWorkerProvider { - - public abstract int queueSize(); - - private final QueueCreatorService queueCreatorService; - - public AbstractLocalAsyncWorkerProvider(ModuleManager moduleManager, - QueueCreatorService queueCreatorService) { - super(moduleManager); - this.queueCreatorService = queueCreatorService; - } - - @Override - public final WorkerRef create(WorkerCreateListener workerCreateListener) { - WORKER_TYPE localAsyncWorker = workerInstance(getModuleManager()); - workerCreateListener.addWorker(localAsyncWorker); - - LocalAsyncWorkerRef localAsyncWorkerRef = new LocalAsyncWorkerRef<>(localAsyncWorker); - QueueEventHandler queueEventHandler = queueCreatorService.create(queueSize(), localAsyncWorkerRef); - localAsyncWorkerRef.setQueueEventHandler(queueEventHandler); - return localAsyncWorkerRef; - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java deleted file mode 100644 index f6e245ea078c..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorker.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.Selector; - -/** - * The AbstractRemoteWorker implementations represent workers, - * which receive remote messages. - *

- * Usually, the implementations are doing persistent, or aggregate works. - * - * @author peng-yongsheng - * @since v3.0-2017 - */ -public abstract class AbstractRemoteWorker extends AbstractWorker { - - public AbstractRemoteWorker(ModuleManager moduleManager) { - super(moduleManager); - } - - public abstract Selector selector(); -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java deleted file mode 100644 index 686828109c68..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractRemoteWorkerProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; - -/** - * The AbstractRemoteWorkerProvider implementations represent providers, - * which create instance of cluster workers whose implemented {@link AbstractRemoteWorker}. - *

- * - * @author peng-yongsheng - * @since v3.0-2017 - */ -public abstract class AbstractRemoteWorkerProvider> extends AbstractWorkerProvider { - - private final RemoteSenderService remoteSenderService; - private final int graphId; - - public AbstractRemoteWorkerProvider(ModuleManager moduleManager, RemoteSenderService remoteSenderService, - int graphId) { - super(moduleManager); - this.remoteSenderService = remoteSenderService; - this.graphId = graphId; - } - - /** - * Create the worker instance into akka system, the akka system will control the cluster worker life cycle. - * - * @return The created worker reference. See {@link RemoteWorkerRef} worker instance, when the worker provider not - * find then Throw this Exception. - */ - @Override final public RemoteWorkerRef create(WorkerCreateListener workerCreateListener) { - WORKER_TYPE remoteWorker = workerInstance(getModuleManager()); - workerCreateListener.addWorker(remoteWorker); - return new RemoteWorkerRef<>(remoteWorker, remoteSenderService, graphId); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorker.java deleted file mode 100644 index b1ac02974e28..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorker.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.graph.Next; -import org.skywalking.apm.collector.core.graph.NodeProcessor; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public abstract class AbstractWorker implements NodeProcessor { - - private final Logger logger = LoggerFactory.getLogger(AbstractWorker.class); - - private final ModuleManager moduleManager; - - public AbstractWorker(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - public final ModuleManager getModuleManager() { - return moduleManager; - } - - private Next next; - - /** - * The data process logic in this method. - * - * @param message Cast the message object to a expect subclass. - * @throws WorkerException Don't handle the exception, throw it. - */ - protected abstract void onWork(INPUT message) throws WorkerException; - - @Override public final void process(INPUT input, Next next) { - this.next = next; - try { - onWork(input); - } catch (WorkerException e) { - logger.error(e.getMessage(), e); - } - } - - protected final void onNext(OUTPUT message) { - next.execute(message); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java deleted file mode 100644 index a33f574f7799..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/AbstractWorkerProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.module.ModuleManager; - -/** - * @author peng-yongsheng - */ -public abstract class AbstractWorkerProvider> implements Provider { - - private final ModuleManager moduleManager; - - public AbstractWorkerProvider(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - } - - public final ModuleManager getModuleManager() { - return moduleManager; - } - - public abstract WORKER_TYPE workerInstance(ModuleManager moduleManager); -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java deleted file mode 100644 index 7c90eecf037d..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/LocalAsyncWorkerRef.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.CollectorException; -import org.skywalking.apm.collector.core.graph.NodeProcessor; -import org.skywalking.apm.collector.queue.base.QueueEventHandler; -import org.skywalking.apm.collector.queue.base.QueueExecutor; - -/** - * @author peng-yongsheng - */ -public class LocalAsyncWorkerRef extends WorkerRef implements QueueExecutor { - - private QueueEventHandler queueEventHandler; - - LocalAsyncWorkerRef(NodeProcessor destinationHandler) { - super(destinationHandler); - } - - public void setQueueEventHandler(QueueEventHandler queueEventHandler) { - this.queueEventHandler = queueEventHandler; - } - - @Override public void execute(INPUT input) throws CollectorException { - out(input); - } - - @Override protected void in(INPUT input) { - queueEventHandler.tell(input); - } - - @Override protected void out(INPUT input) { - super.out(input); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/Provider.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/Provider.java deleted file mode 100644 index 59c761b3a3dd..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/Provider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -/** - * @author peng-yongsheng - */ -public interface Provider { - - WorkerRef create(WorkerCreateListener workerCreateListener) throws ProviderNotFoundException; -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java deleted file mode 100644 index 146077cf1a9f..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/ProviderNotFoundException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -public class ProviderNotFoundException extends Exception { - public ProviderNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java deleted file mode 100644 index f39bc7488474..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/RemoteWorkerRef.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.remote.service.RemoteSenderService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class RemoteWorkerRef extends WorkerRef { - - private final Logger logger = LoggerFactory.getLogger(RemoteWorkerRef.class); - - private final AbstractRemoteWorker remoteWorker; - private final RemoteSenderService remoteSenderService; - private final int graphId; - - RemoteWorkerRef(AbstractRemoteWorker remoteWorker, RemoteSenderService remoteSenderService, - int graphId) { - super(remoteWorker); - this.remoteWorker = remoteWorker; - this.remoteSenderService = remoteSenderService; - this.graphId = graphId; - } - - @Override protected void in(INPUT message) { - try { - RemoteSenderService.Mode mode = remoteSenderService.send(this.graphId, this.remoteWorker.id(), message, this.remoteWorker.selector()); - if (mode.equals(RemoteSenderService.Mode.Local)) { - out(message); - } - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - } - - @Override protected void out(INPUT input) { - super.out(input); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java deleted file mode 100644 index 3efbbda4453a..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/UsedRoleNameException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -public class UsedRoleNameException extends Exception { - public UsedRoleNameException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java deleted file mode 100644 index 7da890c396f8..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerCreateListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker; - -/** - * @author peng-yongsheng - */ -public class WorkerCreateListener { - - private final List persistenceWorkers; - - public WorkerCreateListener() { - this.persistenceWorkers = new ArrayList<>(); - } - - public void addWorker(AbstractWorker worker) { - if (worker instanceof PersistenceWorker) { - persistenceWorkers.add((PersistenceWorker)worker); - } - } - - public List getPersistenceWorkers() { - return persistenceWorkers; - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerException.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerException.java deleted file mode 100644 index 491f61565ac1..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerException.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.CollectorException; - -/** - * Defines a general exception a worker can throw when it - * encounters difficulty. - * - * @author peng-yongsheng - * @since v3.1-2017 - */ -public class WorkerException extends CollectorException { - - public WorkerException(String message) { - super(message); - } - - public WorkerException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java deleted file mode 100644 index 527b98b584d2..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerInvokeException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -/** - * This exception is raised when worker fails to process job during "call" or "ask" - * - * @author peng-yongsheng - * @since v3.1-2017 - */ -public class WorkerInvokeException extends WorkerException { - - public WorkerInvokeException(String message) { - super(message); - } - - public WorkerInvokeException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java deleted file mode 100644 index 11adb2df01ab..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerNotFoundException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -public class WorkerNotFoundException extends WorkerException { - public WorkerNotFoundException(String message) { - super(message); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerRef.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerRef.java deleted file mode 100644 index a86eac5f4374..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/base/WorkerRef.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.base; - -import org.skywalking.apm.collector.core.graph.NodeProcessor; -import org.skywalking.apm.collector.core.graph.WayToNode; - -/** - * @author peng-yongsheng - */ -public abstract class WorkerRef extends WayToNode { - WorkerRef(NodeProcessor destinationHandler) { - super(destinationHandler); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java deleted file mode 100644 index cae8133fa040..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/AggregationWorker.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.impl; - -import org.skywalking.apm.collector.core.data.Data; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.stream.worker.base.AbstractLocalAsyncWorker; -import org.skywalking.apm.collector.stream.worker.base.WorkerException; -import org.skywalking.apm.collector.stream.worker.impl.data.DataCache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public abstract class AggregationWorker extends AbstractLocalAsyncWorker { - - private final Logger logger = LoggerFactory.getLogger(AggregationWorker.class); - - private DataCache dataCache; - private int messageNum; - - public AggregationWorker(ModuleManager moduleManager) { - super(moduleManager); - this.dataCache = new DataCache<>(); - } - - @SuppressWarnings("unchecked") - protected OUTPUT transform(INPUT message) { - return (OUTPUT)message; - } - - @Override protected final void onWork(INPUT message) throws WorkerException { - OUTPUT output = transform(message); - messageNum++; - aggregate(output); - - if (messageNum >= 100) { - sendToNext(); - messageNum = 0; - } - if (output.isEndOfBatch()) { - sendToNext(); - } - } - - private void sendToNext() throws WorkerException { - dataCache.switchPointer(); - while (dataCache.getLast().isWriting()) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - throw new WorkerException(e.getMessage(), e); - } - } - dataCache.getLast().collection().forEach((String id, OUTPUT data) -> { - logger.debug(data.toString()); - onNext(data); - }); - dataCache.finishReadingLast(); - } - - private void aggregate(OUTPUT message) { - dataCache.writing(); - if (dataCache.containsKey(message.getId())) { - dataCache.get(message.getId()).mergeData(message); - } else { - dataCache.put(message.getId(), message); - } - dataCache.finishWriting(); - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java deleted file mode 100644 index 78944afc9676..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/FlushAndSwitch.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.impl; - -/** - * @author peng-yongsheng - */ -public class FlushAndSwitch { -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCache.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCache.java deleted file mode 100644 index 3900f08393a2..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCache.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.impl.data; - -import org.skywalking.apm.collector.core.cache.Window; -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public class DataCache extends Window> { - - private DataCollection lockedDataCollection; - - @Override public DataCollection collectionInstance() { - return new DataCollection<>(); - } - - public boolean containsKey(String id) { - return lockedDataCollection.containsKey(id); - } - - public Data get(String id) { - return lockedDataCollection.get(id); - } - - public void put(String id, DATA_IMPL data) { - lockedDataCollection.put(id, data); - } - - public void writing() { - lockedDataCollection = getCurrentAndWriting(); - } - - public int currentCollectionSize() { - return getCurrent().size(); - } - - public void finishWriting() { - lockedDataCollection.finishWriting(); - lockedDataCollection = null; - } -} diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java deleted file mode 100644 index 973592660894..000000000000 --- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/worker/impl/data/DataCollection.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.stream.worker.impl.data; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import org.skywalking.apm.collector.core.cache.Collection; -import org.skywalking.apm.collector.core.data.Data; - -/** - * @author peng-yongsheng - */ -public class DataCollection implements Collection> { - private Map data; - private volatile boolean writing; - private volatile boolean reading; - - DataCollection() { - this.data = new ConcurrentHashMap<>(); - this.writing = false; - this.reading = false; - } - - public void finishWriting() { - writing = false; - } - - @Override public void writing() { - writing = true; - } - - @Override public boolean isWriting() { - return writing; - } - - @Override public void finishReading() { - reading = false; - } - - @Override public void reading() { - reading = true; - } - - @Override public boolean isReading() { - return reading; - } - - boolean containsKey(String key) { - return data.containsKey(key); - } - - void put(String key, DATA_IMPL value) { - data.put(key, value); - } - - public DATA_IMPL get(String key) { - return data.get(key); - } - - @Override public int size() { - return data.size(); - } - - @Override public void clear() { - data.clear(); - } - - public Map collection() { - return data; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/apache/skywalking/apm/collector/ui/UIModule.java b/apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/apache/skywalking/apm/collector/ui/UIModule.java new file mode 100644 index 000000000000..83dd279e8097 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/apache/skywalking/apm/collector/ui/UIModule.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui; + +import org.apache.skywalking.apm.collector.core.module.Module; + +/** + * @author peng-yongsheng + */ +public class UIModule extends Module { + + public static final String NAME = "ui"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[0]; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/skywalking/apm/collector/ui/UIModule.java b/apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/skywalking/apm/collector/ui/UIModule.java deleted file mode 100644 index 4e4d1e0fdc8a..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-define/src/main/java/org/skywalking/apm/collector/ui/UIModule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui; - -import org.skywalking.apm.collector.core.module.Module; - -/** - * @author peng-yongsheng - */ -public class UIModule extends Module { - - public static final String NAME = "ui"; - - @Override public String name() { - return NAME; - } - - @Override public Class[] services() { - return new Class[0]; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module new file mode 100644 index 000000000000..08d6f9add074 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.ui.UIModule diff --git a/apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module deleted file mode 100644 index 99c8f7d07c70..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.ui.UIModule diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java new file mode 100644 index 000000000000..f41dd61cf8cc --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty; + +import java.util.Properties; +import org.apache.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cluster.ClusterModule; +import org.apache.skywalking.apm.collector.cluster.service.ModuleListenerService; +import org.apache.skywalking.apm.collector.cluster.service.ModuleRegisterService; +import org.apache.skywalking.apm.collector.core.module.Module; +import org.apache.skywalking.apm.collector.core.module.ModuleProvider; +import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedException; +import org.apache.skywalking.apm.collector.jetty.manager.JettyManagerModule; +import org.apache.skywalking.apm.collector.jetty.manager.service.JettyManagerService; +import org.apache.skywalking.apm.collector.naming.NamingModule; +import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; +import org.apache.skywalking.apm.collector.server.Server; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.ui.UIModule; +import org.apache.skywalking.apm.collector.ui.jetty.handler.SegmentTopGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.SpanGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.TraceDagGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.TraceStackGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.application.ApplicationsGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.instancehealth.InstanceHealthGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetOneTimeBucketHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetRangeTimeBucketHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingListener; +import org.apache.skywalking.apm.collector.ui.jetty.handler.servicetree.EntryServiceGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByIdHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler; + +/** + * @author peng-yongsheng + */ +public class UIModuleJettyProvider extends ModuleProvider { + + public static final String NAME = "jetty"; + private static final String HOST = "host"; + private static final String PORT = "port"; + private static final String CONTEXT_PATH = "context_path"; + + @Override public String name() { + return NAME; + } + + @Override public Class module() { + return UIModule.class; + } + + @Override public void prepare(Properties config) throws ServiceNotProvidedException { + } + + @Override public void start(Properties config) throws ServiceNotProvidedException { + String host = config.getProperty(HOST); + Integer port = (Integer)config.get(PORT); + String contextPath = config.getProperty(CONTEXT_PATH); + + ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); + moduleRegisterService.register(UIModule.NAME, this.name(), new UIModuleJettyRegistration(host, port, contextPath)); + + UIJettyNamingListener namingListener = new UIJettyNamingListener(); + ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); + moduleListenerService.addListener(namingListener); + + NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class); + namingHandlerRegisterService.register(new UIJettyNamingHandler(namingListener)); + + JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class); + Server jettyServer = managerService.createIfAbsent(host, port, contextPath); + addHandlers(jettyServer); + } + + @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { + + } + + @Override public String[] requiredModules() { + return new String[] {ClusterModule.NAME, JettyManagerModule.NAME, NamingModule.NAME, CacheModule.NAME, StorageModule.NAME}; + } + + private void addHandlers(Server jettyServer) { + jettyServer.addHandler(new ApplicationsGetHandler(getManager())); + jettyServer.addHandler(new InstanceHealthGetHandler(getManager())); + jettyServer.addHandler(new InstanceMetricGetOneTimeBucketHandler(getManager())); + jettyServer.addHandler(new InstanceMetricGetRangeTimeBucketHandler(getManager())); + jettyServer.addHandler(new InstanceOsInfoGetHandler(getManager())); + jettyServer.addHandler(new EntryServiceGetHandler(getManager())); + jettyServer.addHandler(new ServiceTreeGetByIdHandler(getManager())); + jettyServer.addHandler(new AllInstanceLastTimeGetHandler(getManager())); + jettyServer.addHandler(new OneInstanceLastTimeGetHandler(getManager())); + jettyServer.addHandler(new SegmentTopGetHandler(getManager())); + jettyServer.addHandler(new SpanGetHandler(getManager())); + jettyServer.addHandler(new TraceDagGetHandler(getManager())); + jettyServer.addHandler(new TraceStackGetHandler(getManager())); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java new file mode 100644 index 000000000000..833c0ec4eb10 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty; + +import org.apache.skywalking.apm.collector.cluster.ModuleRegistration; + +/** + * @author peng-yongsheng + */ +public class UIModuleJettyRegistration extends ModuleRegistration { + + private final String host; + private final int port; + private final String contextPath; + + public UIModuleJettyRegistration(String host, int port, String contextPath) { + this.host = host; + this.port = port; + this.contextPath = contextPath; + } + + @Override public Value buildValue() { + return new Value(host, port, contextPath); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java similarity index 79% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java index 80d5370a9eff..4b646ce64cef 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java @@ -16,16 +16,34 @@ * */ -package org.skywalking.apm.collector.ui.jetty.handler; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler; import com.google.gson.JsonElement; import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.ui.service.SegmentTopService; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.SegmentTopService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java new file mode 100644 index 000000000000..dbadab120db9 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler; + +import com.google.gson.JsonElement; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.SpanService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SpanGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(SpanGetHandler.class); + + @Override public String pathSpec() { + return "/span/spanId"; + } + + private final SpanService service; + + public SpanGetHandler(ModuleManager moduleManager) { + this.service = new SpanService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String segmentId = req.getParameter("segmentId"); + String spanIdStr = req.getParameter("spanId"); + logger.debug("segmentSpanId: {}, spanIdStr: {}", segmentId, spanIdStr); + + int spanId; + try { + spanId = Integer.parseInt(spanIdStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("span id must be integer"); + } + + return service.load(segmentId, spanId); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java new file mode 100644 index 000000000000..8cfed47663e9 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler; + +import com.google.gson.JsonElement; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.TraceDagService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TraceDagGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(TraceDagGetHandler.class); + + @Override public String pathSpec() { + return "/traceDag"; + } + + private final TraceDagService service; + + public TraceDagGetHandler(ModuleManager moduleManager) { + this.service = new TraceDagService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { + throw new ArgumentsParseException("the request parameter must contains startTime, endTime"); + } + + String startTimeStr = req.getParameter("startTime"); + String endTimeStr = req.getParameter("endTime"); + logger.debug("startTime: {}, endTimeStr: {}", startTimeStr, endTimeStr); + + long startTime; + try { + startTime = Long.valueOf(req.getParameter("startTime")); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("the request parameter startTime must be a long"); + } + + long endTime; + try { + endTime = Long.valueOf(req.getParameter("endTime")); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("the request parameter endTime must be a long"); + } + + return service.load(startTime, endTime); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java new file mode 100644 index 000000000000..937d5f1ce5ef --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler; + +import com.google.gson.JsonElement; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.TraceStackService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TraceStackGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(TraceStackGetHandler.class); + + @Override public String pathSpec() { + return "/traceStack/globalTraceId"; + } + + private final TraceStackService service; + + public TraceStackGetHandler(ModuleManager moduleManager) { + this.service = new TraceStackService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String globalTraceId = req.getParameter("globalTraceId"); + logger.debug("globalTraceId: {}", globalTraceId); + + return service.load(globalTraceId); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java new file mode 100644 index 000000000000..89bb4804f07e --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.application; + +import com.google.gson.JsonElement; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.ui.service.ApplicationService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationsGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(ApplicationsGetHandler.class); + + @Override public String pathSpec() { + return "/applications"; + } + + private final ApplicationService applicationService; + + public ApplicationsGetHandler(ModuleManager moduleManager) { + this.applicationService = new ApplicationService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { + throw new ArgumentsParseException("must contains startTime. endTime parameter"); + } + + String startTimeStr = req.getParameter("startTime"); + String endTimeStr = req.getParameter("endTime"); + logger.debug("applications get start time: {}, end time: {}", startTimeStr, endTimeStr); + + long startTime; + try { + startTime = Long.parseLong(startTimeStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("start time must be long"); + } + + long endTime; + try { + endTime = Long.parseLong(endTimeStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("end time must be long"); + } + + return applicationService.getApplications(startTime, endTime); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java new file mode 100644 index 000000000000..58cdf029c7bd --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.instancehealth; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.InstanceHealthService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceHealthGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(InstanceHealthGetHandler.class); + + @Override public String pathSpec() { + return "/instance/health/applicationId"; + } + + private final InstanceHealthService service; + + public InstanceHealthGetHandler(ModuleManager moduleManager) { + this.service = new InstanceHealthService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String timeBucketStr = req.getParameter("timeBucket"); + String[] applicationIdsStr = req.getParameterValues("applicationIds"); + logger.debug("instance health get timeBucket: {}, applicationIdsStr: {}", timeBucketStr, applicationIdsStr); + + long timeBucket; + try { + timeBucket = Long.parseLong(timeBucketStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("timestamp must be long"); + } + + int[] applicationIds = new int[applicationIdsStr.length]; + for (int i = 0; i < applicationIdsStr.length; i++) { + try { + applicationIds[i] = Integer.parseInt(applicationIdsStr[i]); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("application id must be integer"); + } + } + + JsonObject response = new JsonObject(); + response.addProperty("timeBucket", timeBucket); + JsonArray appInstances = new JsonArray(); + response.add("appInstances", appInstances); + + for (int applicationId : applicationIds) { + appInstances.add(service.getInstances(timeBucket, applicationId)); + } + return response; + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java new file mode 100644 index 000000000000..ba10c4f9c5f2 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric; + +import com.google.gson.JsonElement; +import java.util.LinkedHashSet; +import java.util.Set; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.InstanceJVMService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricGetOneTimeBucketHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetOneTimeBucketHandler.class); + + @Override public String pathSpec() { + return "/instance/jvm/instanceId/oneBucket"; + } + + private final InstanceJVMService service; + + public InstanceMetricGetOneTimeBucketHandler(ModuleManager moduleManager) { + this.service = new InstanceJVMService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String timeBucketStr = req.getParameter("timeBucket"); + String instanceIdStr = req.getParameter("instanceId"); + String[] metricTypes = req.getParameterValues("metricTypes"); + + logger.debug("instance jvm metric get timeBucket: {}, instance id: {}, metric types: {}", timeBucketStr, instanceIdStr, metricTypes); + + long timeBucket; + try { + timeBucket = Long.parseLong(timeBucketStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("timeBucket must be long"); + } + + int instanceId; + try { + instanceId = Integer.parseInt(instanceIdStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("instance id must be integer"); + } + + if (metricTypes.length == 0) { + throw new ArgumentsParseException("at least one metric type"); + } + + Set metricTypeSet = new LinkedHashSet<>(); + for (String metricType : metricTypes) { + metricTypeSet.add(metricType); + } + + return service.getInstanceJvmMetric(instanceId, metricTypeSet, timeBucket); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java new file mode 100644 index 000000000000..ed430c5a785c --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric; + +import com.google.gson.JsonElement; +import java.util.LinkedHashSet; +import java.util.Set; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.InstanceJVMService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricGetRangeTimeBucketHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetRangeTimeBucketHandler.class); + + @Override public String pathSpec() { + return "/instance/jvm/instanceId/rangeBucket"; + } + + private final InstanceJVMService service; + + public InstanceMetricGetRangeTimeBucketHandler(ModuleManager moduleManager) { + this.service = new InstanceJVMService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String startTimeBucketStr = req.getParameter("startTimeBucket"); + String endTimeBucketStr = req.getParameter("endTimeBucket"); + String instanceIdStr = req.getParameter("instanceId"); + String[] metricTypes = req.getParameterValues("metricTypes"); + + logger.debug("instance jvm metric get start timeBucket: {}, end timeBucket:{} , instance id: {}, metric types: {}", startTimeBucketStr, endTimeBucketStr, instanceIdStr, metricTypes); + + long startTimeBucket; + try { + startTimeBucket = Long.parseLong(startTimeBucketStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("start timeBucket must be long"); + } + + long endTimeBucket; + try { + endTimeBucket = Long.parseLong(endTimeBucketStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("end timeBucket must be long"); + } + + int instanceId; + try { + instanceId = Integer.parseInt(instanceIdStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("instance id must be integer"); + } + + if (metricTypes.length == 0) { + throw new ArgumentsParseException("at least one metric type"); + } + + Set metricTypeSet = new LinkedHashSet<>(); + for (String metricType : metricTypes) { + metricTypeSet.add(metricType); + } + + return service.getInstanceJvmMetrics(instanceId, metricTypeSet, startTimeBucket, endTimeBucket); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java new file mode 100644 index 000000000000..712eb23294a5 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric; + +import com.google.gson.JsonElement; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.InstanceJVMService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceOsInfoGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(InstanceOsInfoGetHandler.class); + + @Override public String pathSpec() { + return "/instance/os/instanceId"; + } + + private final InstanceJVMService service; + + public InstanceOsInfoGetHandler(ModuleManager moduleManager) { + this.service = new InstanceJVMService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String instanceIdStr = req.getParameter("instanceId"); + logger.debug("instance os info get, instance id: {}", instanceIdStr); + + int instanceId; + try { + instanceId = Integer.parseInt(instanceIdStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("instance id must be integer"); + } + + return service.getInstanceOsInfo(instanceId); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java new file mode 100644 index 000000000000..e6403781500c --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.naming; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import java.util.Set; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; + +/** + * @author peng-yongsheng + */ +public class UIJettyNamingHandler extends JettyHandler { + + private final UIJettyNamingListener namingListener; + + public UIJettyNamingHandler(UIJettyNamingListener namingListener) { + this.namingListener = namingListener; + } + + @Override public String pathSpec() { + return "/ui/jetty"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + Set servers = namingListener.getAddresses(); + JsonArray serverArray = new JsonArray(); + servers.forEach(serverArray::add); + return serverArray; + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java new file mode 100644 index 000000000000..325ce80779af --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.naming; + +import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; +import org.apache.skywalking.apm.collector.ui.jetty.UIModuleJettyProvider; +import org.apache.skywalking.apm.collector.ui.UIModule; + +/** + * @author peng-yongsheng + */ +public class UIJettyNamingListener extends ClusterModuleListener { + + public static final String PATH = "/" + UIModule.NAME + "/" + UIModuleJettyProvider.NAME; + + @Override public String path() { + return PATH; + } + + @Override public void serverJoinNotify(String serverAddress) { + + } + + @Override public void serverQuitNotify(String serverAddress) { + + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java similarity index 76% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java index 3cb9bc7e0ca0..50e9dd189866 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/EntryServiceGetHandler.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.collector.ui.jetty.handler.servicetree; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.servicetree; import com.google.gson.JsonElement; import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.ServiceTreeService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.ServiceTreeService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java new file mode 100644 index 000000000000..11afa2db1853 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.servicetree; + +import com.google.gson.JsonElement; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.ui.service.ServiceTreeService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceTreeGetByIdHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByIdHandler.class); + + @Override public String pathSpec() { + return "/service/tree/entryServiceId"; + } + + private final ServiceTreeService service; + + public ServiceTreeGetByIdHandler(ModuleManager moduleManager) { + this.service = new ServiceTreeService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + if (!req.getParameterMap().containsKey("entryServiceId") || !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { + throw new ArgumentsParseException("must contains parameters: entryServiceId, startTime, endTime"); + } + + String entryServiceIdStr = req.getParameter("entryServiceId"); + String startTimeStr = req.getParameter("startTime"); + String endTimeStr = req.getParameter("endTime"); + logger.debug("service entry get entryServiceId: {}, startTime: {}, endTime: {}", entryServiceIdStr, startTimeStr, endTimeStr); + + int entryServiceId; + try { + entryServiceId = Integer.parseInt(entryServiceIdStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("entry service id must be integer"); + } + + long startTime; + try { + startTime = Long.parseLong(startTimeStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("start time must be long"); + } + + long endTime; + try { + endTime = Long.parseLong(endTimeStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("end time must be long"); + } + + return service.loadServiceTree(entryServiceId, startTime, endTime); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java new file mode 100644 index 000000000000..908ffd9141a9 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.time; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.util.Calendar; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.TimeSynchronousService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class AllInstanceLastTimeGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(AllInstanceLastTimeGetHandler.class); + + @Override public String pathSpec() { + return "/time/allInstance"; + } + + private final TimeSynchronousService service; + + public AllInstanceLastTimeGetHandler(ModuleManager moduleManager) { + this.service = new TimeSynchronousService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + Long timeBucket = service.allInstanceLastTime(); + logger.debug("all instance last time: {}", timeBucket); + + if (timeBucket == 0) { + timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()); + } + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket)); + calendar.add(Calendar.SECOND, -5); + timeBucket = calendar.getTimeInMillis(); + + JsonObject timeJson = new JsonObject(); + timeJson.addProperty("timeBucket", TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeBucket)); + return timeJson; + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java new file mode 100644 index 000000000000..4a789a3a11fe --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.jetty.handler.time; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.ui.service.TimeSynchronousService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class OneInstanceLastTimeGetHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(OneInstanceLastTimeGetHandler.class); + + @Override public String pathSpec() { + return "/time/oneInstance"; + } + + private final TimeSynchronousService service; + + public OneInstanceLastTimeGetHandler(ModuleManager moduleManager) { + this.service = new TimeSynchronousService(moduleManager); + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + String instanceIdStr = req.getParameter("instanceId"); + logger.debug("instanceId: {}", instanceIdStr); + + int instanceId; + try { + instanceId = Integer.parseInt(instanceIdStr); + } catch (NumberFormatException e) { + throw new ArgumentsParseException("application instance id must be integer"); + } + + Long time = service.instanceLastTime(instanceId); + logger.debug("application instance id: {}, instance last time: {}", instanceId, time); + JsonObject timeJson = new JsonObject(); + timeJson.addProperty("timeBucket", time); + return timeJson; + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { + throw new UnsupportedOperationException(); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java new file mode 100644 index 000000000000..e987cacebc5f --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; + +/** + * @author peng-yongsheng + */ +public class ApplicationService { + + private final IInstanceUIDAO instanceDAO; + private final ApplicationCacheService applicationCacheService; + + public ApplicationService(ModuleManager moduleManager) { + this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); + this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + + public JsonArray getApplications(long startTime, long endTime) { + JsonArray applications = instanceDAO.getApplications(startTime, endTime); + + applications.forEach(jsonElement -> { + JsonObject application = jsonElement.getAsJsonObject(); + int applicationId = application.get("applicationId").getAsInt(); + String applicationCode = applicationCacheService.get(applicationId); + application.addProperty("applicationCode", applicationCode); + }); + return applications; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java similarity index 75% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java index 3405ed5b8927..c02145cd6b58 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java @@ -16,20 +16,38 @@ * */ -package org.skywalking.apm.collector.ui.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/InstanceJVMService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java similarity index 82% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/InstanceJVMService.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java index 374633450aa7..16a5113b45fc 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/InstanceJVMService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java @@ -16,23 +16,41 @@ * */ -package org.skywalking.apm.collector.ui.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; import com.google.gson.Gson; import com.google.gson.JsonObject; import java.util.Set; -import org.skywalking.apm.collector.core.UnexpectedException; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.skywalking.apm.collector.storage.table.register.Instance; -import org.skywalking.apm.network.proto.PoolType; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.network.proto.PoolType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java new file mode 100644 index 000000000000..f0ce4f0d4fee --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentTopService { + + private final Logger logger = LoggerFactory.getLogger(SegmentTopService.class); + + private final IGlobalTraceUIDAO globalTraceDAO; + private final ISegmentCostUIDAO segmentCostDAO; + + public SegmentTopService(ModuleManager moduleManager) { + this.globalTraceDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTraceUIDAO.class); + this.segmentCostDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentCostUIDAO.class); + } + + public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, + String globalTraceId, ISegmentCostUIDAO.Error error, int applicationId, int limit, int from, + ISegmentCostUIDAO.Sort sort) { + logger.debug("startTime: {}, endTime: {}, minCost: {}, maxCost: {}, operationName: {}, globalTraceId: {}, error: {}, applicationId: {}, limit: {}, from: {}", startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from); + + List segmentIds = new LinkedList<>(); + if (StringUtils.isNotEmpty(globalTraceId)) { + segmentIds = globalTraceDAO.getSegmentIds(globalTraceId); + } + + JsonObject loadTopJsonObj = segmentCostDAO.loadTop(startTime, endTime, minCost, maxCost, operationName, error, applicationId, segmentIds, limit, from, sort); + JsonArray loadTopJsonArray = loadTopJsonObj.get("data").getAsJsonArray(); + for (JsonElement loadTopElement : loadTopJsonArray) { + JsonObject jsonObject = loadTopElement.getAsJsonObject(); + String segmentId = jsonObject.get(SegmentCostTable.COLUMN_SEGMENT_ID).getAsString(); + List globalTraces = globalTraceDAO.getGlobalTraceId(segmentId); + if (CollectionUtils.isNotEmpty(globalTraces)) { + jsonObject.addProperty(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraces.get(0)); + } + } + return loadTopJsonObj; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTreeService.java similarity index 80% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTreeService.java index 8648ca27560b..2c4d91acf029 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTreeService.java @@ -16,25 +16,43 @@ * */ -package org.skywalking.apm.collector.ui.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.util.Iterator; import java.util.Map; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; -import org.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; -import org.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.dao.IServiceEntryUIDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java similarity index 75% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java index fda66c7e9b74..ec20f4f4babb 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java @@ -16,24 +16,42 @@ * */ -package org.skywalking.apm.collector.ui.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.network.proto.KeyWithStringValue; -import org.skywalking.apm.network.proto.LogMessage; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.network.proto.KeyWithStringValue; +import org.apache.skywalking.apm.network.proto.LogMessage; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java new file mode 100644 index 000000000000..36ac05fe34a0 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; + +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TimeSynchronousService { + + private final Logger logger = LoggerFactory.getLogger(TimeSynchronousService.class); + + private final IInstanceUIDAO instanceDAO; + + public TimeSynchronousService(ModuleManager moduleManager) { + this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); + } + + public Long allInstanceLastTime() { + return instanceDAO.lastHeartBeatTime(); + } + + public Long instanceLastTime(int applicationInstanceId) { + return instanceDAO.instanceLastHeartBeatTime(applicationInstanceId); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java similarity index 79% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java index f9e8bac11405..88f9e9e61588 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java @@ -16,22 +16,40 @@ * */ -package org.skywalking.apm.collector.ui.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; -import org.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; -import org.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; -import org.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java new file mode 100644 index 000000000000..31dbcef197bd --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class TraceDagService { + + private final Logger logger = LoggerFactory.getLogger(TraceDagService.class); + + private final IApplicationComponentUIDAO applicationComponentUIDAO; + private final IApplicationMappingUIDAO applicationMappingUIDAO; + private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO; + private final ModuleManager moduleManager; + + public TraceDagService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class); + this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class); + this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class); + } + + public JsonObject load(long startTime, long endTime) { + logger.debug("startTime: {}, endTime: {}", startTime, endTime); + JsonArray applicationComponentArray = applicationComponentUIDAO.load(startTime, endTime); + + JsonArray applicationMappingArray = applicationMappingUIDAO.load(startTime, endTime); + + JsonArray applicationReferenceMetricArray = applicationReferenceMetricUIDAO.load(startTime, endTime); + + TraceDagDataBuilder builder = new TraceDagDataBuilder(moduleManager); + JsonObject traceDag = builder.build(applicationComponentArray, applicationMappingArray, applicationReferenceMetricArray); + + return traceDag; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java similarity index 84% rename from apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java rename to apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java index 07e24e4dc332..bd00f442796a 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java @@ -16,25 +16,43 @@ * */ -package org.skywalking.apm.collector.ui.service; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.List; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.Const; -import org.skywalking.apm.collector.core.util.ObjectUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java deleted file mode 100644 index 003389433b41..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty; - -import java.util.Properties; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cluster.ClusterModule; -import org.skywalking.apm.collector.cluster.service.ModuleListenerService; -import org.skywalking.apm.collector.cluster.service.ModuleRegisterService; -import org.skywalking.apm.collector.core.module.Module; -import org.skywalking.apm.collector.core.module.ModuleProvider; -import org.skywalking.apm.collector.core.module.ServiceNotProvidedException; -import org.skywalking.apm.collector.jetty.manager.JettyManagerModule; -import org.skywalking.apm.collector.jetty.manager.service.JettyManagerService; -import org.skywalking.apm.collector.naming.NamingModule; -import org.skywalking.apm.collector.naming.service.NamingHandlerRegisterService; -import org.skywalking.apm.collector.server.Server; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.ui.UIModule; -import org.skywalking.apm.collector.ui.jetty.handler.SegmentTopGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.SpanGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.TraceDagGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.TraceStackGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.application.ApplicationsGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.instancehealth.InstanceHealthGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetOneTimeBucketHandler; -import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetRangeTimeBucketHandler; -import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingHandler; -import org.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingListener; -import org.skywalking.apm.collector.ui.jetty.handler.servicetree.EntryServiceGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByIdHandler; -import org.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler; -import org.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler; - -/** - * @author peng-yongsheng - */ -public class UIModuleJettyProvider extends ModuleProvider { - - public static final String NAME = "jetty"; - private static final String HOST = "host"; - private static final String PORT = "port"; - private static final String CONTEXT_PATH = "context_path"; - - @Override public String name() { - return NAME; - } - - @Override public Class module() { - return UIModule.class; - } - - @Override public void prepare(Properties config) throws ServiceNotProvidedException { - } - - @Override public void start(Properties config) throws ServiceNotProvidedException { - String host = config.getProperty(HOST); - Integer port = (Integer)config.get(PORT); - String contextPath = config.getProperty(CONTEXT_PATH); - - ModuleRegisterService moduleRegisterService = getManager().find(ClusterModule.NAME).getService(ModuleRegisterService.class); - moduleRegisterService.register(UIModule.NAME, this.name(), new UIModuleJettyRegistration(host, port, contextPath)); - - UIJettyNamingListener namingListener = new UIJettyNamingListener(); - ModuleListenerService moduleListenerService = getManager().find(ClusterModule.NAME).getService(ModuleListenerService.class); - moduleListenerService.addListener(namingListener); - - NamingHandlerRegisterService namingHandlerRegisterService = getManager().find(NamingModule.NAME).getService(NamingHandlerRegisterService.class); - namingHandlerRegisterService.register(new UIJettyNamingHandler(namingListener)); - - JettyManagerService managerService = getManager().find(JettyManagerModule.NAME).getService(JettyManagerService.class); - Server jettyServer = managerService.createIfAbsent(host, port, contextPath); - addHandlers(jettyServer); - } - - @Override public void notifyAfterCompleted() throws ServiceNotProvidedException { - - } - - @Override public String[] requiredModules() { - return new String[] {ClusterModule.NAME, JettyManagerModule.NAME, NamingModule.NAME, CacheModule.NAME, StorageModule.NAME}; - } - - private void addHandlers(Server jettyServer) { - jettyServer.addHandler(new ApplicationsGetHandler(getManager())); - jettyServer.addHandler(new InstanceHealthGetHandler(getManager())); - jettyServer.addHandler(new InstanceMetricGetOneTimeBucketHandler(getManager())); - jettyServer.addHandler(new InstanceMetricGetRangeTimeBucketHandler(getManager())); - jettyServer.addHandler(new InstanceOsInfoGetHandler(getManager())); - jettyServer.addHandler(new EntryServiceGetHandler(getManager())); - jettyServer.addHandler(new ServiceTreeGetByIdHandler(getManager())); - jettyServer.addHandler(new AllInstanceLastTimeGetHandler(getManager())); - jettyServer.addHandler(new OneInstanceLastTimeGetHandler(getManager())); - jettyServer.addHandler(new SegmentTopGetHandler(getManager())); - jettyServer.addHandler(new SpanGetHandler(getManager())); - jettyServer.addHandler(new TraceDagGetHandler(getManager())); - jettyServer.addHandler(new TraceStackGetHandler(getManager())); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java deleted file mode 100644 index ca9f2a5c354c..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/UIModuleJettyRegistration.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty; - -import org.skywalking.apm.collector.cluster.ModuleRegistration; - -/** - * @author peng-yongsheng - */ -public class UIModuleJettyRegistration extends ModuleRegistration { - - private final String host; - private final int port; - private final String contextPath; - - public UIModuleJettyRegistration(String host, int port, String contextPath) { - this.host = host; - this.port = port; - this.contextPath = contextPath; - } - - @Override public Value buildValue() { - return new Value(host, port, contextPath); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java deleted file mode 100644 index e636452ae3fd..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.SpanService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SpanGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(SpanGetHandler.class); - - @Override public String pathSpec() { - return "/span/spanId"; - } - - private final SpanService service; - - public SpanGetHandler(ModuleManager moduleManager) { - this.service = new SpanService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String segmentId = req.getParameter("segmentId"); - String spanIdStr = req.getParameter("spanId"); - logger.debug("segmentSpanId: {}, spanIdStr: {}", segmentId, spanIdStr); - - int spanId; - try { - spanId = Integer.parseInt(spanIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("span id must be integer"); - } - - return service.load(segmentId, spanId); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java deleted file mode 100644 index d718b1ba5a52..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.TraceDagService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceDagGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(TraceDagGetHandler.class); - - @Override public String pathSpec() { - return "/traceDag"; - } - - private final TraceDagService service; - - public TraceDagGetHandler(ModuleManager moduleManager) { - this.service = new TraceDagService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { - throw new ArgumentsParseException("the request parameter must contains startTime, endTime"); - } - - String startTimeStr = req.getParameter("startTime"); - String endTimeStr = req.getParameter("endTime"); - logger.debug("startTime: {}, endTimeStr: {}", startTimeStr, endTimeStr); - - long startTime; - try { - startTime = Long.valueOf(req.getParameter("startTime")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter startTime must be a long"); - } - - long endTime; - try { - endTime = Long.valueOf(req.getParameter("endTime")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter endTime must be a long"); - } - - return service.load(startTime, endTime); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java deleted file mode 100644 index ef0af4dd4e9f..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.TraceStackService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceStackGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(TraceStackGetHandler.class); - - @Override public String pathSpec() { - return "/traceStack/globalTraceId"; - } - - private final TraceStackService service; - - public TraceStackGetHandler(ModuleManager moduleManager) { - this.service = new TraceStackService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String globalTraceId = req.getParameter("globalTraceId"); - logger.debug("globalTraceId: {}", globalTraceId); - - return service.load(globalTraceId); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java deleted file mode 100644 index ca6776a2643c..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.application; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.ApplicationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationsGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(ApplicationsGetHandler.class); - - @Override public String pathSpec() { - return "/applications"; - } - - private final ApplicationService applicationService; - - public ApplicationsGetHandler(ModuleManager moduleManager) { - this.applicationService = new ApplicationService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { - throw new ArgumentsParseException("must contains startTime. endTime parameter"); - } - - String startTimeStr = req.getParameter("startTime"); - String endTimeStr = req.getParameter("endTime"); - logger.debug("applications get start time: {}, end time: {}", startTimeStr, endTimeStr); - - long startTime; - try { - startTime = Long.parseLong(startTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("start time must be long"); - } - - long endTime; - try { - endTime = Long.parseLong(endTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("end time must be long"); - } - - return applicationService.getApplications(startTime, endTime); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java deleted file mode 100644 index a6aabcdcbb22..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.instancehealth; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.InstanceHealthService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceHealthGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceHealthGetHandler.class); - - @Override public String pathSpec() { - return "/instance/health/applicationId"; - } - - private final InstanceHealthService service; - - public InstanceHealthGetHandler(ModuleManager moduleManager) { - this.service = new InstanceHealthService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String timeBucketStr = req.getParameter("timeBucket"); - String[] applicationIdsStr = req.getParameterValues("applicationIds"); - logger.debug("instance health get timeBucket: {}, applicationIdsStr: {}", timeBucketStr, applicationIdsStr); - - long timeBucket; - try { - timeBucket = Long.parseLong(timeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("timestamp must be long"); - } - - int[] applicationIds = new int[applicationIdsStr.length]; - for (int i = 0; i < applicationIdsStr.length; i++) { - try { - applicationIds[i] = Integer.parseInt(applicationIdsStr[i]); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("application id must be integer"); - } - } - - JsonObject response = new JsonObject(); - response.addProperty("timeBucket", timeBucket); - JsonArray appInstances = new JsonArray(); - response.add("appInstances", appInstances); - - for (int applicationId : applicationIds) { - appInstances.add(service.getInstances(timeBucket, applicationId)); - } - return response; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java deleted file mode 100644 index b7f18ad15f96..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.instancemetric; - -import com.google.gson.JsonElement; -import java.util.LinkedHashSet; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.InstanceJVMService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricGetOneTimeBucketHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetOneTimeBucketHandler.class); - - @Override public String pathSpec() { - return "/instance/jvm/instanceId/oneBucket"; - } - - private final InstanceJVMService service; - - public InstanceMetricGetOneTimeBucketHandler(ModuleManager moduleManager) { - this.service = new InstanceJVMService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String timeBucketStr = req.getParameter("timeBucket"); - String instanceIdStr = req.getParameter("instanceId"); - String[] metricTypes = req.getParameterValues("metricTypes"); - - logger.debug("instance jvm metric get timeBucket: {}, instance id: {}, metric types: {}", timeBucketStr, instanceIdStr, metricTypes); - - long timeBucket; - try { - timeBucket = Long.parseLong(timeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("timeBucket must be long"); - } - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("instance id must be integer"); - } - - if (metricTypes.length == 0) { - throw new ArgumentsParseException("at least one metric type"); - } - - Set metricTypeSet = new LinkedHashSet<>(); - for (String metricType : metricTypes) { - metricTypeSet.add(metricType); - } - - return service.getInstanceJvmMetric(instanceId, metricTypeSet, timeBucket); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java deleted file mode 100644 index 1f1c5c8957e4..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.instancemetric; - -import com.google.gson.JsonElement; -import java.util.LinkedHashSet; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.InstanceJVMService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricGetRangeTimeBucketHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetRangeTimeBucketHandler.class); - - @Override public String pathSpec() { - return "/instance/jvm/instanceId/rangeBucket"; - } - - private final InstanceJVMService service; - - public InstanceMetricGetRangeTimeBucketHandler(ModuleManager moduleManager) { - this.service = new InstanceJVMService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String startTimeBucketStr = req.getParameter("startTimeBucket"); - String endTimeBucketStr = req.getParameter("endTimeBucket"); - String instanceIdStr = req.getParameter("instanceId"); - String[] metricTypes = req.getParameterValues("metricTypes"); - - logger.debug("instance jvm metric get start timeBucket: {}, end timeBucket:{} , instance id: {}, metric types: {}", startTimeBucketStr, endTimeBucketStr, instanceIdStr, metricTypes); - - long startTimeBucket; - try { - startTimeBucket = Long.parseLong(startTimeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("start timeBucket must be long"); - } - - long endTimeBucket; - try { - endTimeBucket = Long.parseLong(endTimeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("end timeBucket must be long"); - } - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("instance id must be integer"); - } - - if (metricTypes.length == 0) { - throw new ArgumentsParseException("at least one metric type"); - } - - Set metricTypeSet = new LinkedHashSet<>(); - for (String metricType : metricTypes) { - metricTypeSet.add(metricType); - } - - return service.getInstanceJvmMetrics(instanceId, metricTypeSet, startTimeBucket, endTimeBucket); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java deleted file mode 100644 index 41651b78a7a3..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.instancemetric; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.InstanceJVMService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceOsInfoGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceOsInfoGetHandler.class); - - @Override public String pathSpec() { - return "/instance/os/instanceId"; - } - - private final InstanceJVMService service; - - public InstanceOsInfoGetHandler(ModuleManager moduleManager) { - this.service = new InstanceJVMService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String instanceIdStr = req.getParameter("instanceId"); - logger.debug("instance os info get, instance id: {}", instanceIdStr); - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("instance id must be integer"); - } - - return service.getInstanceOsInfo(instanceId); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java deleted file mode 100644 index 5ded3e3622db..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.naming; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; - -/** - * @author peng-yongsheng - */ -public class UIJettyNamingHandler extends JettyHandler { - - private final UIJettyNamingListener namingListener; - - public UIJettyNamingHandler(UIJettyNamingListener namingListener) { - this.namingListener = namingListener; - } - - @Override public String pathSpec() { - return "/ui/jetty"; - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - Set servers = namingListener.getAddresses(); - JsonArray serverArray = new JsonArray(); - servers.forEach(serverArray::add); - return serverArray; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java deleted file mode 100644 index 16f753dfa50b..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/naming/UIJettyNamingListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.naming; - -import org.skywalking.apm.collector.cluster.ClusterModuleListener; -import org.skywalking.apm.collector.ui.UIModule; -import org.skywalking.apm.collector.ui.jetty.UIModuleJettyProvider; - -/** - * @author peng-yongsheng - */ -public class UIJettyNamingListener extends ClusterModuleListener { - - public static final String PATH = "/" + UIModule.NAME + "/" + UIModuleJettyProvider.NAME; - - @Override public String path() { - return PATH; - } - - @Override public void serverJoinNotify(String serverAddress) { - - } - - @Override public void serverQuitNotify(String serverAddress) { - - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java deleted file mode 100644 index 2f00efb39a12..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.servicetree; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.ServiceTreeService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceTreeGetByIdHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByIdHandler.class); - - @Override public String pathSpec() { - return "/service/tree/entryServiceId"; - } - - private final ServiceTreeService service; - - public ServiceTreeGetByIdHandler(ModuleManager moduleManager) { - this.service = new ServiceTreeService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("entryServiceId") || !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { - throw new ArgumentsParseException("must contains parameters: entryServiceId, startTime, endTime"); - } - - String entryServiceIdStr = req.getParameter("entryServiceId"); - String startTimeStr = req.getParameter("startTime"); - String endTimeStr = req.getParameter("endTime"); - logger.debug("service entry get entryServiceId: {}, startTime: {}, endTime: {}", entryServiceIdStr, startTimeStr, endTimeStr); - - int entryServiceId; - try { - entryServiceId = Integer.parseInt(entryServiceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("entry service id must be integer"); - } - - long startTime; - try { - startTime = Long.parseLong(startTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("start time must be long"); - } - - long endTime; - try { - endTime = Long.parseLong(endTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("end time must be long"); - } - - return service.loadServiceTree(entryServiceId, startTime, endTime); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java deleted file mode 100644 index 86165cc0f0c2..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.time; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.util.Calendar; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.TimeSynchronousService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class AllInstanceLastTimeGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(AllInstanceLastTimeGetHandler.class); - - @Override public String pathSpec() { - return "/time/allInstance"; - } - - private final TimeSynchronousService service; - - public AllInstanceLastTimeGetHandler(ModuleManager moduleManager) { - this.service = new TimeSynchronousService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - Long timeBucket = service.allInstanceLastTime(); - logger.debug("all instance last time: {}", timeBucket); - - if (timeBucket == 0) { - timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket)); - calendar.add(Calendar.SECOND, -5); - timeBucket = calendar.getTimeInMillis(); - - JsonObject timeJson = new JsonObject(); - timeJson.addProperty("timeBucket", TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeBucket)); - return timeJson; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java deleted file mode 100644 index 708b0cf18838..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.jetty.handler.time; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import javax.servlet.http.HttpServletRequest; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.skywalking.apm.collector.server.jetty.JettyHandler; -import org.skywalking.apm.collector.ui.service.TimeSynchronousService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class OneInstanceLastTimeGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(OneInstanceLastTimeGetHandler.class); - - @Override public String pathSpec() { - return "/time/oneInstance"; - } - - private final TimeSynchronousService service; - - public OneInstanceLastTimeGetHandler(ModuleManager moduleManager) { - this.service = new TimeSynchronousService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String instanceIdStr = req.getParameter("instanceId"); - logger.debug("instanceId: {}", instanceIdStr); - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("application instance id must be integer"); - } - - Long time = service.instanceLastTime(instanceId); - logger.debug("application instance id: {}, instance last time: {}", instanceId, time); - JsonObject timeJson = new JsonObject(); - timeJson.addProperty("timeBucket", time); - return timeJson; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ApplicationService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ApplicationService.java deleted file mode 100644 index 60844c7c6073..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/ApplicationService.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.skywalking.apm.collector.cache.CacheModule; -import org.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; - -/** - * @author peng-yongsheng - */ -public class ApplicationService { - - private final IInstanceUIDAO instanceDAO; - private final ApplicationCacheService applicationCacheService; - - public ApplicationService(ModuleManager moduleManager) { - this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); - this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); - } - - public JsonArray getApplications(long startTime, long endTime) { - JsonArray applications = instanceDAO.getApplications(startTime, endTime); - - applications.forEach(jsonElement -> { - JsonObject application = jsonElement.getAsJsonObject(); - int applicationId = application.get("applicationId").getAsInt(); - String applicationCode = applicationCacheService.get(applicationId); - application.addProperty("applicationCode", applicationCode); - }); - return applications; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SegmentTopService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SegmentTopService.java deleted file mode 100644 index bc0f82241c67..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/SegmentTopService.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.core.util.CollectionUtils; -import org.skywalking.apm.collector.core.util.StringUtils; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; -import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentTopService { - - private final Logger logger = LoggerFactory.getLogger(SegmentTopService.class); - - private final IGlobalTraceUIDAO globalTraceDAO; - private final ISegmentCostUIDAO segmentCostDAO; - - public SegmentTopService(ModuleManager moduleManager) { - this.globalTraceDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTraceUIDAO.class); - this.segmentCostDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentCostUIDAO.class); - } - - public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, - String globalTraceId, ISegmentCostUIDAO.Error error, int applicationId, int limit, int from, - ISegmentCostUIDAO.Sort sort) { - logger.debug("startTime: {}, endTime: {}, minCost: {}, maxCost: {}, operationName: {}, globalTraceId: {}, error: {}, applicationId: {}, limit: {}, from: {}", startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from); - - List segmentIds = new LinkedList<>(); - if (StringUtils.isNotEmpty(globalTraceId)) { - segmentIds = globalTraceDAO.getSegmentIds(globalTraceId); - } - - JsonObject loadTopJsonObj = segmentCostDAO.loadTop(startTime, endTime, minCost, maxCost, operationName, error, applicationId, segmentIds, limit, from, sort); - JsonArray loadTopJsonArray = loadTopJsonObj.get("data").getAsJsonArray(); - for (JsonElement loadTopElement : loadTopJsonArray) { - JsonObject jsonObject = loadTopElement.getAsJsonObject(); - String segmentId = jsonObject.get(SegmentCostTable.COLUMN_SEGMENT_ID).getAsString(); - List globalTraces = globalTraceDAO.getGlobalTraceId(segmentId); - if (CollectionUtils.isNotEmpty(globalTraces)) { - jsonObject.addProperty(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraces.get(0)); - } - } - return loadTopJsonObj; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TimeSynchronousService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TimeSynchronousService.java deleted file mode 100644 index 8ea398e8e702..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TimeSynchronousService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.service; - -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TimeSynchronousService { - - private final Logger logger = LoggerFactory.getLogger(TimeSynchronousService.class); - - private final IInstanceUIDAO instanceDAO; - - public TimeSynchronousService(ModuleManager moduleManager) { - this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); - } - - public Long allInstanceLastTime() { - return instanceDAO.lastHeartBeatTime(); - } - - public Long instanceLastTime(int applicationInstanceId) { - return instanceDAO.instanceLastHeartBeatTime(applicationInstanceId); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagService.java deleted file mode 100644 index 4f2cb63fac37..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/skywalking/apm/collector/ui/service/TraceDagService.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.collector.ui.service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.skywalking.apm.collector.core.module.ModuleManager; -import org.skywalking.apm.collector.storage.StorageModule; -import org.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceDagService { - - private final Logger logger = LoggerFactory.getLogger(TraceDagService.class); - - private final IApplicationComponentUIDAO applicationComponentUIDAO; - private final IApplicationMappingUIDAO applicationMappingUIDAO; - private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO; - private final ModuleManager moduleManager; - - public TraceDagService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class); - this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class); - this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class); - } - - public JsonObject load(long startTime, long endTime) { - logger.debug("startTime: {}, endTime: {}", startTime, endTime); - JsonArray applicationComponentArray = applicationComponentUIDAO.load(startTime, endTime); - - JsonArray applicationMappingArray = applicationMappingUIDAO.load(startTime, endTime); - - JsonArray applicationReferenceMetricArray = applicationReferenceMetricUIDAO.load(startTime, endTime); - - TraceDagDataBuilder builder = new TraceDagDataBuilder(moduleManager); - JsonObject traceDag = builder.build(applicationComponentArray, applicationMappingArray, applicationReferenceMetricArray); - - return traceDag; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 000000000000..5500d075e5cd --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.ModuleProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +org.apache.skywalking.apm.collector.ui.jetty.UIModuleJettyProvider diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider deleted file mode 100644 index bfcc9867d332..000000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -org.skywalking.apm.collector.ui.jetty.UIModuleJettyProvider diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/DataCarrier.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/DataCarrier.java similarity index 75% rename from apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/DataCarrier.java rename to apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/DataCarrier.java index 9c3e60e21331..f9ba576dfa6a 100644 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/DataCarrier.java +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/DataCarrier.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.commons.datacarrier; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier; -import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; -import org.skywalking.apm.commons.datacarrier.buffer.Channels; -import org.skywalking.apm.commons.datacarrier.consumer.ConsumerPool; -import org.skywalking.apm.commons.datacarrier.consumer.IConsumer; -import org.skywalking.apm.commons.datacarrier.partition.IDataPartitioner; -import org.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner; +import org.apache.skywalking.apm.commons.datacarrier.buffer.Channels; +import org.apache.skywalking.apm.commons.datacarrier.partition.IDataPartitioner; +import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; +import org.apache.skywalking.apm.commons.datacarrier.consumer.ConsumerPool; +import org.apache.skywalking.apm.commons.datacarrier.consumer.IConsumer; +import org.apache.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner; /** * DataCarrier main class. diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Buffer.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Buffer.java new file mode 100644 index 000000000000..c9604a58864e --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Buffer.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.buffer; + +import java.util.LinkedList; +import org.apache.skywalking.apm.commons.datacarrier.common.AtomicRangeInteger; + +/** + * Created by wusheng on 2016/10/25. + */ +public class Buffer { + private final Object[] buffer; + private BufferStrategy strategy; + private AtomicRangeInteger index; + + Buffer(int bufferSize, BufferStrategy strategy) { + buffer = new Object[bufferSize]; + this.strategy = strategy; + index = new AtomicRangeInteger(0, bufferSize); + } + + void setStrategy(BufferStrategy strategy) { + this.strategy = strategy; + } + + boolean save(T data) { + int i = index.getAndIncrement(); + if (buffer[i] != null) { + switch (strategy) { + case BLOCKING: + while (buffer[i] != null) { + try { + Thread.sleep(1L); + } catch (InterruptedException e) { + } + } + break; + case IF_POSSIBLE: + return false; + case OVERRIDE: + default: + } + } + buffer[i] = data; + return true; + } + + public int getBufferSize() { + return buffer.length; + } + + public LinkedList obtain(int start, int end) { + LinkedList result = new LinkedList(); + for (int i = start; i < end; i++) { + if (buffer[i] != null) { + result.add((T)buffer[i]); + buffer[i] = null; + } + } + return result; + } + +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java new file mode 100644 index 000000000000..125eb7613f54 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.buffer; + +/** + * Created by wusheng on 2016/10/25. + */ +public enum BufferStrategy { + BLOCKING, + OVERRIDE, + IF_POSSIBLE +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Channels.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java similarity index 75% rename from apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Channels.java rename to apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java index e7015f63f47e..9dbfc408aeb1 100644 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Channels.java +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/buffer/Channels.java @@ -16,9 +16,27 @@ * */ -package org.skywalking.apm.commons.datacarrier.buffer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.buffer; -import org.skywalking.apm.commons.datacarrier.partition.IDataPartitioner; +import org.apache.skywalking.apm.commons.datacarrier.partition.IDataPartitioner; /** * Channels of Buffer diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java new file mode 100644 index 000000000000..7dc327e52730 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.common; + +import java.io.Serializable; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by wusheng on 2016/10/25. + */ +public class AtomicRangeInteger extends Number implements Serializable { + private static final long serialVersionUID = -4099792402691141643L; + private AtomicInteger value; + private int startValue; + private int endValue; + + public AtomicRangeInteger(int startValue, int maxValue) { + this.value = new AtomicInteger(startValue); + this.startValue = startValue; + this.endValue = maxValue - 1; + } + + public final int getAndIncrement() { + int current; + int next; + do { + current = this.value.get(); + next = current >= this.endValue ? this.startValue : current + 1; + } + while (!this.value.compareAndSet(current, next)); + + return current; + } + + public final int get() { + return this.value.get(); + } + + public int intValue() { + return this.value.intValue(); + } + + public long longValue() { + return this.value.longValue(); + } + + public float floatValue() { + return this.value.floatValue(); + } + + public double doubleValue() { + return this.value.doubleValue(); + } +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java new file mode 100644 index 000000000000..fb6b34861b5b --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; + +/** + * Created by wusheng on 2016/11/15. + */ +public class ConsumerCannotBeCreatedException extends RuntimeException { + ConsumerCannotBeCreatedException(Throwable t) { + super(t); + } +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java similarity index 84% rename from apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java rename to apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java index c26bd8296997..d436364a1788 100644 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.commons.datacarrier.consumer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; import java.util.ArrayList; import java.util.concurrent.locks.ReentrantLock; -import org.skywalking.apm.commons.datacarrier.buffer.Buffer; -import org.skywalking.apm.commons.datacarrier.buffer.Channels; +import org.apache.skywalking.apm.commons.datacarrier.buffer.Buffer; +import org.apache.skywalking.apm.commons.datacarrier.buffer.Channels; /** * Pool of consumers diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java similarity index 78% rename from apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java rename to apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java index a0b680dc2954..ec4ad3e1cb83 100644 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.commons.datacarrier.consumer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.commons.datacarrier.buffer.Buffer; +import org.apache.skywalking.apm.commons.datacarrier.buffer.Buffer; /** * Created by wusheng on 2016/10/25. diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/IConsumer.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/IConsumer.java new file mode 100644 index 000000000000..2ffb3a534d9d --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/consumer/IConsumer.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; + +import java.util.List; + +/** + * Created by wusheng on 2016/10/25. + */ +public interface IConsumer { + void init(); + + void consume(List data); + + void onError(List data, Throwable t); + + void onExit(); +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java new file mode 100644 index 000000000000..cd06b80ad36e --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.partition; + +import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; + +/** + * Created by wusheng on 2016/10/25. + */ +public interface IDataPartitioner { + int partition(int total, T data); + + /** + * @return an integer represents how many times should retry when {@link BufferStrategy#IF_POSSIBLE}. + * + * Less or equal 1, means not support retry. + */ + int maxRetryCount(); +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java new file mode 100644 index 000000000000..3f5d9d1143a9 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.partition; + +/** + * use threadid % total to partition + * + * Created by wusheng on 2016/10/25. + */ +public class ProducerThreadPartitioner implements IDataPartitioner { + private int retryTime = 3; + + public ProducerThreadPartitioner() { + } + + public ProducerThreadPartitioner(int retryTime) { + this.retryTime = retryTime; + } + + @Override + public int partition(int total, T data) { + return (int)Thread.currentThread().getId() % total; + } + + @Override + public int maxRetryCount() { + return 1; + } +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java new file mode 100644 index 000000000000..4344ad119e7e --- /dev/null +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.partition; + +/** + * use normal int to rolling. + * + * + * Created by wusheng on 2016/10/25. + */ +public class SimpleRollingPartitioner implements IDataPartitioner { + private volatile int i = 0; + + @Override + public int partition(int total, T data) { + return Math.abs(i++ % total); + } + + @Override + public int maxRetryCount() { + return 3; + } +} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java deleted file mode 100644 index 0a2a6c049b18..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.buffer; - -import java.util.LinkedList; -import org.skywalking.apm.commons.datacarrier.common.AtomicRangeInteger; - -/** - * Created by wusheng on 2016/10/25. - */ -public class Buffer { - private final Object[] buffer; - private BufferStrategy strategy; - private AtomicRangeInteger index; - - Buffer(int bufferSize, BufferStrategy strategy) { - buffer = new Object[bufferSize]; - this.strategy = strategy; - index = new AtomicRangeInteger(0, bufferSize); - } - - void setStrategy(BufferStrategy strategy) { - this.strategy = strategy; - } - - boolean save(T data) { - int i = index.getAndIncrement(); - if (buffer[i] != null) { - switch (strategy) { - case BLOCKING: - while (buffer[i] != null) { - try { - Thread.sleep(1L); - } catch (InterruptedException e) { - } - } - break; - case IF_POSSIBLE: - return false; - case OVERRIDE: - default: - } - } - buffer[i] = data; - return true; - } - - public int getBufferSize() { - return buffer.length; - } - - public LinkedList obtain(int start, int end) { - LinkedList result = new LinkedList(); - for (int i = start; i < end; i++) { - if (buffer[i] != null) { - result.add((T)buffer[i]); - buffer[i] = null; - } - } - return result; - } - -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java deleted file mode 100644 index 528dda662515..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.buffer; - -/** - * Created by wusheng on 2016/10/25. - */ -public enum BufferStrategy { - BLOCKING, - OVERRIDE, - IF_POSSIBLE -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java deleted file mode 100644 index b66995549ba5..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.common; - -import java.io.Serializable; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Created by wusheng on 2016/10/25. - */ -public class AtomicRangeInteger extends Number implements Serializable { - private static final long serialVersionUID = -4099792402691141643L; - private AtomicInteger value; - private int startValue; - private int endValue; - - public AtomicRangeInteger(int startValue, int maxValue) { - this.value = new AtomicInteger(startValue); - this.startValue = startValue; - this.endValue = maxValue - 1; - } - - public final int getAndIncrement() { - int current; - int next; - do { - current = this.value.get(); - next = current >= this.endValue ? this.startValue : current + 1; - } - while (!this.value.compareAndSet(current, next)); - - return current; - } - - public final int get() { - return this.value.get(); - } - - public int intValue() { - return this.value.intValue(); - } - - public long longValue() { - return this.value.longValue(); - } - - public float floatValue() { - return this.value.floatValue(); - } - - public double doubleValue() { - return this.value.doubleValue(); - } -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java deleted file mode 100644 index cdb0ee62724c..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.consumer; - -/** - * Created by wusheng on 2016/11/15. - */ -public class ConsumerCannotBeCreatedException extends RuntimeException { - ConsumerCannotBeCreatedException(Throwable t) { - super(t); - } -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java deleted file mode 100644 index 5ae1a614a598..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.consumer; - -import java.util.List; - -/** - * Created by wusheng on 2016/10/25. - */ -public interface IConsumer { - void init(); - - void consume(List data); - - void onError(List data, Throwable t); - - void onExit(); -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java deleted file mode 100644 index e74e1716dfaf..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.partition; - -import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; - -/** - * Created by wusheng on 2016/10/25. - */ -public interface IDataPartitioner { - int partition(int total, T data); - - /** - * @return an integer represents how many times should retry when {@link BufferStrategy#IF_POSSIBLE}. - * - * Less or equal 1, means not support retry. - */ - int maxRetryCount(); -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java deleted file mode 100644 index 2cce75d97639..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.partition; - -/** - * use threadid % total to partition - * - * Created by wusheng on 2016/10/25. - */ -public class ProducerThreadPartitioner implements IDataPartitioner { - private int retryTime = 3; - - public ProducerThreadPartitioner() { - } - - public ProducerThreadPartitioner(int retryTime) { - this.retryTime = retryTime; - } - - @Override - public int partition(int total, T data) { - return (int)Thread.currentThread().getId() % total; - } - - @Override - public int maxRetryCount() { - return 1; - } -} diff --git a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java deleted file mode 100644 index 02774b633799..000000000000 --- a/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.partition; - -/** - * use normal int to rolling. - * - * - * Created by wusheng on 2016/10/25. - */ -public class SimpleRollingPartitioner implements IDataPartitioner { - private volatile int i = 0; - - @Override - public int partition(int total, T data) { - return Math.abs(i++ % total); - } - - @Override - public int maxRetryCount() { - return 3; - } -} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/DataCarrierTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/DataCarrierTest.java similarity index 82% rename from apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/DataCarrierTest.java rename to apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/DataCarrierTest.java index 90099d2084f1..2e6d4cfda626 100644 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/DataCarrierTest.java +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/DataCarrierTest.java @@ -16,18 +16,36 @@ * */ -package org.skywalking.apm.commons.datacarrier; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier; import java.util.List; +import org.apache.skywalking.apm.commons.datacarrier.buffer.Buffer; +import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; +import org.apache.skywalking.apm.commons.datacarrier.buffer.Channels; +import org.apache.skywalking.apm.commons.datacarrier.partition.ProducerThreadPartitioner; +import org.apache.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner; import org.junit.Assert; import org.junit.Test; import org.powermock.api.support.membermodification.MemberModifier; -import org.skywalking.apm.commons.datacarrier.buffer.Buffer; -import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; -import org.skywalking.apm.commons.datacarrier.buffer.Channels; -import org.skywalking.apm.commons.datacarrier.consumer.IConsumer; -import org.skywalking.apm.commons.datacarrier.partition.ProducerThreadPartitioner; -import org.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner; +import org.apache.skywalking.apm.commons.datacarrier.consumer.IConsumer; /** * Created by wusheng on 2016/10/25. diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/SampleData.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/SampleData.java new file mode 100644 index 000000000000..668866e157f7 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/SampleData.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier; + +/** + * Created by wusheng on 2016/10/25. + */ +public class SampleData { + private int intValue; + + private String name; + + public int getIntValue() { + return intValue; + } + + public String getName() { + return name; + } + + public SampleData setIntValue(int intValue) { + this.intValue = intValue; + return this; + } + + public SampleData setName(String name) { + this.name = name; + return this; + } +} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java new file mode 100644 index 000000000000..0f09270b8c19 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.common; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by xin on 2017/7/14. + */ +public class AtomicRangeIntegerTest { + @Test + public void testGetAndIncrement() { + AtomicRangeInteger atomicI = new AtomicRangeInteger(0, 10); + for (int i = 0; i < 10; i++) { + Assert.assertEquals(i, atomicI.getAndIncrement()); + } + Assert.assertEquals(0, atomicI.getAndIncrement()); + Assert.assertEquals(1, atomicI.get()); + Assert.assertEquals(1, atomicI.intValue()); + Assert.assertEquals(1, atomicI.longValue()); + Assert.assertEquals(1, (int)atomicI.floatValue()); + Assert.assertEquals(1, (int)atomicI.doubleValue()); + } +} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java new file mode 100644 index 000000000000..59aa3696d7eb --- /dev/null +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; + +import org.apache.skywalking.apm.commons.datacarrier.buffer.Channels; +import org.apache.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner; +import org.junit.Assert; +import org.junit.Test; +import org.powermock.api.support.membermodification.MemberModifier; +import org.apache.skywalking.apm.commons.datacarrier.SampleData; +import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; + +/** + * Created by wusheng on 2016/10/26. + */ +public class ConsumerPoolTest { + @Test + public void testBeginConsumerPool() throws IllegalAccessException { + Channels channels = new Channels(2, 100, new SimpleRollingPartitioner(), BufferStrategy.BLOCKING); + ConsumerPool pool = new ConsumerPool(channels, new SampleConsumer(), 2); + pool.begin(); + + ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool); + Assert.assertEquals(2, threads.length); + Assert.assertTrue(threads[0].isAlive()); + Assert.assertTrue(threads[1].isAlive()); + } + + @Test + public void testCloseConsumerPool() throws InterruptedException, IllegalAccessException { + Channels channels = new Channels(2, 100, new SimpleRollingPartitioner(), BufferStrategy.BLOCKING); + ConsumerPool pool = new ConsumerPool(channels, new SampleConsumer(), 2); + pool.begin(); + + Thread.sleep(5000); + pool.close(); + ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool); + + Assert.assertEquals(2, threads.length); + Assert.assertFalse((Boolean)MemberModifier.field(ConsumerThread.class, "running").get(threads[0])); + Assert.assertFalse((Boolean)MemberModifier.field(ConsumerThread.class, "running").get(threads[1])); + } +} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java similarity index 81% rename from apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java rename to apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java index 553570e50df0..1854b52012fb 100644 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java @@ -16,17 +16,35 @@ * */ -package org.skywalking.apm.commons.datacarrier.consumer; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.concurrent.LinkedBlockingQueue; +import org.apache.skywalking.apm.commons.datacarrier.DataCarrier; +import org.apache.skywalking.apm.commons.datacarrier.SampleData; import org.junit.Assert; import org.junit.Test; import org.powermock.api.support.membermodification.MemberModifier; -import org.skywalking.apm.commons.datacarrier.DataCarrier; -import org.skywalking.apm.commons.datacarrier.SampleData; /** * Created by wusheng on 2016/10/26. diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java new file mode 100644 index 000000000000..6a6a2516a715 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.consumer; + +import java.util.List; +import org.apache.skywalking.apm.commons.datacarrier.SampleData; + +/** + * Created by wusheng on 2016/10/26. + */ +public class SampleConsumer implements IConsumer { + public int i = 1; + + @Override + public void init() { + + } + + @Override + public void consume(List data) { + for (SampleData one : data) { + one.setIntValue(this.hashCode()); + ConsumerTest.BUFFER.offer(one); + } + } + + @Override + public void onError(List data, Throwable t) { + + } + + @Override + public void onExit() { + + } +} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java new file mode 100644 index 000000000000..0d0bbff9559f --- /dev/null +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.partition; + +import org.apache.skywalking.apm.commons.datacarrier.SampleData; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by wusheng on 2016/10/25. + */ +public class ProducerThreadPartitionerTest { + @Test + public void testPartition() { + int partitionNum = (int)Thread.currentThread().getId() % 10; + ProducerThreadPartitioner partitioner = new ProducerThreadPartitioner(); + Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum); + Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum); + Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum); + } +} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java new file mode 100644 index 000000000000..c3ec06638659 --- /dev/null +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.commons.datacarrier.partition; + +import org.apache.skywalking.apm.commons.datacarrier.SampleData; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by wusheng on 2016/10/25. + */ +public class SimpleRollingPartitionerTest { + @Test + public void testPartition() { + SimpleRollingPartitioner partitioner = new SimpleRollingPartitioner(); + Assert.assertEquals(partitioner.partition(10, new SampleData()), 0); + Assert.assertEquals(partitioner.partition(10, new SampleData()), 1); + Assert.assertEquals(partitioner.partition(10, new SampleData()), 2); + } +} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java deleted file mode 100644 index fc238298b8f2..000000000000 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier; - -/** - * Created by wusheng on 2016/10/25. - */ -public class SampleData { - private int intValue; - - private String name; - - public int getIntValue() { - return intValue; - } - - public String getName() { - return name; - } - - public SampleData setIntValue(int intValue) { - this.intValue = intValue; - return this; - } - - public SampleData setName(String name) { - this.name = name; - return this; - } -} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java deleted file mode 100644 index 7f0fc1c30bb2..000000000000 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.common; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by xin on 2017/7/14. - */ -public class AtomicRangeIntegerTest { - @Test - public void testGetAndIncrement() { - AtomicRangeInteger atomicI = new AtomicRangeInteger(0, 10); - for (int i = 0; i < 10; i++) { - Assert.assertEquals(i, atomicI.getAndIncrement()); - } - Assert.assertEquals(0, atomicI.getAndIncrement()); - Assert.assertEquals(1, atomicI.get()); - Assert.assertEquals(1, atomicI.intValue()); - Assert.assertEquals(1, atomicI.longValue()); - Assert.assertEquals(1, (int)atomicI.floatValue()); - Assert.assertEquals(1, (int)atomicI.doubleValue()); - } -} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java deleted file mode 100644 index 494058a90dfb..000000000000 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.consumer; - -import org.junit.Assert; -import org.junit.Test; -import org.powermock.api.support.membermodification.MemberModifier; -import org.skywalking.apm.commons.datacarrier.SampleData; -import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; -import org.skywalking.apm.commons.datacarrier.buffer.Channels; -import org.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner; - -/** - * Created by wusheng on 2016/10/26. - */ -public class ConsumerPoolTest { - @Test - public void testBeginConsumerPool() throws IllegalAccessException { - Channels channels = new Channels(2, 100, new SimpleRollingPartitioner(), BufferStrategy.BLOCKING); - ConsumerPool pool = new ConsumerPool(channels, new SampleConsumer(), 2); - pool.begin(); - - ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool); - Assert.assertEquals(2, threads.length); - Assert.assertTrue(threads[0].isAlive()); - Assert.assertTrue(threads[1].isAlive()); - } - - @Test - public void testCloseConsumerPool() throws InterruptedException, IllegalAccessException { - Channels channels = new Channels(2, 100, new SimpleRollingPartitioner(), BufferStrategy.BLOCKING); - ConsumerPool pool = new ConsumerPool(channels, new SampleConsumer(), 2); - pool.begin(); - - Thread.sleep(5000); - pool.close(); - ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool); - - Assert.assertEquals(2, threads.length); - Assert.assertFalse((Boolean)MemberModifier.field(ConsumerThread.class, "running").get(threads[0])); - Assert.assertFalse((Boolean)MemberModifier.field(ConsumerThread.class, "running").get(threads[1])); - } -} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java deleted file mode 100644 index 6b54c09c852b..000000000000 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.consumer; - -import java.util.List; -import org.skywalking.apm.commons.datacarrier.SampleData; - -/** - * Created by wusheng on 2016/10/26. - */ -public class SampleConsumer implements IConsumer { - public int i = 1; - - @Override - public void init() { - - } - - @Override - public void consume(List data) { - for (SampleData one : data) { - one.setIntValue(this.hashCode()); - ConsumerTest.BUFFER.offer(one); - } - } - - @Override - public void onError(List data, Throwable t) { - - } - - @Override - public void onExit() { - - } -} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java deleted file mode 100644 index a9fd9aa68ff8..000000000000 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.partition; - -import org.junit.Assert; -import org.junit.Test; -import org.skywalking.apm.commons.datacarrier.SampleData; - -/** - * Created by wusheng on 2016/10/25. - */ -public class ProducerThreadPartitionerTest { - @Test - public void testPartition() { - int partitionNum = (int)Thread.currentThread().getId() % 10; - ProducerThreadPartitioner partitioner = new ProducerThreadPartitioner(); - Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum); - Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum); - Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum); - } -} diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java deleted file mode 100644 index d867ea346d48..000000000000 --- a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.commons.datacarrier.partition; - -import org.junit.Assert; -import org.junit.Test; -import org.skywalking.apm.commons.datacarrier.SampleData; - -/** - * Created by wusheng on 2016/10/25. - */ -public class SimpleRollingPartitionerTest { - @Test - public void testPartition() { - SimpleRollingPartitioner partitioner = new SimpleRollingPartitioner(); - Assert.assertEquals(partitioner.partition(10, new SampleData()), 0); - Assert.assertEquals(partitioner.partition(10, new SampleData()), 1); - Assert.assertEquals(partitioner.partition(10, new SampleData()), 2); - } -} diff --git a/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/ConfigInitializer.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/ConfigInitializer.java similarity index 83% rename from apm-commons/apm-util/src/main/java/org/skywalking/apm/util/ConfigInitializer.java rename to apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/ConfigInitializer.java index 93fae9c2c3d5..7e33e450163a 100644 --- a/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/ConfigInitializer.java +++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/ConfigInitializer.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.util; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.util; import java.lang.reflect.Field; import java.lang.reflect.Modifier; diff --git a/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/MachineInfo.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/MachineInfo.java similarity index 75% rename from apm-commons/apm-util/src/main/java/org/skywalking/apm/util/MachineInfo.java rename to apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/MachineInfo.java index b5a143116e9b..53f697d6fc33 100644 --- a/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/MachineInfo.java +++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/MachineInfo.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.util; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.util; import java.lang.management.ManagementFactory; import java.net.InetAddress; diff --git a/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java new file mode 100644 index 000000000000..9796f09e4dc1 --- /dev/null +++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.util; + +public final class StringUtil { + public static boolean isEmpty(String str) { + if (str == null || "".equals(str) || str.length() == 0) { + return true; + } + return false; + } + + public static String join(final char delimiter, final String... strings) { + if (strings.length == 0) { + return null; + } + if (strings.length == 1) { + return strings[0]; + } + int length = strings.length - 1; + for (final String s : strings) { + if (s == null) { + continue; + } + length += s.length(); + } + final StringBuilder sb = new StringBuilder(length); + if (strings[0] != null) { + sb.append(strings[0]); + } + for (int i = 1; i < strings.length; ++i) { + if (!isEmpty(strings[i])) { + sb.append(delimiter).append(strings[i]); + } else { + sb.append(delimiter); + } + } + return sb.toString(); + } +} diff --git a/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/StringUtil.java b/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/StringUtil.java deleted file mode 100644 index 64b37b0038ae..000000000000 --- a/apm-commons/apm-util/src/main/java/org/skywalking/apm/util/StringUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.util; - -public final class StringUtil { - public static boolean isEmpty(String str) { - if (str == null || "".equals(str) || str.length() == 0) { - return true; - } - return false; - } - - public static String join(final char delimiter, final String... strings) { - if (strings.length == 0) { - return null; - } - if (strings.length == 1) { - return strings[0]; - } - int length = strings.length - 1; - for (final String s : strings) { - if (s == null) { - continue; - } - length += s.length(); - } - final StringBuilder sb = new StringBuilder(length); - if (strings[0] != null) { - sb.append(strings[0]); - } - for (int i = 1; i < strings.length; ++i) { - if (!isEmpty(strings[i])) { - sb.append(delimiter).append(strings[i]); - } else { - sb.append(delimiter); - } - } - return sb.toString(); - } -} diff --git a/apm-commons/apm-util/src/test/java/org/skywalking/apm/util/ConfigInitializerTest.java b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/ConfigInitializerTest.java similarity index 77% rename from apm-commons/apm-util/src/test/java/org/skywalking/apm/util/ConfigInitializerTest.java rename to apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/ConfigInitializerTest.java index e8dc86512e51..9bb01c11764f 100644 --- a/apm-commons/apm-util/src/test/java/org/skywalking/apm/util/ConfigInitializerTest.java +++ b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/ConfigInitializerTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.util; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.util; import java.util.Properties; import org.junit.Assert; diff --git a/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java new file mode 100644 index 000000000000..c29b1ef6f5a7 --- /dev/null +++ b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by wusheng on 2017/2/27. + */ +public class StringUtilTest { + @Test + public void testIsEmpty() { + Assert.assertTrue(StringUtil.isEmpty(null)); + Assert.assertTrue(StringUtil.isEmpty("")); + Assert.assertFalse(StringUtil.isEmpty(" ")); + Assert.assertFalse(StringUtil.isEmpty("A String")); + } + + @Test + public void testJoin() { + Assert.assertNull(StringUtil.join('.')); + Assert.assertEquals("Single part.", StringUtil.join('.', "Single part.")); + Assert.assertEquals("part1.part2.p3", StringUtil.join('.', "part1", "part2", "p3")); + } +} diff --git a/apm-commons/apm-util/src/test/java/org/skywalking/apm/util/StringUtilTest.java b/apm-commons/apm-util/src/test/java/org/skywalking/apm/util/StringUtilTest.java deleted file mode 100644 index 015cf49bffbe..000000000000 --- a/apm-commons/apm-util/src/test/java/org/skywalking/apm/util/StringUtilTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.util; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by wusheng on 2017/2/27. - */ -public class StringUtilTest { - @Test - public void testIsEmpty() { - Assert.assertTrue(StringUtil.isEmpty(null)); - Assert.assertTrue(StringUtil.isEmpty("")); - Assert.assertFalse(StringUtil.isEmpty(" ")); - Assert.assertFalse(StringUtil.isEmpty("A String")); - } - - @Test - public void testJoin() { - Assert.assertNull(StringUtil.join('.')); - Assert.assertEquals("Single part.", StringUtil.join('.', "Single part.")); - Assert.assertEquals("part1.part2.p3", StringUtil.join('.', "part1", "part2", "p3")); - } -} diff --git a/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/Component.java b/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/Component.java new file mode 100644 index 000000000000..dc8043ef1512 --- /dev/null +++ b/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/Component.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.network.trace.component; + +/** + * The Component represents component library, + * which has been supported by skywalking sniffer. + * + * The supported list is in {@link ComponentsDefine}. + * + * @author wusheng + */ +public interface Component { + int getId(); + + String getName(); +} diff --git a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java similarity index 82% rename from apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java rename to apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index a38f228f5fca..de3802f0750f 100644 --- a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.network.trace.component; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.network.trace.component; /** * The supported list of skywalking java sniffer. @@ -76,12 +94,12 @@ public class ComponentsDefine { public static final OfficialComponent ROCKET_MQ = new OfficialComponent(25, "RocketMQ"); - private static ComponentsDefine instance = new ComponentsDefine(); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; public static ComponentsDefine getInstance() { - return instance; + return INSTANCE; } public ComponentsDefine() { diff --git a/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/OfficialComponent.java b/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/OfficialComponent.java new file mode 100644 index 000000000000..57707e79dd94 --- /dev/null +++ b/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/OfficialComponent.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.network.trace.component; + +/** + * @author wusheng + */ +public class OfficialComponent implements Component { + private int id; + private String name; + + public OfficialComponent(int id, String name) { + this.id = id; + this.name = name; + } + + @Override + public int getId() { + return id; + } + + @Override + public String getName() { + return name; + } +} diff --git a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java deleted file mode 100644 index 959f8adcb8e4..000000000000 --- a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.network.trace.component; - -/** - * The Component represents component library, - * which has been supported by skywalking sniffer. - * - * The supported list is in {@link ComponentsDefine}. - * - * @author wusheng - */ -public interface Component { - int getId(); - - String getName(); -} diff --git a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/OfficialComponent.java b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/OfficialComponent.java deleted file mode 100644 index 88fd7e1088f3..000000000000 --- a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/OfficialComponent.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.network.trace.component; - -/** - * @author wusheng - */ -public class OfficialComponent implements Component { - private int id; - private String name; - - public OfficialComponent(int id, String name) { - this.id = id; - this.name = name; - } - - @Override - public int getId() { - return id; - } - - @Override - public String getName() { - return name; - } -} diff --git a/apm-network/src/main/proto/ApplicationRegisterService.proto b/apm-network/src/main/proto/ApplicationRegisterService.proto index a40392bb3961..2143448b86f1 100644 --- a/apm-network/src/main/proto/ApplicationRegisterService.proto +++ b/apm-network/src/main/proto/ApplicationRegisterService.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "KeyWithIntegerValue.proto"; @@ -17,4 +17,4 @@ message Application { message ApplicationMapping { repeated KeyWithIntegerValue application = 1; -} \ No newline at end of file +} diff --git a/apm-network/src/main/proto/DiscoveryService.proto b/apm-network/src/main/proto/DiscoveryService.proto index 0715b36b5a08..5605c0d024e9 100644 --- a/apm-network/src/main/proto/DiscoveryService.proto +++ b/apm-network/src/main/proto/DiscoveryService.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "Downstream.proto"; diff --git a/apm-network/src/main/proto/Downstream.proto b/apm-network/src/main/proto/Downstream.proto index cbeb2f41abc2..bf38d5311f24 100644 --- a/apm-network/src/main/proto/Downstream.proto +++ b/apm-network/src/main/proto/Downstream.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; // nothing down stream from collector yet. message Downstream { diff --git a/apm-network/src/main/proto/JVMMetricsService.proto b/apm-network/src/main/proto/JVMMetricsService.proto index 2f9bc8d72668..6e074347283d 100644 --- a/apm-network/src/main/proto/JVMMetricsService.proto +++ b/apm-network/src/main/proto/JVMMetricsService.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "Downstream.proto"; diff --git a/apm-network/src/main/proto/KeyWithIntegerValue.proto b/apm-network/src/main/proto/KeyWithIntegerValue.proto index 328ef45a5579..c01f49889b8a 100644 --- a/apm-network/src/main/proto/KeyWithIntegerValue.proto +++ b/apm-network/src/main/proto/KeyWithIntegerValue.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; message KeyWithIntegerValue { string key = 1; diff --git a/apm-network/src/main/proto/KeyWithStringValue.proto b/apm-network/src/main/proto/KeyWithStringValue.proto index e1a3a4e3e149..92cbd45a4887 100644 --- a/apm-network/src/main/proto/KeyWithStringValue.proto +++ b/apm-network/src/main/proto/KeyWithStringValue.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; message KeyWithStringValue { string key = 1; diff --git a/apm-network/src/main/proto/TraceSegmentService.proto b/apm-network/src/main/proto/TraceSegmentService.proto index daaf0aa00807..607d8a6e4333 100644 --- a/apm-network/src/main/proto/TraceSegmentService.proto +++ b/apm-network/src/main/proto/TraceSegmentService.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "Downstream.proto"; import "KeyWithStringValue.proto"; diff --git a/apm-network/src/test/java/org/apache/skywalking/apm/network/trace/proto/GRPCNoServerTest.java b/apm-network/src/test/java/org/apache/skywalking/apm/network/trace/proto/GRPCNoServerTest.java new file mode 100644 index 000000000000..9b1939717526 --- /dev/null +++ b/apm-network/src/test/java/org/apache/skywalking/apm/network/trace/proto/GRPCNoServerTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.network.trace.proto; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import io.grpc.internal.DnsNameResolverProvider; +import io.grpc.netty.NettyChannelBuilder; +import io.grpc.stub.StreamObserver; +import org.junit.Assert; +import org.apache.skywalking.apm.network.proto.Downstream; +import org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +/** + * @author wusheng + */ +public class GRPCNoServerTest { + public static void main(String[] args) throws InterruptedException { + ManagedChannelBuilder channelBuilder = + NettyChannelBuilder.forAddress("127.0.0.1", 8080) + .nameResolverFactory(new DnsNameResolverProvider()) + .maxInboundMessageSize(1024 * 1024 * 50) + .usePlaintext(true); + ManagedChannel channel = channelBuilder.build(); + TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub = TraceSegmentServiceGrpc.newStub(channel); + final Status[] status = {null}; + StreamObserver streamObserver = serviceStub.collect(new StreamObserver() { + @Override public void onNext(Downstream value) { + + } + + @Override public void onError(Throwable t) { + status[0] = ((StatusRuntimeException)t).getStatus(); + } + + @Override public void onCompleted() { + + } + }); + + streamObserver.onNext(null); + streamObserver.onCompleted(); + + Thread.sleep(2 * 1000); + + Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode()); + } +} diff --git a/apm-network/src/test/java/org/skywalking/apm/network/trace/proto/GRPCNoServerTest.java b/apm-network/src/test/java/org/skywalking/apm/network/trace/proto/GRPCNoServerTest.java deleted file mode 100644 index 0ef28be45213..000000000000 --- a/apm-network/src/test/java/org/skywalking/apm/network/trace/proto/GRPCNoServerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.network.trace.proto; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.grpc.Status; -import io.grpc.StatusRuntimeException; -import io.grpc.internal.DnsNameResolverProvider; -import io.grpc.netty.NettyChannelBuilder; -import io.grpc.stub.StreamObserver; -import org.junit.Assert; -import org.skywalking.apm.network.proto.Downstream; -import org.skywalking.apm.network.proto.TraceSegmentServiceGrpc; -import org.skywalking.apm.network.proto.UpstreamSegment; - -/** - * @author wusheng - */ -public class GRPCNoServerTest { - public static void main(String[] args) throws InterruptedException { - ManagedChannelBuilder channelBuilder = - NettyChannelBuilder.forAddress("127.0.0.1", 8080) - .nameResolverFactory(new DnsNameResolverProvider()) - .maxInboundMessageSize(1024 * 1024 * 50) - .usePlaintext(true); - ManagedChannel channel = channelBuilder.build(); - TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub = TraceSegmentServiceGrpc.newStub(channel); - final Status[] status = {null}; - StreamObserver streamObserver = serviceStub.collect(new StreamObserver() { - @Override public void onNext(Downstream value) { - - } - - @Override public void onError(Throwable t) { - status[0] = ((StatusRuntimeException)t).getStatus(); - } - - @Override public void onCompleted() { - - } - }); - - streamObserver.onNext(null); - streamObserver.onCompleted(); - - Thread.sleep(2 * 1000); - - Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode()); - } -} diff --git a/apm-sniffer/apm-agent-core/pom.xml b/apm-sniffer/apm-agent-core/pom.xml index d24408f65091..c610d973d8ee 100644 --- a/apm-sniffer/apm-agent-core/pom.xml +++ b/apm-sniffer/apm-agent-core/pom.xml @@ -38,14 +38,12 @@ 1.8.0 1.7.6 - org.skywalking.apm.dependencies + org.apache.skywalking.apm.dependencies com.lmax.disruptor ${shade.package}.${shade.com.lmax.disruptor.source} com.google ${shade.package}.${shade.com.google.source} - org.apache - ${shade.package}.${shade.org.apache.source} io.grpc ${shade.package}.${shade.io.grpc.source} io.netty @@ -166,10 +164,6 @@ ${shade.com.google.source} ${shade.com.google.target} - - ${shade.org.apache.source} - ${shade.org.apache.target} - ${shade.io.grpc.source} ${shade.io.grpc.target} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java new file mode 100644 index 000000000000..5ddcbf28b297 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; + +/** + * @author wusheng + */ +public class AgentPackageNotFoundException extends Exception { + public AgentPackageNotFoundException(String message) { + super(message); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.java new file mode 100644 index 000000000000..86f2378b1349 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; + +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +/** + * @author wusheng + */ +public class AgentPackagePath { + private static final ILog logger = LogManager.getLogger(AgentPackagePath.class); + + private static File AGENT_PACKAGE_PATH; + + public static File getPath() throws AgentPackageNotFoundException { + if (AGENT_PACKAGE_PATH == null) { + AGENT_PACKAGE_PATH = findPath(); + } + return AGENT_PACKAGE_PATH; + } + + public static boolean isPathFound() { + return AGENT_PACKAGE_PATH != null; + } + + private static File findPath() throws AgentPackageNotFoundException { + String classResourcePath = AgentPackagePath.class.getName().replaceAll("\\.", "/") + ".class"; + + URL resource = AgentPackagePath.class.getClassLoader().getSystemClassLoader().getResource(classResourcePath); + if (resource != null) { + String urlString = resource.toString(); + + logger.debug("The beacon class location is {}.", urlString); + + int insidePathIndex = urlString.indexOf('!'); + boolean isInJar = insidePathIndex > -1; + + if (isInJar) { + urlString = urlString.substring(urlString.indexOf("file:"), insidePathIndex); + File agentJarFile = null; + try { + agentJarFile = new File(new URL(urlString).getFile()); + } catch (MalformedURLException e) { + logger.error(e, "Can not locate agent jar file by url:" + urlString); + } + if (agentJarFile.exists()) { + return agentJarFile.getParentFile(); + } + } else { + String classLocation = urlString.substring(urlString.indexOf("file:"), urlString.length() - classResourcePath.length()); + return new File(classLocation); + } + } + + logger.error("Can not locate agent jar file."); + throw new AgentPackageNotFoundException("Can not locate agent jar file."); + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/BootService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/BootService.java new file mode 100644 index 000000000000..81c9d4425a3b --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/BootService.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; + +/** + * The BootService is an interface to all remote, which need to boot when plugin mechanism begins to + * work. + * {@link #boot()} will be called when BootService start up. + * + * @author wusheng + */ +public interface BootService { + void beforeBoot() throws Throwable; + + void boot() throws Throwable; + + void afterBoot() throws Throwable; + + void shutdown() throws Throwable; +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java new file mode 100644 index 000000000000..fe7c0d064483 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author zhangkewei + */ +public class DefaultNamedThreadFactory implements ThreadFactory { + private static final AtomicInteger BOOT_SERVICE_SEQ = new AtomicInteger(0); + private final AtomicInteger threadSeq = new AtomicInteger(0); + private final String namePrefix; + public DefaultNamedThreadFactory(String name) { + namePrefix = "SkywalkingAgent-" + BOOT_SERVICE_SEQ.incrementAndGet() + "-" + name + "-"; + } + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r,namePrefix + threadSeq.getAndIncrement()); + t.setDaemon(true); + return t; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/ServiceManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/ServiceManager.java similarity index 78% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/ServiceManager.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/ServiceManager.java index 7a0c83501f7c..1f8c3f8bf675 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/ServiceManager.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/ServiceManager.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.agent.core.boot; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.ServiceLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; /** * The ServiceManager bases on {@link ServiceLoader}, diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java similarity index 81% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index ee66bae3217e..95c9106a9d66 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.agent.core.conf; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.conf; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.logging.core.LogLevel; -import org.skywalking.apm.agent.core.logging.core.WriterFactory; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.logging.core.LogLevel; +import org.apache.skywalking.apm.agent.core.logging.core.WriterFactory; /** * This is the core config in sniffer agent. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/ConfigNotFoundException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/ConfigNotFoundException.java new file mode 100644 index 000000000000..ea549e2aca2d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/ConfigNotFoundException.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.conf; + +/** + * @author wusheng + */ +public class ConfigNotFoundException extends Exception { + public ConfigNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ConfigNotFoundException(String message) { + super(message); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Constants.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Constants.java new file mode 100644 index 000000000000..cf935c1434ee --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Constants.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.conf; + +public class Constants { + public static String PATH_SEPARATOR = System.getProperty("file.separator", "/"); + + public static String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java new file mode 100644 index 000000000000..9c17d3471022 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.conf; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; + +/** + * The RemoteDownstreamConfig includes configurations from collector side. + * All of them initialized null, Null-Value or empty collection. + * + * @author wusheng + */ +public class RemoteDownstreamConfig { + public static class Agent { + public volatile static int APPLICATION_ID = DictionaryUtil.nullValue(); + + public volatile static int APPLICATION_INSTANCE_ID = DictionaryUtil.nullValue(); + } + + public static class Collector { + /** + * Collector GRPC-Service address. + */ + public volatile static List GRPC_SERVERS = new LinkedList(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java similarity index 80% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java index 0e313996b393..6baa9c2a9289 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.agent.core.conf; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.conf; -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.util.ConfigInitializer; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.util.ConfigInitializer; +import org.apache.skywalking.apm.util.StringUtil; import java.io.File; import java.io.FileInputStream; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/AbstractTracerContext.java similarity index 77% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/AbstractTracerContext.java index b2d580439198..2b866e7d9b76 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/AbstractTracerContext.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.agent.core.context; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.EntrySpan; -import org.skywalking.apm.agent.core.context.trace.ExitSpan; -import org.skywalking.apm.agent.core.context.trace.LocalSpan; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.EntrySpan; +import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LocalSpan; /** * The AbstractTracerContext represents the tracer context manager. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItem.java new file mode 100644 index 000000000000..5311ac3ac4b2 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItem.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +import java.util.Iterator; + +/** + * @author wusheng + */ +public class CarrierItem implements Iterator { + private String headKey; + private String headValue; + private CarrierItem next; + + public CarrierItem(String headKey, String headValue) { + this.headKey = headKey; + this.headValue = headValue; + next = null; + } + + public CarrierItem(String headKey, String headValue, CarrierItem next) { + this.headKey = headKey; + this.headValue = headValue; + this.next = next; + } + + public String getHeadKey() { + return headKey; + } + + public String getHeadValue() { + return headValue; + } + + public void setHeadValue(String headValue) { + this.headValue = headValue; + } + + @Override + public boolean hasNext() { + return next != null; + } + + @Override + public CarrierItem next() { + return next; + } + + @Override + public void remove() { + + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItemHead.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItemHead.java new file mode 100644 index 000000000000..9e90c5690cd9 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CarrierItemHead.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +/** + * @author wusheng + */ +public class CarrierItemHead extends CarrierItem { + public CarrierItemHead(CarrierItem next) { + super("", "", next); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java similarity index 84% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java index 1e79f6e92d7b..ec4323dc19eb 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java @@ -16,16 +16,34 @@ * */ -package org.skywalking.apm.agent.core.context; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; import java.io.Serializable; import java.util.List; -import org.skywalking.apm.agent.core.context.ids.DistributedTraceId; -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.context.ids.PropagatedTraceId; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.ids.PropagatedTraceId; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.util.StringUtil; /** * {@link ContextCarrier} is a data carrier of {@link TracingContext}. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java similarity index 81% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java index 735bc5c04802..80b151d60035 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java @@ -16,19 +16,37 @@ * */ -package org.skywalking.apm.agent.core.context; - -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.agent.core.sampling.SamplingService; -import org.skywalking.apm.util.StringUtil; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.sampling.SamplingService; +import org.apache.skywalking.apm.util.StringUtil; /** * {@link ContextManager} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextSnapshot.java similarity index 75% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextSnapshot.java index 603705285bd8..0388ecedc84f 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextSnapshot.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.agent.core.context; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; import java.util.List; -import org.skywalking.apm.agent.core.context.ids.DistributedTraceId; -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.util.StringUtil; /** * The ContextSnapshot is a snapshot for current context. The snapshot carries the info for building diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java new file mode 100644 index 000000000000..93628218d4d5 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +/** + * @author wusheng + */ +public interface IgnoreTracerContextListener { + void afterFinished(IgnoredTracerContext traceSegment); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContext.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContext.java index 5745af67bd1d..b0693079eca8 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContext.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.agent.core.context; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.NoopSpan; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.NoopSpan; /** * The IgnoredTracerContext represent a context should be ignored. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/Injectable.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/Injectable.java new file mode 100644 index 000000000000..5b0c15d459c5 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/Injectable.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +/** + * The Injectable represents a provider, which gives the reference of {@link ContextCarrier} and peer + * for the agent core, for cross-process propagation. + * + * @author wusheng + */ +public interface Injectable { + ContextCarrier getCarrier(); + + /** + * @return peer, represent ipv4, ipv6, hostname, or cluster addresses list. + */ + String getPeer(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/SW3CarrierItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/SW3CarrierItem.java new file mode 100644 index 000000000000..5e320d088ab4 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/SW3CarrierItem.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +/** + * @author wusheng + */ +public class SW3CarrierItem extends CarrierItem { + public static final String HEADER_NAME = "sw3"; + private ContextCarrier carrier; + + public SW3CarrierItem(ContextCarrier carrier, CarrierItem next) { + super(HEADER_NAME, carrier.serialize(), next); + this.carrier = carrier; + } + + @Override + public void setHeadValue(String headValue) { + carrier.deserialize(headValue); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TraceContextCarrierItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TraceContextCarrierItem.java new file mode 100644 index 000000000000..da53d8e811e7 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TraceContextCarrierItem.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +/** + * @author wusheng + */ +public class TraceContextCarrierItem extends CarrierItem { + private static final String HEAD_NAME = "Trace-Context"; + + public TraceContextCarrierItem(String headValue, CarrierItem next) { + super(HEAD_NAME, headValue, next); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java similarity index 90% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java index aa72c1dd12e6..5d66466f1671 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java @@ -16,26 +16,44 @@ * */ -package org.skywalking.apm.agent.core.context; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.EntrySpan; -import org.skywalking.apm.agent.core.context.trace.ExitSpan; -import org.skywalking.apm.agent.core.context.trace.LocalSpan; -import org.skywalking.apm.agent.core.context.trace.NoopExitSpan; -import org.skywalking.apm.agent.core.context.trace.NoopSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.context.trace.WithPeerInfo; -import org.skywalking.apm.agent.core.dictionary.DictionaryManager; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.agent.core.dictionary.PossibleFound; -import org.skywalking.apm.agent.core.sampling.SamplingService; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.EntrySpan; +import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LocalSpan; +import org.apache.skywalking.apm.agent.core.context.trace.NoopExitSpan; +import org.apache.skywalking.apm.agent.core.context.trace.NoopSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.context.trace.WithPeerInfo; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryManager; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.dictionary.PossibleFound; +import org.apache.skywalking.apm.agent.core.sampling.SamplingService; /** * The TracingContext represents a core tracing logic controller. It build the final {@link diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContextListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContextListener.java new file mode 100644 index 000000000000..44c9c636dc30 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContextListener.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; + +public interface TracingContextListener { + void afterFinished(TraceSegment traceSegment); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceId.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceId.java new file mode 100644 index 000000000000..f4f63dd332a9 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceId.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.ids; + +import org.apache.skywalking.apm.network.proto.UniqueId; + +/** + * The DistributedTraceId presents a distributed call chain. + *

+ * This call chain has an unique (service) entrance, + *

+ * such as: Service : http://www.skywalking.com/cust/query, all the remote, called behind this service, rest remote, + * db executions, are using the same DistributedTraceId even in different JVM. + *

+ * The DistributedTraceId contains only one string, and can NOT be reset, creating a new instance is the + * only option. + * + * @author wusheng + */ +public abstract class DistributedTraceId { + private ID id; + + public DistributedTraceId(ID id) { + this.id = id; + } + + public DistributedTraceId(String id) { + this.id = new ID(id); + } + + public String encode() { + return id.encode(); + } + + @Override + public String toString() { + return id.toString(); + } + + public UniqueId toUniqueId() { + return id.transform(); + } + + /** + * Compare the two DistributedTraceId by its {@link #id}, + * even these two DistributedTraceIds are not the same instances. + * + * @param o target DistributedTraceId + * @return return if they have the same {@link #id} + */ + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + DistributedTraceId id1 = (DistributedTraceId)o; + + return id != null ? id.equals(id1.id) : id1.id == null; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java new file mode 100644 index 000000000000..6935d7ec0fe1 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.ids; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * @author wusheng + */ +public class DistributedTraceIds { + private LinkedList relatedGlobalTraces; + + public DistributedTraceIds() { + relatedGlobalTraces = new LinkedList(); + } + + public List getRelatedGlobalTraces() { + return Collections.unmodifiableList(relatedGlobalTraces); + } + + public void append(DistributedTraceId distributedTraceId) { + if (relatedGlobalTraces.size() > 0 && relatedGlobalTraces.getFirst() instanceof NewDistributedTraceId) { + relatedGlobalTraces.removeFirst(); + } + if (!relatedGlobalTraces.contains(distributedTraceId)) { + relatedGlobalTraces.add(distributedTraceId); + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java index 6d751cff4a6a..a7673f6f168c 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.agent.core.context.ids; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.ids; import java.util.Random; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; public final class GlobalIdGenerator { private static final ThreadLocal THREAD_ID_SEQUENCE = new ThreadLocal() { diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/ID.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/ID.java similarity index 75% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/ID.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/ID.java index 9ba21e592404..4192fe070b7c 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/ID.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/ID.java @@ -16,9 +16,27 @@ * */ -package org.skywalking.apm.agent.core.context.ids; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.ids; -import org.skywalking.apm.network.proto.UniqueId; +import org.apache.skywalking.apm.network.proto.UniqueId; /** * @author wusheng diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java new file mode 100644 index 000000000000..8f689ab02430 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.ids; + +/** + * The NewDistributedTraceId is a {@link DistributedTraceId} with a new generated id. + * + * @author wusheng + */ +public class NewDistributedTraceId extends DistributedTraceId { + public NewDistributedTraceId() { + super(GlobalIdGenerator.generate()); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java new file mode 100644 index 000000000000..4ad4196afd7e --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.ids; + +/** + * The PropagatedTraceId represents a {@link DistributedTraceId}, which is propagated from the peer. + * + * @author wusheng + */ +public class PropagatedTraceId extends DistributedTraceId { + public PropagatedTraceId(String id) { + super(id); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/AbstractTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/AbstractTag.java new file mode 100644 index 000000000000..415cfda013b1 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/AbstractTag.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.tag; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; + +public abstract class AbstractTag { + /** + * The key of this Tag. + */ + protected final String key; + + public AbstractTag(String tagKey) { + this.key = tagKey; + } + + protected abstract void set(AbstractSpan span, T tagValue); + + /** + * @return the key of this tag. + */ + public String key() { + return this.key; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/StringTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/StringTag.java new file mode 100644 index 000000000000..a8b4808b06a0 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/StringTag.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.tag; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; + +/** + * A subclass of {@link AbstractTag}, + * represent a tag with a {@link String} value. + *

+ * Created by wusheng on 2017/2/17. + */ +public class StringTag extends AbstractTag { + public StringTag(String tagKey) { + super(tagKey); + } + + @Override + public void set(AbstractSpan span, String tagValue) { + span.tag(key, tagValue); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java new file mode 100644 index 000000000000..3059cb1b5c7b --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.tag; + +/** + * The span tags are supported by sky-walking engine. + * As default, all tags will be stored, but these ones have particular meanings. + *

+ * Created by wusheng on 2017/2/17. + */ +public final class Tags { + private Tags() { + } + + /** + * URL records the url of the incoming request. + */ + public static final StringTag URL = new StringTag("url"); + + /** + * STATUS_CODE records the http status code of the response. + */ + public static final StringTag STATUS_CODE = new StringTag("status_code"); + + /** + * DB_TYPE records database type, such as sql, redis, cassandra and so on. + */ + public static final StringTag DB_TYPE = new StringTag("db.type"); + + /** + * DB_INSTANCE records database instance name. + */ + public static final StringTag DB_INSTANCE = new StringTag("db.instance"); + + /** + * DB_STATEMENT records the sql statement of the database access. + */ + public static final StringTag DB_STATEMENT = new StringTag("db.statement"); + + /** + * DB_BIND_VARIABLES records the bind variables of sql statement. + */ + public static final StringTag DB_BIND_VARIABLES = new StringTag("db.bind_vars"); + + public static final class HTTP { + public static final StringTag METHOD = new StringTag("http.method"); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java new file mode 100644 index 000000000000..a974f7ca05e5 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +import java.util.Map; +import org.apache.skywalking.apm.network.trace.component.Component; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * The AbstractSpan represents the span's skeleton, which contains all open methods. + * + * @author wusheng + */ +public interface AbstractSpan { + /** + * Set the component id, which defines in {@link ComponentsDefine} + * + * @param component + * @return the span for chaining. + */ + AbstractSpan setComponent(Component component); + + /** + * Only use this method in explicit instrumentation, like opentracing-skywalking-bridge. It it higher recommend + * don't use this for performance consideration. + * + * @param componentName + * @return the span for chaining. + */ + AbstractSpan setComponent(String componentName); + + AbstractSpan setLayer(SpanLayer layer); + + /** + * Set a key:value tag on the Span. + * + * @return this Span instance, for chaining + */ + AbstractSpan tag(String key, String value); + + /** + * Record an exception event of the current walltime timestamp. + * + * @param t any subclass of {@link Throwable}, which occurs in this span. + * @return the Span, for chaining + */ + AbstractSpan log(Throwable t); + + AbstractSpan errorOccurred(); + + /** + * @return true if the actual span is an entry span. + */ + boolean isEntry(); + + /** + * @return true if the actual span is an exit span. + */ + boolean isExit(); + + /** + * Record an event at a specific timestamp. + * + * @param timestamp The explicit timestamp for the log record. + * @param event the events + * @return the Span, for chaining + */ + AbstractSpan log(long timestamp, Map event); + + /** + * Sets the string name for the logical operation this span represents. + * + * @return this Span instance, for chaining + */ + AbstractSpan setOperationName(String operationName); + + /** + * Start a span. + * + * @return this Span instance, for chaining + */ + AbstractSpan start(); + + /** + * Get the id of span + * + * @return id value. + */ + int getSpanId(); + + int getOperationId(); + + String getOperationName(); + + AbstractSpan setOperationId(int operationId); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java similarity index 86% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java index b54e1a742184..cfa4b819e8f1 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java @@ -16,17 +16,35 @@ * */ -package org.skywalking.apm.agent.core.context.trace; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.context.util.ThrowableTransformer; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.proto.SpanType; -import org.skywalking.apm.network.trace.component.Component; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.context.util.ThrowableTransformer; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.SpanType; +import org.apache.skywalking.apm.network.trace.component.Component; /** * The AbstractTracingSpan represents a group of {@link AbstractSpan} implementations, which belongs a real diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/EntrySpan.java similarity index 81% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/EntrySpan.java index 05012521ec9c..c374c7dc1527 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/EntrySpan.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.agent.core.context.trace; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.trace.component.Component; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.trace.component.Component; /** * The EntrySpan represents a service provider point, such as Tomcat server entrance. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/ExitSpan.java similarity index 81% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/ExitSpan.java index 717264db945f..cb9e49f35997 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/ExitSpan.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.agent.core.context.trace; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.trace.component.Component; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.trace.component.Component; /** * The ExitSpan represents a service consumer point, such as Feign, Okhttp client for a Http service. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LocalSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LocalSpan.java new file mode 100644 index 000000000000..6e7d83a7d14a --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LocalSpan.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +/** + * The LocalSpan represents a normal tracing point, such as a local method. + * + * @author wusheng + */ +public class LocalSpan extends AbstractTracingSpan { + + public LocalSpan(int spanId, int parentSpanId, int operationId) { + super(spanId, parentSpanId, operationId); + } + + public LocalSpan(int spanId, int parentSpanId, String operationName) { + super(spanId, parentSpanId, operationName); + } + + @Override + public LocalSpan tag(String key, String value) { + super.tag(key, value); + return this; + } + + @Override + public LocalSpan log(Throwable t) { + super.log(t); + return this; + } + + @Override public boolean isEntry() { + return false; + } + + @Override public boolean isExit() { + return false; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LogDataEntity.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LogDataEntity.java new file mode 100644 index 000000000000..d17ee86bdeea --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/LogDataEntity.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.network.proto.LogMessage; + +/** + * The LogDataEntity represents a collection of {@link KeyValuePair}, + * contains several fields of a logging operation. + * + * @author wusheng + */ +public class LogDataEntity { + private long timestamp = 0; + private List logs; + + private LogDataEntity(long timestamp, List logs) { + this.timestamp = timestamp; + this.logs = logs; + } + + public List getLogs() { + return logs; + } + + public static class Builder { + protected List logs; + + public Builder() { + logs = new LinkedList(); + } + + public Builder add(KeyValuePair... fields) { + for (KeyValuePair field : fields) { + logs.add(field); + } + return this; + } + + public LogDataEntity build(long timestamp) { + return new LogDataEntity(timestamp, logs); + } + } + + public LogMessage transform() { + LogMessage.Builder logMessageBuilder = LogMessage.newBuilder(); + for (KeyValuePair log : logs) { + logMessageBuilder.addData(log.transform()); + } + logMessageBuilder.setTime(timestamp); + return logMessageBuilder.build(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopExitSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopExitSpan.java new file mode 100644 index 000000000000..82244ddee6d8 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopExitSpan.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +public class NoopExitSpan extends NoopSpan implements WithPeerInfo { + + private String peer; + private int peerId; + + public NoopExitSpan(int peerId) { + this.peerId = peerId; + } + + public NoopExitSpan(String peer) { + this.peer = peer; + } + + @Override + public int getPeerId() { + return peerId; + } + + @Override + public String getPeer() { + return peer; + } + + @Override + public boolean isExit() { + return true; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java new file mode 100644 index 000000000000..27e6ac41f6c3 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +import java.util.Map; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.network.trace.component.Component; + +/** + * The NoopSpan represents a span implementation without any actual operation. + * This span implementation is for {@link IgnoredTracerContext}, + * for keeping the memory and gc cost as low as possible. + * + * @author wusheng + */ +public class NoopSpan implements AbstractSpan { + public NoopSpan() { + } + + @Override + public AbstractSpan log(Throwable t) { + return this; + } + + @Override public AbstractSpan errorOccurred() { + return this; + } + + public void finish() { + + } + + @Override public AbstractSpan setComponent(Component component) { + return this; + } + + @Override public AbstractSpan setComponent(String componentName) { + return this; + } + + @Override public AbstractSpan setLayer(SpanLayer layer) { + return this; + } + + @Override + public AbstractSpan tag(String key, String value) { + return this; + } + + @Override public boolean isEntry() { + return false; + } + + @Override public boolean isExit() { + return false; + } + + @Override public AbstractSpan log(long timestamp, Map event) { + return this; + } + + @Override public AbstractSpan setOperationName(String operationName) { + return this; + } + + @Override public AbstractSpan start() { + return this; + } + + @Override public int getSpanId() { + return 0; + } + + @Override public int getOperationId() { + return 0; + } + + @Override public String getOperationName() { + return ""; + } + + @Override public AbstractSpan setOperationId(int operationId) { + return this; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/SpanLayer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/SpanLayer.java new file mode 100644 index 000000000000..3ab7ea0cd4d7 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/SpanLayer.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +/** + * @author wusheng + */ +public enum SpanLayer { + DB(1), + RPC_FRAMEWORK(2), + HTTP(3), + MQ(4); + + private int code; + + SpanLayer(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + + public static void asDB(AbstractSpan span) { + span.setLayer(SpanLayer.DB); + } + + public static void asRPCFramework(AbstractSpan span) { + span.setLayer(SpanLayer.RPC_FRAMEWORK); + } + + public static void asHttp(AbstractSpan span) { + span.setLayer(SpanLayer.HTTP); + } + + public static void asMQ(AbstractSpan span) { + span.setLayer(SpanLayer.MQ); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java new file mode 100644 index 000000000000..70efe9073e07 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryManager; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.dictionary.PossibleFound; + +/** + * The StackBasedTracingSpan represents a span with an inside stack construction. + * + * This kind of span can start and finish multi times in a stack-like invoke line. + * + * @author wusheng + */ +public abstract class StackBasedTracingSpan extends AbstractTracingSpan { + protected int stackDepth; + + protected StackBasedTracingSpan(int spanId, int parentSpanId, String operationName) { + super(spanId, parentSpanId, operationName); + this.stackDepth = 0; + } + + protected StackBasedTracingSpan(int spanId, int parentSpanId, int operationId) { + super(spanId, parentSpanId, operationId); + this.stackDepth = 0; + } + + @Override + public boolean finish(TraceSegment owner) { + if (--stackDepth == 0) { + if (this.operationId == DictionaryUtil.nullValue()) { + this.operationId = (Integer)DictionaryManager.findOperationNameCodeSection() + .findOrPrepare4Register(owner.getApplicationId(), operationName) + .doInCondition( + new PossibleFound.FoundAndObtain() { + @Override public Object doProcess(int value) { + return value; + } + }, + new PossibleFound.NotFoundAndObtain() { + @Override public Object doProcess() { + return DictionaryUtil.nullValue(); + } + } + ); + } + return super.finish(owner); + } else { + return false; + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegment.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegment.java new file mode 100644 index 000000000000..fdff2d03313d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegment.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceIds; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId; +import org.apache.skywalking.apm.agent.core.context.ids.GlobalIdGenerator; +import org.apache.skywalking.apm.agent.core.context.ids.NewDistributedTraceId; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +/** + * {@link TraceSegment} is a segment or fragment of the distributed trace. {@see https://github.com/opentracing/specification/blob/master/specification.md#the-opentracing-data-model} + * A {@link TraceSegment} means the segment, which exists in current {@link Thread}. And the distributed trace is formed + * by multi {@link TraceSegment}s, because the distributed trace crosses multi-processes, multi-threads.

+ * + * @author wusheng + */ +public class TraceSegment { + /** + * The id of this trace segment. Every segment has its unique-global-id. + */ + private ID traceSegmentId; + + /** + * The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one + * element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment, + * we use this {@link #refs} to link them. + * + * This field will not be serialized. Keeping this field is only for quick accessing. + */ + private List refs; + + /** + * The spans belong to this trace segment. They all have finished. All active spans are hold and controlled by + * "skywalking-api" module. + */ + private List spans; + + /** + * The relatedGlobalTraces represent a set of all related trace. Most time it contains only one + * element, because only one parent {@link TraceSegment} exists, but, in batch scenario, the num becomes greater + * than 1, also meaning multi-parents {@link TraceSegment}.

The difference between + * relatedGlobalTraces and {@link #refs} is: {@link #refs} targets this {@link TraceSegment}'s direct + * parent,

and

relatedGlobalTraces targets this {@link TraceSegment}'s related call chain, a + * call chain contains multi {@link TraceSegment}s, only using {@link #refs} is not enough for analysis and ui. + */ + private DistributedTraceIds relatedGlobalTraces; + + private boolean ignore = false; + + private boolean isSizeLimited = false; + + /** + * Create a default/empty trace segment, with current time as start time, and generate a new segment id. + */ + public TraceSegment() { + this.traceSegmentId = GlobalIdGenerator.generate(); + this.spans = new LinkedList(); + this.relatedGlobalTraces = new DistributedTraceIds(); + this.relatedGlobalTraces.append(new NewDistributedTraceId()); + } + + /** + * Establish the link between this segment and its parents. + * + * @param refSegment {@link TraceSegmentRef} + */ + public void ref(TraceSegmentRef refSegment) { + if (refs == null) { + refs = new LinkedList(); + } + if (!refs.contains(refSegment)) { + refs.add(refSegment); + } + } + + /** + * Establish the line between this segment and all relative global trace ids. + */ + public void relatedGlobalTraces(DistributedTraceId distributedTraceId) { + relatedGlobalTraces.append(distributedTraceId); + } + + /** + * After {@link AbstractSpan} is finished, as be controller by "skywalking-api" module, notify the {@link + * TraceSegment} to archive it. + * + * @param finishedSpan + */ + public void archive(AbstractTracingSpan finishedSpan) { + spans.add(finishedSpan); + } + + /** + * Finish this {@link TraceSegment}.

return this, for chaining + */ + public TraceSegment finish(boolean isSizeLimited) { + this.isSizeLimited = isSizeLimited; + return this; + } + + public ID getTraceSegmentId() { + return traceSegmentId; + } + + public int getApplicationId() { + return RemoteDownstreamConfig.Agent.APPLICATION_ID; + } + + public boolean hasRef() { + return !(refs == null || refs.size() == 0); + } + + public List getRefs() { + return refs; + } + + public List getRelatedGlobalTraces() { + return relatedGlobalTraces.getRelatedGlobalTraces(); + } + + public boolean isSingleSpanSegment() { + return this.spans != null && this.spans.size() == 1; + } + + public boolean isIgnore() { + return ignore; + } + + public void setIgnore(boolean ignore) { + this.ignore = ignore; + } + + /** + * This is a high CPU cost method, only called when sending to collector or test cases. + * + * @return the segment as GRPC service parameter + */ + public UpstreamSegment transform() { + UpstreamSegment.Builder upstreamBuilder = UpstreamSegment.newBuilder(); + for (DistributedTraceId distributedTraceId : getRelatedGlobalTraces()) { + upstreamBuilder = upstreamBuilder.addGlobalTraceIds(distributedTraceId.toUniqueId()); + } + TraceSegmentObject.Builder traceSegmentBuilder = TraceSegmentObject.newBuilder(); + /** + * Trace Segment + */ + traceSegmentBuilder.setTraceSegmentId(this.traceSegmentId.transform()); + // Don't serialize TraceSegmentReference + + // SpanObject + for (AbstractTracingSpan span : this.spans) { + traceSegmentBuilder.addSpans(span.transform()); + } + traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID); + traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID); + traceSegmentBuilder.setIsSizeLimited(this.isSizeLimited); + + upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString()); + return upstreamBuilder.build(); + } + + @Override + public String toString() { + return "TraceSegment{" + + "traceSegmentId='" + traceSegmentId + '\'' + + ", refs=" + refs + + ", spans=" + spans + + ", relatedGlobalTraces=" + relatedGlobalTraces + + '}'; + } + + public int getApplicationInstanceId() { + return RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java similarity index 82% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java index aeab92fb7ad7..3b9d2151fd6f 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java @@ -16,15 +16,33 @@ * */ -package org.skywalking.apm.agent.core.context.trace; - -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.network.proto.RefType; -import org.skywalking.apm.network.proto.TraceSegmentReference; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.network.proto.RefType; +import org.apache.skywalking.apm.network.proto.TraceSegmentReference; /** * {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment}, diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/WithPeerInfo.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/WithPeerInfo.java new file mode 100644 index 000000000000..44e8fc410095 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/WithPeerInfo.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.trace; + +/** + * @author wusheng + */ +public interface WithPeerInfo { + int getPeerId(); + + String getPeer(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/KeyValuePair.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/KeyValuePair.java new file mode 100644 index 000000000000..90695187ac5d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/KeyValuePair.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +import org.apache.skywalking.apm.network.proto.KeyWithStringValue; + +/** + * The KeyValuePair represents a object which contains a string key and a string value. + * + * @author wusheng + */ +public class KeyValuePair { + private String key; + private String value; + + public KeyValuePair(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + + public KeyWithStringValue transform() { + KeyWithStringValue.Builder keyValueBuilder = KeyWithStringValue.newBuilder(); + keyValueBuilder.setKey(key); + if (value != null) { + keyValueBuilder.setValue(value); + } + return keyValueBuilder.build(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java new file mode 100644 index 000000000000..bf96e512b1ce --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +/** + * {@link ThrowableTransformer} is responsible for transferring stack trace of throwable. + */ +public enum ThrowableTransformer { + INSTANCE; + + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + public String convert2String(Throwable throwable, final int maxLength) { + final StringBuilder stackMessage = new StringBuilder(); + Throwable causeException = throwable; + while (causeException != null) { + stackMessage.append(printExceptionInfo(causeException)); + + boolean overMaxLength = printStackElement(throwable.getStackTrace(), new AppendListener() { + public void append(String value) { + stackMessage.append(value); + } + + public boolean overMaxLength() { + return stackMessage.length() > maxLength; + } + }); + + if (overMaxLength) { + break; + } + + causeException = throwable.getCause(); + } + + return stackMessage.toString(); + } + + private String printExceptionInfo(Throwable causeException) { + return causeException.toString() + LINE_SEPARATOR; + } + + private boolean printStackElement(StackTraceElement[] stackTrace, AppendListener printListener) { + for (StackTraceElement traceElement : stackTrace) { + printListener.append("at " + traceElement + LINE_SEPARATOR); + if (printListener.overMaxLength()) { + return true; + } + } + return false; + } + + private interface AppendListener { + void append(String value); + + boolean overMaxLength(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java new file mode 100644 index 000000000000..811c9321a782 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; + +import io.netty.util.internal.ConcurrentSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.skywalking.apm.network.proto.Application; +import org.apache.skywalking.apm.network.proto.ApplicationMapping; +import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; +import org.apache.skywalking.apm.network.proto.KeyWithIntegerValue; + +import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.APPLICATION_CODE_BUFFER_SIZE; + +/** + * Map of application id to application code, which is from the collector side. + * + * @author wusheng + */ +public enum ApplicationDictionary { + INSTANCE; + private Map applicationDictionary = new ConcurrentHashMap(); + private Set unRegisterApplications = new ConcurrentSet(); + + public PossibleFound find(String applicationCode) { + Integer applicationId = applicationDictionary.get(applicationCode); + if (applicationId != null) { + return new Found(applicationId); + } else { + if (applicationDictionary.size() + unRegisterApplications.size() < APPLICATION_CODE_BUFFER_SIZE) { + unRegisterApplications.add(applicationCode); + } + return new NotFound(); + } + } + + public void syncRemoteDictionary( + ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub applicationRegisterServiceBlockingStub) { + if (unRegisterApplications.size() > 0) { + ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.register( + Application.newBuilder().addAllApplicationCode(unRegisterApplications).build()); + if (applicationMapping.getApplicationCount() > 0) { + for (KeyWithIntegerValue keyWithIntegerValue : applicationMapping.getApplicationList()) { + unRegisterApplications.remove(keyWithIntegerValue.getKey()); + applicationDictionary.put(keyWithIntegerValue.getKey(), keyWithIntegerValue.getValue()); + } + } + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryManager.java new file mode 100644 index 000000000000..8ac92ac48a4f --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryManager.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class DictionaryManager { + /** + * @return {@link ApplicationDictionary} to find application id for application code and network address. + */ + public static ApplicationDictionary findApplicationCodeSection() { + return ApplicationDictionary.INSTANCE; + } + + /** + * @return {@link OperationNameDictionary} to find service id. + */ + public static OperationNameDictionary findOperationNameCodeSection() { + return OperationNameDictionary.INSTANCE; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java new file mode 100644 index 000000000000..6c1b903bab36 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class DictionaryUtil { + public static int nullValue() { + return 0; + } + + public static boolean isNull(int id) { + return id == nullValue(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/Found.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/Found.java new file mode 100644 index 000000000000..a4c7c5e46988 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/Found.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class Found extends PossibleFound { + public Found(int value) { + super(value); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/NotFound.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/NotFound.java new file mode 100644 index 000000000000..145268ac70db --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/NotFound.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class NotFound extends PossibleFound { + public NotFound() { + super(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java similarity index 78% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java index e74a92e8be3d..1d3cbe224364 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java @@ -16,19 +16,37 @@ * */ -package org.skywalking.apm.agent.core.dictionary; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; import io.netty.util.internal.ConcurrentSet; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.skywalking.apm.network.proto.ServiceNameCollection; -import org.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; -import org.skywalking.apm.network.proto.ServiceNameElement; -import org.skywalking.apm.network.proto.ServiceNameMappingCollection; -import org.skywalking.apm.network.proto.ServiceNameMappingElement; +import org.apache.skywalking.apm.network.proto.ServiceNameCollection; +import org.apache.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; +import org.apache.skywalking.apm.network.proto.ServiceNameElement; +import org.apache.skywalking.apm.network.proto.ServiceNameMappingCollection; +import org.apache.skywalking.apm.network.proto.ServiceNameMappingElement; -import static org.skywalking.apm.agent.core.conf.Config.Dictionary.OPERATION_NAME_BUFFER_SIZE; +import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.OPERATION_NAME_BUFFER_SIZE; /** * @author wusheng diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/PossibleFound.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/PossibleFound.java new file mode 100644 index 000000000000..96622ca7bfd9 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/PossibleFound.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.dictionary; + +/** + * The PossibleFound represents a value, which may needEnhance or not. + * + * @author wusheng + */ +public abstract class PossibleFound { + private boolean found; + private int value; + + PossibleFound(int value) { + this.found = true; + this.value = value; + } + + PossibleFound() { + this.found = false; + } + + public void doInCondition(Found condition1, NotFound condition2) { + if (found) { + condition1.doProcess(value); + } else { + condition2.doProcess(); + } + } + + public Object doInCondition(FoundAndObtain condition1, NotFoundAndObtain condition2) { + if (found) { + return condition1.doProcess(value); + } else { + return condition2.doProcess(); + } + } + + public interface Found { + void doProcess(int value); + } + + public interface NotFound { + void doProcess(); + } + + public interface FoundAndObtain { + Object doProcess(int value); + } + + public interface NotFoundAndObtain { + Object doProcess(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java new file mode 100644 index 000000000000..7d5fcaa3e34f --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm; + +import io.grpc.ManagedChannel; +import java.util.LinkedList; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.jvm.cpu.CPUProvider; +import org.apache.skywalking.apm.agent.core.jvm.gc.GCProvider; +import org.apache.skywalking.apm.agent.core.jvm.memory.MemoryProvider; +import org.apache.skywalking.apm.agent.core.jvm.memorypool.MemoryPoolProvider; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.remote.GRPCChannelListener; +import org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager; +import org.apache.skywalking.apm.agent.core.remote.GRPCChannelStatus; +import org.apache.skywalking.apm.network.proto.JVMMetric; +import org.apache.skywalking.apm.network.proto.JVMMetrics; +import org.apache.skywalking.apm.network.proto.JVMMetricsServiceGrpc; + +/** + * The JVMService represents a timer, + * which collectors JVM cpu, memory, memorypool and gc info, + * and send the collected info to Collector through the channel provided by {@link GRPCChannelManager} + * + * @author wusheng + */ +public class JVMService implements BootService, Runnable { + private static final ILog logger = LogManager.getLogger(JVMService.class); + private LinkedBlockingQueue queue; + private volatile ScheduledFuture collectMetricFuture; + private volatile ScheduledFuture sendMetricFuture; + private Sender sender; + @Override + public void beforeBoot() throws Throwable { + queue = new LinkedBlockingQueue(Config.Jvm.BUFFER_SIZE); + sender = new Sender(); + ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(sender); + } + + @Override + public void boot() throws Throwable { + collectMetricFuture = Executors + .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-produce")) + .scheduleAtFixedRate(this, 0, 1, TimeUnit.SECONDS); + sendMetricFuture = Executors + .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-consume")) + .scheduleAtFixedRate(sender, 0, 1, TimeUnit.SECONDS); + } + + @Override + public void afterBoot() throws Throwable { + + } + + @Override + public void shutdown() throws Throwable { + collectMetricFuture.cancel(true); + sendMetricFuture.cancel(true); + } + + @Override + public void run() { + if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue() + && RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue() + ) { + long currentTimeMillis = System.currentTimeMillis(); + try { + JVMMetric.Builder jvmBuilder = JVMMetric.newBuilder(); + jvmBuilder.setTime(currentTimeMillis); + jvmBuilder.setCpu(CPUProvider.INSTANCE.getCpuMetric()); + jvmBuilder.addAllMemory(MemoryProvider.INSTANCE.getMemoryMetricList()); + jvmBuilder.addAllMemoryPool(MemoryPoolProvider.INSTANCE.getMemoryPoolMetricList()); + jvmBuilder.addAllGc(GCProvider.INSTANCE.getGCList()); + + JVMMetric jvmMetric = jvmBuilder.build(); + if (!queue.offer(jvmMetric)) { + queue.poll(); + queue.offer(jvmMetric); + } + } catch (Exception e) { + logger.error(e, "Collect JVM info fail."); + } + } + } + + private class Sender implements Runnable, GRPCChannelListener { + private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT; + private volatile JVMMetricsServiceGrpc.JVMMetricsServiceBlockingStub stub = null; + + @Override + public void run() { + if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue() + && RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue() + ) { + if (status == GRPCChannelStatus.CONNECTED) { + try { + JVMMetrics.Builder builder = JVMMetrics.newBuilder(); + LinkedList buffer = new LinkedList(); + queue.drainTo(buffer); + if (buffer.size() > 0) { + builder.addAllMetrics(buffer); + builder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID); + stub.collect(builder.build()); + } + } catch (Throwable t) { + logger.error(t, "send JVM metrics to Collector fail."); + } + } + } + } + + @Override + public void statusChanged(GRPCChannelStatus status) { + if (GRPCChannelStatus.CONNECTED.equals(status)) { + ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel(); + stub = JVMMetricsServiceGrpc.newBlockingStub(channel); + } + this.status = status; + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java new file mode 100644 index 000000000000..f0c671070385 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.cpu; + +import org.apache.skywalking.apm.network.proto.CPU; + +/** + * @author wusheng + */ +public abstract class CPUMetricAccessor { + private long lastCPUTimeNs; + private long lastSampleTimeNs; + private final int cpuCoreNum; + + public CPUMetricAccessor(int cpuCoreNum) { + this.cpuCoreNum = cpuCoreNum; + } + + protected void init() { + lastCPUTimeNs = this.getCpuTime(); + this.lastSampleTimeNs = System.nanoTime(); + } + + protected abstract long getCpuTime(); + + public CPU getCPUMetric() { + long cpuTime = this.getCpuTime(); + long cpuCost = cpuTime - lastCPUTimeNs; + long now = System.nanoTime(); + + CPU.Builder cpuBuilder = CPU.newBuilder(); + return cpuBuilder.setUsagePercent(cpuCost * 1.0d / ((now - lastSampleTimeNs) * cpuCoreNum)).build(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java new file mode 100644 index 000000000000..571c1686f92d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.cpu; + +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.os.ProcessorUtil; +import org.apache.skywalking.apm.network.proto.CPU; + +/** + * @author wusheng + */ +public enum CPUProvider { + INSTANCE; + private CPUMetricAccessor cpuMetricAccessor; + + CPUProvider() { + int processorNum = ProcessorUtil.getNumberOfProcessors(); + try { + this.cpuMetricAccessor = + (CPUMetricAccessor)CPUProvider.class.getClassLoader().loadClass("org.apache.skywalking.apm.agent.core.jvm.cpu.SunCpuAccessor") + .getConstructor(int.class).newInstance(processorNum); + } catch (Exception e) { + this.cpuMetricAccessor = new NoSupportedCPUAccessor(processorNum); + ILog logger = LogManager.getLogger(CPUProvider.class); + logger.error(e, "Only support accessing CPU metric in SUN JVM platform."); + } + } + + public CPU getCpuMetric() { + return cpuMetricAccessor.getCPUMetric(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java new file mode 100644 index 000000000000..814105ba0da1 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.cpu; + +/** + * @author wusheng + */ +public class NoSupportedCPUAccessor extends CPUMetricAccessor { + public NoSupportedCPUAccessor(int cpuCoreNum) { + super(cpuCoreNum); + } + + @Override + protected long getCpuTime() { + return 0; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java new file mode 100644 index 000000000000..790213362e38 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.cpu; + +import com.sun.management.OperatingSystemMXBean; +import java.lang.management.ManagementFactory; + +/** + * @author wusheng + */ +public class SunCpuAccessor extends CPUMetricAccessor { + private final OperatingSystemMXBean osMBean; + + public SunCpuAccessor(int cpuCoreNum) { + super(cpuCoreNum); + this.osMBean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); + this.init(); + } + + @Override + protected long getCpuTime() { + return osMBean.getProcessCpuTime(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java new file mode 100644 index 000000000000..d62f3e20d156 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.lang.management.GarbageCollectorMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class CMSGCModule extends GCModule { + public CMSGCModule(List beans) { + super(beans); + } + + @Override protected String getOldGCName() { + return "ConcurrentMarkSweep"; + } + + @Override protected String getNewGCName() { + return "ParNew"; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/G1GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/G1GCModule.java new file mode 100644 index 000000000000..da4961ed556a --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/G1GCModule.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.lang.management.GarbageCollectorMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class G1GCModule extends GCModule { + public G1GCModule(List beans) { + super(beans); + } + + @Override protected String getOldGCName() { + return "G1 Old Generation"; + } + + @Override protected String getNewGCName() { + return "G1 Young Generation"; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java new file mode 100644 index 000000000000..fe08c30ad98e --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.util.List; +import org.apache.skywalking.apm.network.proto.GC; + +/** + * @author wusheng + */ +public interface GCMetricAccessor { + List getGCList(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java new file mode 100644 index 000000000000..a5a0eb2be4bf --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.lang.management.GarbageCollectorMXBean; +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.network.proto.GC; +import org.apache.skywalking.apm.network.proto.GCPhrase; + +/** + * @author wusheng + */ +public abstract class GCModule implements GCMetricAccessor { + private List beans; + + public GCModule(List beans) { + this.beans = beans; + } + + @Override + public List getGCList() { + List gcList = new LinkedList(); + for (GarbageCollectorMXBean bean : beans) { + String name = bean.getName(); + GCPhrase phrase; + if (name.equals(getNewGCName())) { + phrase = GCPhrase.NEW; + } else if (name.equals(getOldGCName())) { + phrase = GCPhrase.OLD; + } else { + continue; + } + + gcList.add( + GC.newBuilder().setPhrase(phrase) + .setCount(bean.getCollectionCount()) + .setTime(bean.getCollectionTime()) + .build() + ); + } + + return gcList; + } + + protected abstract String getOldGCName(); + + protected abstract String getNewGCName(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCProvider.java new file mode 100644 index 000000000000..3ac9fc8d28db --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCProvider.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.lang.management.GarbageCollectorMXBean; +import java.lang.management.ManagementFactory; +import java.util.List; +import org.apache.skywalking.apm.network.proto.GC; + +/** + * @author wusheng + */ +public enum GCProvider { + INSTANCE; + + private GCMetricAccessor metricAccessor; + private List beans; + + GCProvider() { + beans = ManagementFactory.getGarbageCollectorMXBeans(); + for (GarbageCollectorMXBean bean : beans) { + String name = bean.getName(); + GCMetricAccessor accessor = findByBeanName(name); + if (accessor != null) { + metricAccessor = accessor; + break; + } + } + + if (metricAccessor == null) { + this.metricAccessor = new UnknowGC(); + } + } + + public List getGCList() { + return metricAccessor.getGCList(); + } + + private GCMetricAccessor findByBeanName(String name) { + if (name.indexOf("PS") > -1) { + //Parallel (Old) collector ( -XX:+UseParallelOldGC ) + return new ParallelGCModule(beans); + } else if (name.indexOf("ConcurrentMarkSweep") > -1) { + // CMS collector ( -XX:+UseConcMarkSweepGC ) + return new CMSGCModule(beans); + } else if (name.indexOf("G1") > -1) { + // G1 collector ( -XX:+UseG1GC ) + return new G1GCModule(beans); + } else if (name.equals("MarkSweepCompact")) { + // Serial collector ( -XX:+UseSerialGC ) + return new SerialGCModule(beans); + } else { + // Unknown + return null; + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java new file mode 100644 index 000000000000..b2a701bd7877 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.lang.management.GarbageCollectorMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class ParallelGCModule extends GCModule { + public ParallelGCModule(List beans) { + super(beans); + } + + @Override protected String getOldGCName() { + return "PS MarkSweep"; + } + + @Override protected String getNewGCName() { + return "PS Scavenge"; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java new file mode 100644 index 000000000000..c7026fb6d3cc --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.lang.management.GarbageCollectorMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class SerialGCModule extends GCModule { + public SerialGCModule(List beans) { + super(beans); + } + + @Override protected String getOldGCName() { + return "MarkSweepCompact"; + } + + @Override protected String getNewGCName() { + return "Copy"; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/UnknowGC.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/UnknowGC.java new file mode 100644 index 000000000000..09fbbccb102a --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/UnknowGC.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.gc; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.network.proto.GC; +import org.apache.skywalking.apm.network.proto.GCPhrase; + +/** + * @author wusheng + */ +public class UnknowGC implements GCMetricAccessor { + @Override + public List getGCList() { + List gcList = new LinkedList(); + gcList.add(GC.newBuilder().setPhrase(GCPhrase.NEW).build()); + gcList.add(GC.newBuilder().setPhrase(GCPhrase.OLD).build()); + return gcList; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java new file mode 100644 index 000000000000..a2438f5046ec --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memory; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.MemoryUsage; +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.network.proto.Memory; + +/** + * @author wusheng + */ +public enum MemoryProvider { + INSTANCE; + private final MemoryMXBean memoryMXBean; + + MemoryProvider() { + this.memoryMXBean = ManagementFactory.getMemoryMXBean(); + } + + public List getMemoryMetricList() { + List memoryList = new LinkedList(); + + MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); + Memory.Builder heapMemoryBuilder = Memory.newBuilder(); + heapMemoryBuilder.setIsHeap(true); + heapMemoryBuilder.setInit(heapMemoryUsage.getInit()); + heapMemoryBuilder.setUsed(heapMemoryUsage.getUsed()); + heapMemoryBuilder.setCommitted(heapMemoryUsage.getCommitted()); + heapMemoryBuilder.setMax(heapMemoryUsage.getMax()); + memoryList.add(heapMemoryBuilder.build()); + + MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); + Memory.Builder nonHeapMemoryBuilder = Memory.newBuilder(); + nonHeapMemoryBuilder.setIsHeap(false); + nonHeapMemoryBuilder.setInit(nonHeapMemoryUsage.getInit()); + nonHeapMemoryBuilder.setUsed(nonHeapMemoryUsage.getUsed()); + nonHeapMemoryBuilder.setCommitted(nonHeapMemoryUsage.getCommitted()); + nonHeapMemoryBuilder.setMax(nonHeapMemoryUsage.getMax()); + memoryList.add(nonHeapMemoryBuilder.build()); + + return memoryList; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java new file mode 100644 index 000000000000..855ac9890de2 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.lang.management.MemoryPoolMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class CMSCollectorModule extends MemoryPoolModule { + public CMSCollectorModule(List beans) { + super(beans); + } + + @Override protected String[] getPermNames() { + return new String[] {"CMS Perm Gen", "Compressed Class Space"}; + } + + @Override protected String[] getCodeCacheNames() { + return new String[] {"Code Cache"}; + } + + @Override protected String[] getEdenNames() { + return new String[] {"Par Eden Space"}; + } + + @Override protected String[] getOldNames() { + return new String[] {"CMS Old Gen"}; + } + + @Override protected String[] getSurvivorNames() { + return new String[] {"Par Survivor Space"}; + } + + @Override protected String[] getMetaspaceNames() { + return new String[] {"Metaspace"}; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java new file mode 100644 index 000000000000..f8a60ad3a864 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.lang.management.MemoryPoolMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class G1CollectorModule extends MemoryPoolModule { + public G1CollectorModule(List beans) { + super(beans); + } + + @Override protected String[] getPermNames() { + return new String[] {"G1 Perm Gen", "Compressed Class Space"}; + } + + @Override protected String[] getCodeCacheNames() { + return new String[] {"Code Cache"}; + } + + @Override protected String[] getEdenNames() { + return new String[] {"G1 Eden Space"}; + } + + @Override protected String[] getOldNames() { + return new String[] {"G1 Old Gen"}; + } + + @Override protected String[] getSurvivorNames() { + return new String[] {"G1 Survivor Space"}; + } + + @Override protected String[] getMetaspaceNames() { + return new String[] {"Metaspace"}; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java new file mode 100644 index 000000000000..3287268f6c6c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.util.List; +import org.apache.skywalking.apm.network.proto.MemoryPool; + +/** + * @author wusheng + */ +public interface MemoryPoolMetricAccessor { + List getMemoryPoolMetricList(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java similarity index 75% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java index 123536d93f46..63fc86f0c8ba 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.agent.core.jvm.memorypool; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.network.proto.MemoryPool; -import org.skywalking.apm.network.proto.PoolType; +import org.apache.skywalking.apm.network.proto.MemoryPool; +import org.apache.skywalking.apm.network.proto.PoolType; /** * @author wusheng diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java new file mode 100644 index 000000000000..f05db4690306 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryPoolMXBean; +import java.util.List; +import org.apache.skywalking.apm.network.proto.MemoryPool; + +/** + * @author wusheng + */ +public enum MemoryPoolProvider { + INSTANCE; + + private MemoryPoolMetricAccessor metricAccessor; + private List beans; + + MemoryPoolProvider() { + beans = ManagementFactory.getMemoryPoolMXBeans(); + for (MemoryPoolMXBean bean : beans) { + String name = bean.getName(); + MemoryPoolMetricAccessor accessor = findByBeanName(name); + if (accessor != null) { + metricAccessor = accessor; + break; + } + } + if (metricAccessor == null) { + metricAccessor = new UnknownMemoryPool(); + } + } + + public List getMemoryPoolMetricList() { + return metricAccessor.getMemoryPoolMetricList(); + } + + private MemoryPoolMetricAccessor findByBeanName(String name) { + if (name.indexOf("PS") > -1) { + //Parallel (Old) collector ( -XX:+UseParallelOldGC ) + return new ParallelCollectorModule(beans); + } else if (name.indexOf("CMS") > -1) { + // CMS collector ( -XX:+UseConcMarkSweepGC ) + return new CMSCollectorModule(beans); + } else if (name.indexOf("G1") > -1) { + // G1 collector ( -XX:+UseG1GC ) + return new G1CollectorModule(beans); + } else if (name.equals("Survivor Space")) { + // Serial collector ( -XX:+UseSerialGC ) + return new SerialCollectorModule(beans); + } else { + // Unknown + return null; + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java new file mode 100644 index 000000000000..527de961a22f --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.lang.management.MemoryPoolMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class ParallelCollectorModule extends MemoryPoolModule { + + public ParallelCollectorModule(List beans) { + super(beans); + } + + @Override protected String[] getPermNames() { + return new String[] {"PS Perm Gen", "Compressed Class Space"}; + } + + @Override protected String[] getCodeCacheNames() { + return new String[] {"Code Cache"}; + } + + @Override protected String[] getEdenNames() { + return new String[] {"PS Eden Space"}; + } + + @Override protected String[] getOldNames() { + return new String[] {"PS Old Gen"}; + } + + @Override protected String[] getSurvivorNames() { + return new String[] {"PS Survivor Space"}; + } + + @Override protected String[] getMetaspaceNames() { + return new String[] {"Metaspace"}; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java new file mode 100644 index 000000000000..6ba6092e99b4 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.lang.management.MemoryPoolMXBean; +import java.util.List; + +/** + * @author wusheng + */ +public class SerialCollectorModule extends MemoryPoolModule { + public SerialCollectorModule(List beans) { + super(beans); + } + + @Override protected String[] getPermNames() { + return new String[] {"Perm Gen", "Compressed Class Space"}; + } + + @Override protected String[] getCodeCacheNames() { + return new String[] {"Code Cache"}; + } + + @Override protected String[] getEdenNames() { + return new String[] {"Eden Space"}; + } + + @Override protected String[] getOldNames() { + return new String[] {"Tenured Gen"}; + } + + @Override protected String[] getSurvivorNames() { + return new String[] {"Survivor Space"}; + } + + @Override protected String[] getMetaspaceNames() { + return new String[] {"Metaspace"}; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java new file mode 100644 index 000000000000..ef0c172c1afe --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.jvm.memorypool; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.network.proto.MemoryPool; +import org.apache.skywalking.apm.network.proto.PoolType; + +/** + * @author wusheng + */ +public class UnknownMemoryPool implements MemoryPoolMetricAccessor { + @Override + public List getMemoryPoolMetricList() { + List poolList = new LinkedList(); + poolList.add(MemoryPool.newBuilder().setType(PoolType.CODE_CACHE_USAGE).build()); + poolList.add(MemoryPool.newBuilder().setType(PoolType.NEWGEN_USAGE).build()); + poolList.add(MemoryPool.newBuilder().setType(PoolType.OLDGEN_USAGE).build()); + poolList.add(MemoryPool.newBuilder().setType(PoolType.SURVIVOR_USAGE).build()); + poolList.add(MemoryPool.newBuilder().setType(PoolType.PERMGEN_USAGE).build()); + poolList.add(MemoryPool.newBuilder().setType(PoolType.METASPACE_USAGE).build()); + return new LinkedList(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/ILog.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/ILog.java new file mode 100644 index 000000000000..196cc06f078a --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/ILog.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.api; + +/** + * The Log interface. + * It's very easy to understand, like any other log-component. + * Do just like log4j or log4j2 does. + *

+ * Created by xin on 2016/11/10. + */ +public interface ILog { + void info(String format); + + void info(String format, Object... arguments); + + void warn(String format, Object... arguments); + + void error(String format, Throwable e); + + void error(Throwable e, String format, Object... arguments); + + boolean isDebugEnable(); + + boolean isInfoEnable(); + + boolean isWarnEnable(); + + boolean isErrorEnable(); + + void debug(String format); + + void debug(String format, Object... arguments); + + void error(String format); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogManager.java new file mode 100644 index 000000000000..8a878823b3d4 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogManager.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.api; + +import org.apache.skywalking.apm.agent.core.logging.core.EasyLogResolver; + +/** + * LogManager is the {@link LogResolver} implementation manager. By using {@link LogResolver}, {@link + * LogManager#getLogger(Class)} returns a {@link ILog} implementation. This module use this class as the main entrance, + * and block the implementation detail about log-component. In different modules, like server or sniffer, it will use + * different implementations.

If no {@link LogResolver} is registered, return {@link NoopLogger#INSTANCE} to avoid + * {@link NullPointerException}. If {@link LogManager#setLogResolver(LogResolver)} is called twice, the second will + * override the first without any warning or exception.

Created by xin on 2016/11/10. + */ +public class LogManager { + private static LogResolver RESOLVER = new EasyLogResolver(); + + public static void setLogResolver(LogResolver resolver) { + LogManager.RESOLVER = resolver; + } + + public static ILog getLogger(Class clazz) { + if (RESOLVER == null) { + return NoopLogger.INSTANCE; + } + return LogManager.RESOLVER.getLogger(clazz); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogResolver.java new file mode 100644 index 000000000000..ef41d5a642e5 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/LogResolver.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.api; + +/** + * {@link LogResolver} just do only one thing: return the {@link ILog} implementation. + *

+ * Created by xin on 2016/11/10. + */ +public interface LogResolver { + /** + * @param clazz, the class is showed in log message. + * @return {@link ILog} implementation. + */ + ILog getLogger(Class clazz); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/NoopLogger.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/NoopLogger.java new file mode 100644 index 000000000000..d6f1d4ae6bc6 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/api/NoopLogger.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.api; + +/** + * No operation logger implementation. + * Just implement {@link ILog} interface, but do nothing. + *

+ * Created by xin on 2016/11/10. + */ +public enum NoopLogger implements ILog { + INSTANCE { + + }; + + @Override + public void info(String message) { + + } + + @Override + public void info(String format, Object... arguments) { + + } + + @Override + public void warn(String format, Object... arguments) { + + } + + @Override + public void error(String format, Throwable e) { + + } + + @Override + public boolean isDebugEnable() { + return false; + } + + @Override + public boolean isInfoEnable() { + return false; + } + + @Override + public boolean isWarnEnable() { + return false; + } + + @Override + public boolean isErrorEnable() { + return false; + } + + @Override + public void debug(String format) { + + } + + @Override + public void debug(String format, Object... arguments) { + + } + + @Override + public void error(String format) { + + } + + @Override + public void error(Throwable e, String format, Object... arguments) { + + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolver.java new file mode 100644 index 000000000000..7ecdf8f3d609 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolver.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogResolver; + +/** + * Created by wusheng on 2016/11/26. + */ +public class EasyLogResolver implements LogResolver { + @Override + public ILog getLogger(Class clazz) { + return new EasyLogger(clazz); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogger.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogger.java similarity index 80% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogger.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogger.java index 2293bff2230b..599f6149b2cf 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogger.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogger.java @@ -16,17 +16,35 @@ * */ -package org.skywalking.apm.agent.core.logging.core; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.Constants; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.conf.Constants; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.util.StringUtil; /** * The EasyLogger is a simple implementation of {@link ILog}. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/FileWriter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java similarity index 85% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/FileWriter.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java index a0a8739c2b34..3ab84232a074 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/FileWriter.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.logging.core; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; import com.lmax.disruptor.EventFactory; import com.lmax.disruptor.EventHandler; @@ -30,8 +48,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.Callable; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.Constants; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.conf.Constants; /** * The FileWriter support async file output, by using a queue as buffer. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/IWriter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/IWriter.java new file mode 100644 index 000000000000..8e92501e7cb9 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/IWriter.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +public interface IWriter { + void write(String message); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogLevel.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogLevel.java new file mode 100644 index 000000000000..76a6781a74ce --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogLevel.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +/** + * Created by xin on 2016/12/7. + */ +public enum LogLevel { + DEBUG, INFO, WARN, ERROR, OFF +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogMessageHolder.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogMessageHolder.java new file mode 100644 index 000000000000..b4da293c6a0d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/LogMessageHolder.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +/** + * The LogMessageHolder is a {@link String} holder, + * in order to in-process propagation String across the disruptor queue. + * + * @author wusheng + */ +public class LogMessageHolder { + private String message; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriter.java new file mode 100644 index 000000000000..6faca49a7793 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +import java.io.PrintStream; + +public enum SystemOutWriter implements IWriter { + INSTANCE; + + /** + * Tricky codes for avoiding style-check. + * Because, in here, "system.out.println" is the only choice to output logs. + * + * @param message + */ + @Override + public void write(String message) { + PrintStream out = System.out; + out.println(message); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/WriterFactory.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/WriterFactory.java new file mode 100644 index 000000000000..ba0c8bf89f46 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/WriterFactory.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.util.StringUtil; + +public class WriterFactory { + public static IWriter getLogWriter() { + if (AgentPackagePath.isPathFound()) { + if (StringUtil.isEmpty(Config.Logging.DIR)) { + try { + Config.Logging.DIR = AgentPackagePath.getPath() + "/logs"; + } catch (AgentPackageNotFoundException e) { + e.printStackTrace(); + } + } + return FileWriter.get(); + } else { + return SystemOutWriter.INSTANCE; + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/OSUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java similarity index 80% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/OSUtil.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java index b9e620e2ebfa..a94ac7a66a1f 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/OSUtil.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.os; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.os; import java.lang.management.ManagementFactory; import java.net.Inet4Address; @@ -27,7 +45,7 @@ import java.util.Enumeration; import java.util.LinkedList; import java.util.List; -import org.skywalking.apm.network.proto.OSInfo; +import org.apache.skywalking.apm.network.proto.OSInfo; /** * @author wusheng diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/ProcessorUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/ProcessorUtil.java new file mode 100644 index 000000000000..d4ee7955e36f --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/ProcessorUtil.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.os; + +import java.lang.management.ManagementFactory; + +/** + * @author wusheng + */ +public class ProcessorUtil { + public static int getNumberOfProcessors() { + return ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java similarity index 78% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java index aff63ccd6d63..e72e0758d1e3 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.agent.core.plugin; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; import net.bytebuddy.dynamic.DynamicType; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.util.StringUtil; /** * Basic abstract class of all sky-walking auto-instrumentation plugins. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/EnhanceContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/EnhanceContext.java new file mode 100644 index 000000000000..a512fd9f9f99 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/EnhanceContext.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; + +/** + * The EnhanceContext represents the context or status for processing a class. + * + * Based on this context, the plugin core {@link ClassEnhancePluginDefine} + * knows how to process the specific steps for every particular plugin. + * + * @author wusheng + */ +public class EnhanceContext { + private boolean isEnhanced = false; + /** + * The object has already been enhanced or extended. + * e.g. added the new field, or implemented the new interface + */ + private boolean objectExtended = false; + + public boolean isEnhanced() { + return isEnhanced; + } + + public void initializationStageCompleted() { + isEnhanced = true; + } + + public boolean isObjectExtended() { + return objectExtended; + } + + public void extendObjectCompleted() { + objectExtended = true; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginBootstrap.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginBootstrap.java new file mode 100644 index 000000000000..db5627472d89 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginBootstrap.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; + +/** + * Plugins finder. + * Use {@link PluginResourcesResolver} to find all plugins, + * and ask {@link PluginCfg} to load all plugin definitions. + * + * @author wusheng + */ +public class PluginBootstrap { + private static final ILog logger = LogManager.getLogger(PluginBootstrap.class); + + /** + * load all plugins. + * + * @return plugin definition list. + */ + public List loadPlugins() throws AgentPackageNotFoundException { + AgentClassLoader.initDefaultLoader(); + + PluginResourcesResolver resolver = new PluginResourcesResolver(); + List resources = resolver.getResources(); + + if (resources == null || resources.size() == 0) { + logger.info("no plugin files (skywalking-plugin.def) found, continue to start application."); + return new ArrayList(); + } + + for (URL pluginUrl : resources) { + try { + PluginCfg.INSTANCE.load(pluginUrl.openStream()); + } catch (Throwable t) { + logger.error(t, "plugin file [{}] init failure.", pluginUrl); + } + } + + List pluginClassList = PluginCfg.INSTANCE.getPluginClassList(); + + List plugins = new ArrayList(); + for (PluginDefine pluginDefine : pluginClassList) { + try { + logger.debug("loading plugin class {}.", pluginDefine.getDefineClass()); + AbstractClassEnhancePluginDefine plugin = + (AbstractClassEnhancePluginDefine)Class.forName(pluginDefine.getDefineClass(), + true, + AgentClassLoader.getDefault()) + .newInstance(); + plugins.add(plugin); + } catch (Throwable t) { + logger.error(t, "load plugin [{}] failure.", pluginDefine.getDefineClass()); + } + } + + return plugins; + + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java new file mode 100644 index 000000000000..adbec5a7471e --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +import org.apache.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public enum PluginCfg { + INSTANCE; + + private static final ILog logger = LogManager.getLogger(PluginCfg.class); + + private List pluginClassList = new ArrayList(); + + void load(InputStream input) throws IOException { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + String pluginDefine = null; + while ((pluginDefine = reader.readLine()) != null) { + try { + if (pluginDefine == null || pluginDefine.trim().length() == 0) { + continue; + } + PluginDefine plugin = PluginDefine.build(pluginDefine); + pluginClassList.add(plugin); + } catch (IllegalPluginDefineException e) { + logger.error(e, "Failed to format plugin({}) define.", pluginDefine); + } + } + } finally { + input.close(); + } + } + + public List getPluginClassList() { + return pluginClassList; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java new file mode 100644 index 000000000000..d57af4c4ce7d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +import org.apache.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException; +import org.apache.skywalking.apm.util.StringUtil; + +public class PluginDefine { + /** + * Plugin name. + */ + private String name; + + /** + * The class name of plugin defined. + */ + private String defineClass; + + private PluginDefine(String name, String defineClass) { + this.name = name; + this.defineClass = defineClass; + } + + public static PluginDefine build(String define) throws IllegalPluginDefineException { + if (StringUtil.isEmpty(define)) { + throw new IllegalPluginDefineException(define); + } + + String[] pluginDefine = define.split("="); + if (pluginDefine.length != 2) { + throw new IllegalPluginDefineException(define); + } + + String pluginName = pluginDefine[0]; + String defineClass = pluginDefine[1]; + return new PluginDefine(pluginName, defineClass); + } + + public String getDefineClass() { + return defineClass; + } +} + + diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginException.java new file mode 100644 index 000000000000..8ded527c0e7d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +public class PluginException extends RuntimeException { + private static final long serialVersionUID = -6020188711867490724L; + + public PluginException(String message) { + super(message); + } + + public PluginException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginFinder.java similarity index 77% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginFinder.java index 7ef061d0c832..d4cb09de1125 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginFinder.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; import java.util.HashMap; import java.util.LinkedList; @@ -25,10 +43,10 @@ import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.bytebuddy.AbstractJunction; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.plugin.match.IndirectMatch; -import org.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.bytebuddy.AbstractJunction; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.not; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java new file mode 100644 index 000000000000..00ff2c7b3b6b --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader; + +/** + * Use the current classloader to read all plugin define file. + * The file must be named 'skywalking-plugin.def' + * + * @author wusheng + */ +public class PluginResourcesResolver { + private static final ILog logger = LogManager.getLogger(PluginResourcesResolver.class); + + public List getResources() { + List cfgUrlPaths = new ArrayList(); + Enumeration urls; + try { + urls = AgentClassLoader.getDefault().getResources("skywalking-plugin.def"); + + while (urls.hasMoreElements()) { + URL pluginUrl = urls.nextElement(); + cfgUrlPaths.add(pluginUrl); + logger.info("find skywalking plugin define in {}", pluginUrl); + } + + return cfgUrlPaths; + } catch (IOException e) { + logger.error("read resources failure.", e); + } + return null; + } + + /** + * Get the classloader. + * First getDefault current thread's classloader, + * if fail, getDefault {@link PluginResourcesResolver}'s classloader. + * + * @return the classloader to find plugin definitions. + */ + private ClassLoader getDefaultClassLoader() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (Throwable ex) { + // Cannot access thread context ClassLoader - falling back to system class loader... + } + if (cl == null) { + // No thread context class loader -> use class loader of this class. + cl = PluginResourcesResolver.class.getClassLoader(); + } + return cl; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessClassFinder.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessClassFinder.java new file mode 100644 index 000000000000..750d8591c796 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessClassFinder.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin; + +import java.util.HashMap; +import java.util.Map; +import net.bytebuddy.pool.TypePool; + +/** + * The WitnessClassFinder represents a pool of {@link TypePool}s, + * each {@link TypePool} matches a {@link ClassLoader}, + * which helps to find the class define existed or not. + * + * @author wusheng + */ +public enum WitnessClassFinder { + INSTANCE; + + private Map poolMap = new HashMap(); + + /** + * @param witnessClass + * @param classLoader for finding the witnessClass + * @return true, if the given witnessClass exists, through the given classLoader. + */ + public boolean exist(String witnessClass, ClassLoader classLoader) { + ClassLoader mappingKey = classLoader == null ? NullClassLoader.INSTANCE : classLoader; + if (!poolMap.containsKey(mappingKey)) { + synchronized (poolMap) { + if (!poolMap.containsKey(mappingKey)) { + TypePool classTypePool = classLoader == null ? TypePool.Default.ofClassPath() : TypePool.Default.of(classLoader); + poolMap.put(mappingKey, classTypePool); + } + } + } + TypePool typePool = poolMap.get(mappingKey); + TypePool.Resolution witnessClassResolution = typePool.describe(witnessClass); + return witnessClassResolution.isResolved(); + } +} + +final class NullClassLoader extends ClassLoader { + static NullClassLoader INSTANCE = new NullClassLoader(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java new file mode 100644 index 000000000000..da0b20061f76 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.bytebuddy; + +import net.bytebuddy.matcher.ElementMatcher; + +/** + * Created by wusheng on 16/7/31. + */ +public abstract class AbstractJunction implements ElementMatcher.Junction { + @Override + public Junction and(ElementMatcher other) { + return new Conjunction(this, other); + } + + @Override + public Junction or(ElementMatcher other) { + return new Disjunction(this, other); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java similarity index 77% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java index 5a0c3d185cad..aa87ddfbb640 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.bytebuddy; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.bytebuddy; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.ParameterList; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java new file mode 100644 index 000000000000..3c03560da022 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.exception; + +/** + * Thrown to indicate that a illegal format plugin definition has been defined in skywalking-plugin.define. + */ +public class IllegalPluginDefineException extends Exception { + public IllegalPluginDefineException(String define) { + super("Illegal plugin define : " + define); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java new file mode 100644 index 000000000000..025be74f8cb6 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +/** + * One of the three "Intercept Point". + * "Intercept Point" is a definition about where and how intercept happens. + * In this "Intercept Point", the definition targets class's constructors, and the interceptor. + *

+ * ref to two others: {@link StaticMethodsInterceptPoint} and {@link InstanceMethodsInterceptPoint} + *

+ * Created by wusheng on 2016/11/29. + */ +public interface ConstructorInterceptPoint { + /** + * Constructor matcher + * + * @return matcher instance. + */ + ElementMatcher getConstructorMatcher(); + + /** + * @return represents a class name, the class instance must be a instance of {@link + * org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor} + */ + String getConstructorInterceptor(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java new file mode 100644 index 000000000000..66e3dfc6af0a --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor; + +import org.apache.skywalking.apm.agent.core.plugin.PluginException; + +public class EnhanceException extends PluginException { + private static final long serialVersionUID = -2234782755784217255L; + + public EnhanceException(String message) { + super(message); + } + + public EnhanceException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java new file mode 100644 index 000000000000..fb150efba4d8 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +/** + * One of the three "Intercept Point". + * "Intercept Point" is a definition about where and how intercept happens. + * In this "Intercept Point", the definition targets class's instance methods, and the interceptor. + *

+ * ref to two others: {@link ConstructorInterceptPoint} and {@link StaticMethodsInterceptPoint} + *

+ * Created by wusheng on 2016/11/29. + */ +public interface InstanceMethodsInterceptPoint { + /** + * class instance methods matcher. + * + * @return methods matcher + */ + ElementMatcher getMethodsMatcher(); + + /** + * @return represents a class name, the class instance must instanceof InstanceMethodsAroundInterceptor. + */ + String getMethodsInterceptor(); + + boolean isOverrideArgs(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java new file mode 100644 index 000000000000..b01716f181ce --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor; + +public class InterceptorException extends RuntimeException { + private static final long serialVersionUID = 7846035239994885019L; + + public InterceptorException(String message) { + super(message); + } + + public InterceptorException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java new file mode 100644 index 000000000000..60c6711a6eef --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +/** + * One of the three "Intercept Point". + * "Intercept Point" is a definition about where and how intercept happens. + * In this "Intercept Point", the definition targets class's static methods, and the interceptor. + *

+ * ref to two others: {@link ConstructorInterceptPoint} and {@link InstanceMethodsInterceptPoint} + *

+ * Created by wusheng on 2016/11/29. + */ +public interface StaticMethodsInterceptPoint { + /** + * static methods matcher. + * + * @return matcher instance. + */ + ElementMatcher getMethodsMatcher(); + + /** + * @return represents a class name, the class instance must instanceof StaticMethodsAroundInterceptor. + */ + String getMethodsInterceptor(); + + boolean isOverrideArgs(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java similarity index 85% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java index aac104981b18..155db6f97b64 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java @@ -16,23 +16,41 @@ * */ -package org.skywalking.apm.agent.core.plugin.interceptor.enhance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.implementation.FieldAccessor; import net.bytebuddy.implementation.MethodDelegation; import net.bytebuddy.implementation.SuperMethodCall; import net.bytebuddy.implementation.bind.annotation.Morph; -import org.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.EnhanceContext; -import org.skywalking.apm.agent.core.plugin.PluginException; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.EnhanceException; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.EnhanceException; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.PluginException; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.util.StringUtil; import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE; import static net.bytebuddy.matcher.ElementMatchers.isStatic; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java new file mode 100644 index 000000000000..63f6211b3862 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; + +/** + * Plugins, which only need enhance class static methods. Actually, inherit from {@link + * ClassInstanceMethodsEnhancePluginDefine} has no differences with inherit from {@link ClassEnhancePluginDefine}. Just + * override {@link ClassEnhancePluginDefine#getStaticMethodsInterceptPoints}, and return {@link null}, which means + * nothing to enhance. + * + * @author wusheng + */ +public abstract class ClassInstanceMethodsEnhancePluginDefine extends ClassEnhancePluginDefine { + + /** + * @return null, means enhance no static methods. + */ + @Override + protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return null; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java new file mode 100644 index 000000000000..abe79e865acb --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +/** + * Plugins, which only need enhance class static methods. Actually, inherit from {@link + * ClassStaticMethodsEnhancePluginDefine} has no differences with inherit from {@link ClassEnhancePluginDefine}. Just + * override {@link ClassEnhancePluginDefine#getConstructorsInterceptPoints} and {@link + * ClassEnhancePluginDefine#getInstanceMethodsInterceptPoints}, and return {@link null}, which means nothing to + * enhance. + * + * @author wusheng + */ +public abstract class ClassStaticMethodsEnhancePluginDefine extends ClassEnhancePluginDefine { + + /** + * @return null, means enhance no constructors. + */ + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + /** + * @return null, means enhance no instance methods. + */ + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return null; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java new file mode 100644 index 000000000000..34e88a21a794 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +import net.bytebuddy.implementation.bind.annotation.AllArguments; +import net.bytebuddy.implementation.bind.annotation.RuntimeType; +import net.bytebuddy.implementation.bind.annotation.This; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.PluginException; +import org.apache.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; + +/** + * The actual byte-buddy's interceptor to intercept constructor methods. + * In this class, it provide a bridge between byte-buddy and sky-walking plugin. + * + * @author wusheng + */ +public class ConstructorInter { + private static final ILog logger = LogManager.getLogger(ConstructorInter.class); + + /** + * An {@link InstanceConstructorInterceptor} + * This name should only stay in {@link String}, the real {@link Class} type will trigger classloader failure. + * If you want to know more, please check on books about Classloader or Classloader appointment mechanism. + */ + private InstanceConstructorInterceptor interceptor; + + /** + * @param constructorInterceptorClassName class full name. + */ + public ConstructorInter(String constructorInterceptorClassName, ClassLoader classLoader) throws PluginException { + try { + interceptor = InterceptorInstanceLoader.load(constructorInterceptorClassName, classLoader); + } catch (Throwable t) { + throw new PluginException("Can't create InstanceConstructorInterceptor.", t); + } + } + + /** + * Intercept the target constructor. + * + * @param obj target class instance. + * @param allArguments all constructor arguments + */ + @RuntimeType + public void intercept(@This Object obj, + @AllArguments Object[] allArguments) { + try { + EnhancedInstance targetObject = (EnhancedInstance)obj; + + interceptor.onConstruct(targetObject, allArguments); + } catch (Throwable t) { + logger.error("ConstructorInter failure.", t); + } + + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java new file mode 100644 index 000000000000..fca6ebea9ee6 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +/** + * @author wusheng + */ +public interface EnhancedInstance { + Object getSkyWalkingDynamicField(); + + void setSkyWalkingDynamicField(Object value); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java similarity index 78% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java index 385d98c48a17..230e9316bd5e 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.interceptor.enhance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; import java.lang.reflect.Method; import java.util.concurrent.Callable; @@ -25,10 +43,10 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType; import net.bytebuddy.implementation.bind.annotation.SuperCall; import net.bytebuddy.implementation.bind.annotation.This; -import org.skywalking.apm.agent.core.plugin.PluginException; -import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.PluginException; +import org.apache.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; /** * The actual byte-buddy's interceptor to intercept class instance methods. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java similarity index 78% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java index f065a0d12149..6fc99780cff2 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.interceptor.enhance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; import java.lang.reflect.Method; import net.bytebuddy.implementation.bind.annotation.AllArguments; @@ -24,10 +42,10 @@ import net.bytebuddy.implementation.bind.annotation.Origin; import net.bytebuddy.implementation.bind.annotation.RuntimeType; import net.bytebuddy.implementation.bind.annotation.This; -import org.skywalking.apm.agent.core.plugin.PluginException; -import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.PluginException; +import org.apache.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; /** * The actual byte-buddy's interceptor to intercept class instance methods. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java new file mode 100644 index 000000000000..3b85beb7e1b5 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +/** + * The instance constructor's interceptor interface. + * Any plugin, which wants to intercept constructor, must implement this interface. + *

+ * + * @author wusheng + */ +public interface InstanceConstructorInterceptor { + /** + * Called before the origin constructor invocation. + */ + void onConstruct(EnhancedInstance objInst, Object[] allArguments); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java new file mode 100644 index 000000000000..ca38f36b3ee2 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +import java.lang.reflect.Method; + +/** + * A interceptor, which intercept method's invocation. The target methods will be defined in {@link + * ClassEnhancePluginDefine}'s subclass, most likely in {@link ClassInstanceMethodsEnhancePluginDefine} + * + * @author wusheng + */ +public interface InstanceMethodsAroundInterceptor { + /** + * called before target method invocation. + * + * @param method + * @param result change this result, if you want to truncate the method. + * @throws Throwable + */ + void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable; + + /** + * called after target method invocation. Even method's invocation triggers an exception. + * + * @param method + * @param ret the method's original return value. + * @return the method's actual return value. + * @throws Throwable + */ + Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable; + + /** + * called when occur exception. + * + * @param method + * @param t the exception occur. + */ + void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Throwable t); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java new file mode 100644 index 000000000000..9a0bb42e83f8 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +/** + * This is a method return value manipulator. When a interceptor's method, such as {@link + * InstanceMethodsAroundInterceptor#beforeMethod(org.apache.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext, + * InstanceMethodInvokeContext, MethodInterceptResult)}, has this as a method argument, the interceptor can manipulate + * the method's return value.

The new value set to this object, by {@link MethodInterceptResult#defineReturnValue(Object)}, + * will override the origin return value. + * + * @author wusheng + */ +public class MethodInterceptResult { + private boolean isContinue = true; + + private Object ret = null; + + /** + * define the new return value. + * + * @param ret new return value. + */ + public void defineReturnValue(Object ret) { + this.isContinue = false; + this.ret = ret; + } + + /** + * @return true, will trigger method interceptor({@link InstMethodsInter} and {@link StaticMethodsInter}) to invoke + * the origin method. Otherwise, not. + */ + public boolean isContinue() { + return isContinue; + } + + /** + * @return the new return value. + */ + Object _ret() { + return ret; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java new file mode 100644 index 000000000000..4b6d35caaa08 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +/** + * @author wusheng + */ +public interface OverrideCallable { + Object call(Object[] args); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java new file mode 100644 index 000000000000..a4faebc6d8dd --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; + +import java.lang.reflect.Method; + +/** + * The static method's interceptor interface. + * Any plugin, which wants to intercept static methods, must implement this interface. + * + * @author wusheng + */ +public interface StaticMethodsAroundInterceptor { + /** + * called before target method invocation. + * + * @param method + * @param result change this result, if you want to truncate the method. + */ + void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + MethodInterceptResult result); + + /** + * called after target method invocation. Even method's invocation triggers an exception. + * + * @param method + * @param ret the method's original return value. + * @return the method's actual return value. + */ + Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, Object ret); + + /** + * called when occur exception. + * + * @param method + * @param t the exception occur. + */ + void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Throwable t); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java index 2ca3863dd2e4..6f62a32dffc4 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.interceptor.enhance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; import java.lang.reflect.Method; import java.util.concurrent.Callable; @@ -24,9 +42,9 @@ import net.bytebuddy.implementation.bind.annotation.Origin; import net.bytebuddy.implementation.bind.annotation.RuntimeType; import net.bytebuddy.implementation.bind.annotation.SuperCall; -import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; /** * The actual byte-buddy's interceptor to intercept class instance methods. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java index 27120d92d8c0..45354facae78 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java @@ -16,16 +16,34 @@ * */ -package org.skywalking.apm.agent.core.plugin.interceptor.enhance; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance; import java.lang.reflect.Method; import net.bytebuddy.implementation.bind.annotation.AllArguments; import net.bytebuddy.implementation.bind.annotation.Morph; import net.bytebuddy.implementation.bind.annotation.Origin; import net.bytebuddy.implementation.bind.annotation.RuntimeType; -import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; /** * The actual byte-buddy's interceptor to intercept class instance methods. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java similarity index 85% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java index 9b84829ba8bd..389dc71c5acf 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.agent.core.plugin.loader; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.loader; -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.skywalking.apm.agent.core.plugin.PluginBootstrap; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; import java.io.*; import java.net.MalformedURLException; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java similarity index 77% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java index d0289646a12d..9dffa25e3dfa 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.agent.core.plugin.loader; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.loader; -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java similarity index 77% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java index 1998b53ce9cb..5b0ee1892362 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassAnnotationMatch.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.match; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.match; import java.util.ArrayList; import java.util.Arrays; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassMatch.java new file mode 100644 index 000000000000..2c12fcf9d1ad --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/ClassMatch.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.match; + +/** + * @author wusheng + */ +public interface ClassMatch { +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java similarity index 80% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java index c47c4db8c4bc..3c449b837389 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/HierarchyMatch.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.match; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.match; import java.util.ArrayList; import java.util.Arrays; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/IndirectMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/IndirectMatch.java new file mode 100644 index 000000000000..74c005e30e54 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/IndirectMatch.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.match; + +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +/** + * All implementations can't direct match the class like {@link NameMatch} did. + * + * @author wusheng + */ +public interface IndirectMatch extends ClassMatch { + ElementMatcher.Junction buildJunction(); + + boolean isMatch(TypeDescription typeDescription); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java index f22201e2c3fb..f2c18f800735 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/MethodAnnotationMatch.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.plugin.match; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.match; import java.util.ArrayList; import java.util.Arrays; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/NameMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/NameMatch.java new file mode 100644 index 000000000000..0d95ab06c0c3 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/NameMatch.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.plugin.match; + +/** + * Match the class with an explicit class name. + * + * @author wusheng + */ +public class NameMatch implements ClassMatch { + private String className; + + private NameMatch(String className) { + this.className = className; + } + + public String getClassName() { + return className; + } + + public static NameMatch byName(String className) { + return new NameMatch(className); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java new file mode 100644 index 000000000000..a762d8966f45 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +import io.grpc.ManagedChannel; +import java.util.UUID; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.apache.skywalking.apm.agent.core.dictionary.ApplicationDictionary; +import org.apache.skywalking.apm.agent.core.os.OSUtil; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.dictionary.OperationNameDictionary; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.network.proto.Application; +import org.apache.skywalking.apm.network.proto.ApplicationInstance; +import org.apache.skywalking.apm.network.proto.ApplicationInstanceHeartbeat; +import org.apache.skywalking.apm.network.proto.ApplicationInstanceMapping; +import org.apache.skywalking.apm.network.proto.ApplicationInstanceRecover; +import org.apache.skywalking.apm.network.proto.ApplicationMapping; +import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; +import org.apache.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc; +import org.apache.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; + +/** + * @author wusheng + */ +public class AppAndServiceRegisterClient implements BootService, GRPCChannelListener, Runnable, TracingContextListener { + private static final ILog logger = LogManager.getLogger(AppAndServiceRegisterClient.class); + private static final String PROCESS_UUID = UUID.randomUUID().toString().replaceAll("-", ""); + + private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT; + private volatile ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub applicationRegisterServiceBlockingStub; + private volatile InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceBlockingStub instanceDiscoveryServiceBlockingStub; + private volatile ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceBlockingStub serviceNameDiscoveryServiceBlockingStub; + private volatile ScheduledFuture applicationRegisterFuture; + private volatile boolean needRegisterRecover = false; + private volatile long lastSegmentTime = -1; + + @Override + public void statusChanged(GRPCChannelStatus status) { + if (GRPCChannelStatus.CONNECTED.equals(status)) { + ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel(); + applicationRegisterServiceBlockingStub = ApplicationRegisterServiceGrpc.newBlockingStub(channel); + instanceDiscoveryServiceBlockingStub = InstanceDiscoveryServiceGrpc.newBlockingStub(channel); + if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()) { + needRegisterRecover = true; + } + serviceNameDiscoveryServiceBlockingStub = ServiceNameDiscoveryServiceGrpc.newBlockingStub(channel); + } else { + applicationRegisterServiceBlockingStub = null; + instanceDiscoveryServiceBlockingStub = null; + serviceNameDiscoveryServiceBlockingStub = null; + } + this.status = status; + } + + @Override + public void beforeBoot() throws Throwable { + ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(this); + } + + @Override + public void boot() throws Throwable { + applicationRegisterFuture = Executors + .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("AppAndServiceRegisterClient")) + .scheduleAtFixedRate(this, 0, Config.Collector.APP_AND_SERVICE_REGISTER_CHECK_INTERVAL, TimeUnit.SECONDS); + } + + @Override + public void afterBoot() throws Throwable { + TracingContext.ListenerManager.add(this); + } + + @Override + public void shutdown() throws Throwable { + applicationRegisterFuture.cancel(true); + } + + @Override + public void run() { + logger.debug("AppAndServiceRegisterClient running, status:{}.",status); + boolean shouldTry = true; + while (GRPCChannelStatus.CONNECTED.equals(status) && shouldTry) { + shouldTry = false; + try { + if (RemoteDownstreamConfig.Agent.APPLICATION_ID == DictionaryUtil.nullValue()) { + if (applicationRegisterServiceBlockingStub != null) { + ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.register( + Application.newBuilder().addApplicationCode(Config.Agent.APPLICATION_CODE).build()); + if (applicationMapping.getApplicationCount() > 0) { + RemoteDownstreamConfig.Agent.APPLICATION_ID = applicationMapping.getApplication(0).getValue(); + shouldTry = true; + } + } + } else { + if (instanceDiscoveryServiceBlockingStub != null) { + if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID == DictionaryUtil.nullValue()) { + + ApplicationInstanceMapping instanceMapping = instanceDiscoveryServiceBlockingStub.register(ApplicationInstance.newBuilder() + .setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID) + .setAgentUUID(PROCESS_UUID) + .setRegisterTime(System.currentTimeMillis()) + .setOsinfo(OSUtil.buildOSInfo()) + .build()); + if (instanceMapping.getApplicationInstanceId() != DictionaryUtil.nullValue()) { + RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID + = instanceMapping.getApplicationInstanceId(); + } + } else { + if (needRegisterRecover) { + instanceDiscoveryServiceBlockingStub.registerRecover(ApplicationInstanceRecover.newBuilder() + .setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID) + .setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID) + .setRegisterTime(System.currentTimeMillis()) + .setOsinfo(OSUtil.buildOSInfo()) + .build()); + needRegisterRecover = false; + } else { + if (lastSegmentTime - System.currentTimeMillis() > 60 * 1000) { + instanceDiscoveryServiceBlockingStub.heartbeat(ApplicationInstanceHeartbeat.newBuilder() + .setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID) + .setHeartbeatTime(System.currentTimeMillis()) + .build()); + } + } + + ApplicationDictionary.INSTANCE.syncRemoteDictionary(applicationRegisterServiceBlockingStub); + OperationNameDictionary.INSTANCE.syncRemoteDictionary(serviceNameDiscoveryServiceBlockingStub); + } + } + } + } catch (Throwable t) { + logger.error(t, "AppAndServiceRegisterClient execute fail."); + ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(t); + } + } + } + + @Override + public void afterFinished(TraceSegment traceSegment) { + lastSegmentTime = System.currentTimeMillis(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java new file mode 100644 index 000000000000..5890550f3852 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; +import org.apache.skywalking.apm.agent.core.conf.Config; + +/** + * The CollectorDiscoveryService is responsible for start {@link DiscoveryRestServiceClient}. + * + * @author wusheng + */ +public class CollectorDiscoveryService implements BootService { + private ScheduledFuture future; + + @Override + public void beforeBoot() throws Throwable { + + } + + @Override + public void boot() throws Throwable { + future = Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("CollectorDiscoveryService")) + .scheduleAtFixedRate(new DiscoveryRestServiceClient(), 0, + Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS); + } + + @Override + public void afterBoot() throws Throwable { + + } + + @Override + public void shutdown() throws Throwable { + future.cancel(true); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java index 0221959645a7..6a0c29fb51a2 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.remote; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; import com.google.gson.Gson; import com.google.gson.JsonArray; @@ -30,16 +48,16 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; -import static org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.Collector.GRPC_SERVERS; +import static org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.Collector.GRPC_SERVERS; /** * The DiscoveryRestServiceClient try to get the collector's grpc-server list * in every 60 seconds, - * and override {@link org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.Collector#GRPC_SERVERS}. + * and override {@link org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.Collector#GRPC_SERVERS}. * * @author wusheng */ diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelListener.java new file mode 100644 index 000000000000..50dbc6bb2716 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelListener.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +/** + * @author wusheng + */ +public interface GRPCChannelListener { + void statusChanged(GRPCChannelStatus status); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java similarity index 82% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelManager.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java index dedc1e17a548..ae903dfa9394 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelManager.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.remote; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -31,12 +49,12 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.conf.Config; /** * @author wusheng diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelStatus.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelStatus.java new file mode 100644 index 000000000000..bf7ea1ce0c4a --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelStatus.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +/** + * @author wusheng + */ +public enum GRPCChannelStatus { + CONNECTED, + DISCONNECT +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java new file mode 100644 index 000000000000..3929c7db36b0 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +/** + * @author wusheng + */ +public class GRPCStreamServiceStatus { + private volatile boolean status; + + public GRPCStreamServiceStatus(boolean status) { + this.status = status; + } + + public boolean isStatus() { + return status; + } + + public void finished() { + this.status = true; + } + + /** + * @param maxTimeout max wait time, milliseconds. + */ + public boolean wait4Finish(long maxTimeout) { + long time = 0; + while (!status) { + if (time > maxTimeout) { + break; + } + try2Sleep(5); + time += 5; + } + return status; + } + + /** + * Try to sleep, and ignore the {@link InterruptedException} + * + * @param millis the length of time to sleep in milliseconds + */ + private void try2Sleep(long millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + + } + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/RESTResponseStatusError.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/RESTResponseStatusError.java new file mode 100644 index 000000000000..26c7ff98783c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/RESTResponseStatusError.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +/** + * The RESTResponseStatusError represents the REST-Service discovery got an unexpected response code. + * Most likely, the response code is not 200. + * + * @author wusheng + */ +class RESTResponseStatusError extends Exception { + RESTResponseStatusError(int responseCode) { + super("Unexpected service response code: " + responseCode); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java new file mode 100644 index 000000000000..b683ab0d2fa6 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +import io.grpc.ManagedChannel; +import io.grpc.stub.StreamObserver; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.apache.skywalking.apm.commons.datacarrier.DataCarrier; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; +import org.apache.skywalking.apm.commons.datacarrier.consumer.IConsumer; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.network.proto.Downstream; +import org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; + +import static org.apache.skywalking.apm.agent.core.conf.Config.Buffer.BUFFER_SIZE; +import static org.apache.skywalking.apm.agent.core.conf.Config.Buffer.CHANNEL_SIZE; +import static org.apache.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED; + +/** + * @author wusheng + */ +public class TraceSegmentServiceClient implements BootService, IConsumer, TracingContextListener, GRPCChannelListener { + private static final ILog logger = LogManager.getLogger(TraceSegmentServiceClient.class); + private static final int TIMEOUT = 30 * 1000; + + private long lastLogTime; + private long segmentUplinkedCounter; + private long segmentAbandonedCounter; + private volatile DataCarrier carrier; + private volatile TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub; + private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT; + + @Override + public void beforeBoot() throws Throwable { + ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(this); + } + + @Override + public void boot() throws Throwable { + lastLogTime = System.currentTimeMillis(); + segmentUplinkedCounter = 0; + segmentAbandonedCounter = 0; + carrier = new DataCarrier(CHANNEL_SIZE, BUFFER_SIZE); + carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE); + carrier.consume(this, 1); + } + + @Override + public void afterBoot() throws Throwable { + TracingContext.ListenerManager.add(this); + } + + @Override + public void shutdown() throws Throwable { + carrier.shutdownConsumers(); + } + + @Override + public void init() { + + } + + @Override + public void consume(List data) { + if (CONNECTED.equals(status)) { + final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false); + StreamObserver upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver() { + @Override + public void onNext(Downstream downstream) { + + } + + @Override + public void onError(Throwable throwable) { + status.finished(); + if (logger.isErrorEnable()) { + logger.error(throwable, "Send UpstreamSegment to collector fail with a grpc internal exception."); + } + ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable); + } + + @Override + public void onCompleted() { + status.finished(); + } + }); + + for (TraceSegment segment : data) { + try { + UpstreamSegment upstreamSegment = segment.transform(); + upstreamSegmentStreamObserver.onNext(upstreamSegment); + } catch (Throwable t) { + logger.error(t, "Transform and send UpstreamSegment to collector fail."); + } + } + upstreamSegmentStreamObserver.onCompleted(); + + if (status.wait4Finish(TIMEOUT)) { + segmentUplinkedCounter += data.size(); + } + } else { + segmentAbandonedCounter += data.size(); + } + + printUplinkStatus(); + } + + private void printUplinkStatus() { + long currentTimeMillis = System.currentTimeMillis(); + if (currentTimeMillis - lastLogTime > 30 * 1000) { + lastLogTime = currentTimeMillis; + if (segmentUplinkedCounter > 0) { + logger.debug("{} trace segments have been sent to collector.", segmentUplinkedCounter); + segmentUplinkedCounter = 0; + } + if (segmentAbandonedCounter > 0) { + logger.debug("{} trace segments have been abandoned, cause by no available channel.", segmentAbandonedCounter); + segmentAbandonedCounter = 0; + } + } + } + + @Override + public void onError(List data, Throwable t) { + logger.error(t, "Try to send {} trace segments to collector, with unexpected exception.", data.size()); + } + + @Override + public void onExit() { + + } + + @Override + public void afterFinished(TraceSegment traceSegment) { + if (traceSegment.isIgnore()) { + return; + } + if (!carrier.produce(traceSegment)) { + if (logger.isDebugEnable()) { + logger.debug("One trace segment has been abandoned, cause by buffer is full."); + } + } + } + + @Override + public void statusChanged(GRPCChannelStatus status) { + if (CONNECTED.equals(status)) { + ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel(); + serviceStub = TraceSegmentServiceGrpc.newStub(channel); + } + this.status = status; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/sampling/SamplingService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java similarity index 75% rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/sampling/SamplingService.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java index ba354ccea36e..11976047d6ee 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/sampling/SamplingService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java @@ -16,19 +16,37 @@ * */ -package org.skywalking.apm.agent.core.sampling; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.sampling; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.conf.Config; /** * The SamplingService take charge of how to sample the {@link TraceSegment}. Every {@link TraceSegment}s diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java deleted file mode 100644 index 3df5034f30ce..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.boot; - -/** - * @author wusheng - */ -public class AgentPackageNotFoundException extends Exception { - public AgentPackageNotFoundException(String message) { - super(message); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackagePath.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackagePath.java deleted file mode 100644 index e280033f17fd..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackagePath.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.boot; - -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; - -/** - * @author wusheng - */ -public class AgentPackagePath { - private static final ILog logger = LogManager.getLogger(AgentPackagePath.class); - - private static File AGENT_PACKAGE_PATH; - - public static File getPath() throws AgentPackageNotFoundException { - if (AGENT_PACKAGE_PATH == null) { - AGENT_PACKAGE_PATH = findPath(); - } - return AGENT_PACKAGE_PATH; - } - - public static boolean isPathFound() { - return AGENT_PACKAGE_PATH != null; - } - - private static File findPath() throws AgentPackageNotFoundException { - String classResourcePath = AgentPackagePath.class.getName().replaceAll("\\.", "/") + ".class"; - - URL resource = AgentPackagePath.class.getClassLoader().getSystemClassLoader().getResource(classResourcePath); - if (resource != null) { - String urlString = resource.toString(); - - logger.debug("The beacon class location is {}.", urlString); - - int insidePathIndex = urlString.indexOf('!'); - boolean isInJar = insidePathIndex > -1; - - if (isInJar) { - urlString = urlString.substring(urlString.indexOf("file:"), insidePathIndex); - File agentJarFile = null; - try { - agentJarFile = new File(new URL(urlString).getFile()); - } catch (MalformedURLException e) { - logger.error(e, "Can not locate agent jar file by url:" + urlString); - } - if (agentJarFile.exists()) { - return agentJarFile.getParentFile(); - } - } else { - String classLocation = urlString.substring(urlString.indexOf("file:"), urlString.length() - classResourcePath.length()); - return new File(classLocation); - } - } - - logger.error("Can not locate agent jar file."); - throw new AgentPackageNotFoundException("Can not locate agent jar file."); - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/BootService.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/BootService.java deleted file mode 100644 index 8ea91d89cb8e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/BootService.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.boot; - -/** - * The BootService is an interface to all remote, which need to boot when plugin mechanism begins to - * work. - * {@link #boot()} will be called when BootService start up. - * - * @author wusheng - */ -public interface BootService { - void beforeBoot() throws Throwable; - - void boot() throws Throwable; - - void afterBoot() throws Throwable; - - void shutdown() throws Throwable; -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java deleted file mode 100644 index a2f12d4bc0a2..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.boot; - -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author zhangkewei - */ -public class DefaultNamedThreadFactory implements ThreadFactory { - private static final AtomicInteger BOOT_SERVICE_SEQ = new AtomicInteger(0); - private final AtomicInteger threadSeq = new AtomicInteger(0); - private final String namePrefix; - public DefaultNamedThreadFactory(String name) { - namePrefix = "SkywalkingAgent-" + BOOT_SERVICE_SEQ.incrementAndGet() + "-" + name + "-"; - } - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r,namePrefix + threadSeq.getAndIncrement()); - t.setDaemon(true); - return t; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/ConfigNotFoundException.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/ConfigNotFoundException.java deleted file mode 100644 index 023b0825081d..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/ConfigNotFoundException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.conf; - -/** - * @author wusheng - */ -public class ConfigNotFoundException extends Exception { - public ConfigNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public ConfigNotFoundException(String message) { - super(message); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Constants.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Constants.java deleted file mode 100644 index 90055ff7c53f..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Constants.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.conf; - -public class Constants { - public static String PATH_SEPARATOR = System.getProperty("file.separator", "/"); - - public static String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java deleted file mode 100644 index ecfc095c576b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.conf; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; - -/** - * The RemoteDownstreamConfig includes configurations from collector side. - * All of them initialized null, Null-Value or empty collection. - * - * @author wusheng - */ -public class RemoteDownstreamConfig { - public static class Agent { - public volatile static int APPLICATION_ID = DictionaryUtil.nullValue(); - - public volatile static int APPLICATION_INSTANCE_ID = DictionaryUtil.nullValue(); - } - - public static class Collector { - /** - * Collector GRPC-Service address. - */ - public volatile static List GRPC_SERVERS = new LinkedList(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItem.java deleted file mode 100644 index 8b596016bcb5..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItem.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -import java.util.Iterator; - -/** - * @author wusheng - */ -public class CarrierItem implements Iterator { - private String headKey; - private String headValue; - private CarrierItem next; - - public CarrierItem(String headKey, String headValue) { - this.headKey = headKey; - this.headValue = headValue; - next = null; - } - - public CarrierItem(String headKey, String headValue, CarrierItem next) { - this.headKey = headKey; - this.headValue = headValue; - this.next = next; - } - - public String getHeadKey() { - return headKey; - } - - public String getHeadValue() { - return headValue; - } - - public void setHeadValue(String headValue) { - this.headValue = headValue; - } - - @Override - public boolean hasNext() { - return next != null; - } - - @Override - public CarrierItem next() { - return next; - } - - @Override - public void remove() { - - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItemHead.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItemHead.java deleted file mode 100644 index 88f2e8b25a10..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/CarrierItemHead.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -/** - * @author wusheng - */ -public class CarrierItemHead extends CarrierItem { - public CarrierItemHead(CarrierItem next) { - super("", "", next); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java deleted file mode 100644 index dbf79543a58d..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoreTracerContextListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -/** - * @author wusheng - */ -public interface IgnoreTracerContextListener { - void afterFinished(IgnoredTracerContext traceSegment); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java deleted file mode 100644 index cd35a0f08403..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -/** - * The Injectable represents a provider, which gives the reference of {@link ContextCarrier} and peer - * for the agent core, for cross-process propagation. - * - * @author wusheng - */ -public interface Injectable { - ContextCarrier getCarrier(); - - /** - * @return peer, represent ipv4, ipv6, hostname, or cluster addresses list. - */ - String getPeer(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/SW3CarrierItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/SW3CarrierItem.java deleted file mode 100644 index 926789500637..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/SW3CarrierItem.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -/** - * @author wusheng - */ -public class SW3CarrierItem extends CarrierItem { - public static final String HEADER_NAME = "sw3"; - private ContextCarrier carrier; - - public SW3CarrierItem(ContextCarrier carrier, CarrierItem next) { - super(HEADER_NAME, carrier.serialize(), next); - this.carrier = carrier; - } - - @Override - public void setHeadValue(String headValue) { - carrier.deserialize(headValue); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TraceContextCarrierItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TraceContextCarrierItem.java deleted file mode 100644 index 7a4c1db42743..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TraceContextCarrierItem.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -/** - * @author wusheng - */ -public class TraceContextCarrierItem extends CarrierItem { - private static final String HEAD_NAME = "Trace-Context"; - - public TraceContextCarrierItem(String headValue, CarrierItem next) { - super(HEAD_NAME, headValue, next); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java deleted file mode 100644 index 5b855fbede14..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public interface TracingContextListener { - void afterFinished(TraceSegment traceSegment); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceId.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceId.java deleted file mode 100644 index 45e774fc35eb..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceId.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids; - -import org.skywalking.apm.network.proto.UniqueId; - -/** - * The DistributedTraceId presents a distributed call chain. - *

- * This call chain has an unique (service) entrance, - *

- * such as: Service : http://www.skywalking.com/cust/query, all the remote, called behind this service, rest remote, - * db executions, are using the same DistributedTraceId even in different JVM. - *

- * The DistributedTraceId contains only one string, and can NOT be reset, creating a new instance is the - * only option. - * - * @author wusheng - */ -public abstract class DistributedTraceId { - private ID id; - - public DistributedTraceId(ID id) { - this.id = id; - } - - public DistributedTraceId(String id) { - this.id = new ID(id); - } - - public String encode() { - return id.encode(); - } - - @Override - public String toString() { - return id.toString(); - } - - public UniqueId toUniqueId() { - return id.transform(); - } - - /** - * Compare the two DistributedTraceId by its {@link #id}, - * even these two DistributedTraceIds are not the same instances. - * - * @param o target DistributedTraceId - * @return return if they have the same {@link #id} - */ - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - DistributedTraceId id1 = (DistributedTraceId)o; - - return id != null ? id.equals(id1.id) : id1.id == null; - } - - @Override - public int hashCode() { - return id != null ? id.hashCode() : 0; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java deleted file mode 100644 index 28d0122f40e7..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * @author wusheng - */ -public class DistributedTraceIds { - private LinkedList relatedGlobalTraces; - - public DistributedTraceIds() { - relatedGlobalTraces = new LinkedList(); - } - - public List getRelatedGlobalTraces() { - return Collections.unmodifiableList(relatedGlobalTraces); - } - - public void append(DistributedTraceId distributedTraceId) { - if (relatedGlobalTraces.size() > 0 && relatedGlobalTraces.getFirst() instanceof NewDistributedTraceId) { - relatedGlobalTraces.removeFirst(); - } - if (!relatedGlobalTraces.contains(distributedTraceId)) { - relatedGlobalTraces.add(distributedTraceId); - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java deleted file mode 100644 index c526c2e762a1..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids; - -/** - * The NewDistributedTraceId is a {@link DistributedTraceId} with a new generated id. - * - * @author wusheng - */ -public class NewDistributedTraceId extends DistributedTraceId { - public NewDistributedTraceId() { - super(GlobalIdGenerator.generate()); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java deleted file mode 100644 index 94e8fb39c56a..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/PropagatedTraceId.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids; - -/** - * The PropagatedTraceId represents a {@link DistributedTraceId}, which is propagated from the peer. - * - * @author wusheng - */ -public class PropagatedTraceId extends DistributedTraceId { - public PropagatedTraceId(String id) { - super(id); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Base64.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Base64.java deleted file mode 100644 index 59bb0e0faf5c..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Base64.java +++ /dev/null @@ -1,965 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids.base64; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.util.Arrays; - -/** - * This class consists exclusively of static methods for obtaining - * encoders and decoders for the Base64 encoding scheme. The - * implementation of this class supports the following types of Base64 - * as specified in - * RFC 4648 and - * RFC 2045. - * - *

    - *
  • Basic - *

    Uses "The Base64 Alphabet" as specified in Table 1 of - * RFC 4648 and RFC 2045 for encoding and decoding operation. - * The encoder does not add any line feed (line separator) - * character. The decoder rejects data that contains characters - * outside the base64 alphabet.

  • - * - *
  • URL and Filename safe - *

    Uses the "URL and Filename safe Base64 Alphabet" as specified - * in Table 2 of RFC 4648 for encoding and decoding. The - * encoder does not add any line feed (line separator) character. - * The decoder rejects data that contains characters outside the - * base64 alphabet.

  • - * - *
  • MIME - *

    Uses the "The Base64 Alphabet" as specified in Table 1 of - * RFC 2045 for encoding and decoding operation. The encoded output - * must be represented in lines of no more than 76 characters each - * and uses a carriage return {@code '\r'} followed immediately by - * a linefeed {@code '\n'} as the line separator. No line separator - * is added to the end of the encoded output. All line separators - * or other characters not found in the base64 alphabet table are - * ignored in decoding operation.

  • - *
- * - *

Unless otherwise noted, passing a {@code null} argument to a - * method of this class will cause a {@link java.lang.NullPointerException - * NullPointerException} to be thrown. - * - * @author Xueming Shen - * @since 1.8 - */ - -public class Base64 { - - private Base64() { - } - - /** - * Returns a {@link Encoder} that encodes using the - * Basic type base64 encoding scheme. - * - * @return A Base64 encoder. - */ - public static Encoder getEncoder() { - return Encoder.RFC4648; - } - - /** - * Returns a {@link Encoder} that encodes using the - * URL and Filename safe type base64 - * encoding scheme. - * - * @return A Base64 encoder. - */ - public static Encoder getUrlEncoder() { - return Encoder.RFC4648_URLSAFE; - } - - /** - * Returns a {@link Encoder} that encodes using the - * MIME type base64 encoding scheme. - * - * @return A Base64 encoder. - */ - public static Encoder getMimeEncoder() { - return Encoder.RFC2045; - } - - /** - * Returns a {@link Encoder} that encodes using the - * MIME type base64 encoding scheme - * with specified line length and line separators. - * - * @param lineLength the length of each output line (rounded down to nearest multiple of 4). If {@code lineLength <= - * 0} the output will not be separated in lines - * @param lineSeparator the line separator for each output line - * @return A Base64 encoder. - * @throws IllegalArgumentException if {@code lineSeparator} includes any character of "The Base64 Alphabet" as - * specified in Table 1 of RFC 2045. - */ - public static Encoder getMimeEncoder(int lineLength, byte[] lineSeparator) { - Objects.requireNonNull(lineSeparator); - int[] base64 = Decoder.fromBase64; - for (byte b : lineSeparator) { - if (base64[b & 0xff] != -1) - throw new IllegalArgumentException( - "Illegal base64 line separator character 0x" + Integer.toString(b, 16)); - } - if (lineLength <= 0) { - return Encoder.RFC4648; - } - return new Encoder(false, lineSeparator, lineLength >> 2 << 2, true); - } - - /** - * Returns a {@link Decoder} that decodes using the - * Basic type base64 encoding scheme. - * - * @return A Base64 decoder. - */ - public static Decoder getDecoder() { - return Decoder.RFC4648; - } - - /** - * Returns a {@link Decoder} that decodes using the - * URL and Filename safe type base64 - * encoding scheme. - * - * @return A Base64 decoder. - */ - public static Decoder getUrlDecoder() { - return Decoder.RFC4648_URLSAFE; - } - - /** - * Returns a {@link Decoder} that decodes using the - * MIME type base64 decoding scheme. - * - * @return A Base64 decoder. - */ - public static Decoder getMimeDecoder() { - return Decoder.RFC2045; - } - - /** - * This class implements an encoder for encoding byte data using - * the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. - * - *

Instances of {@link Encoder} class are safe for use by - * multiple concurrent threads. - * - *

Unless otherwise noted, passing a {@code null} argument to - * a method of this class will cause a - * {@link java.lang.NullPointerException NullPointerException} to - * be thrown. - * - * @see Decoder - * @since 1.8 - */ - public static class Encoder { - - private final byte[] newline; - private final int linemax; - private final boolean isURL; - private final boolean doPadding; - - private Encoder(boolean isURL, byte[] newline, int linemax, boolean doPadding) { - this.isURL = isURL; - this.newline = newline; - this.linemax = linemax; - this.doPadding = doPadding; - } - - /** - * This array is a lookup table that translates 6-bit positive integer - * index values into their "Base64 Alphabet" equivalents as specified - * in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). - */ - private static final char[] toBase64 = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' - }; - - /** - * It's the lookup table for "URL and Filename safe Base64" as specified - * in Table 2 of the RFC 4648, with the '+' and '/' changed to '-' and - * '_'. This table is used when BASE64_URL is specified. - */ - private static final char[] toBase64URL = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' - }; - - private static final int MIMELINEMAX = 76; - private static final byte[] CRLF = new byte[] {'\r', '\n'}; - - static final Encoder RFC4648 = new Encoder(false, null, -1, true); - static final Encoder RFC4648_URLSAFE = new Encoder(true, null, -1, true); - static final Encoder RFC2045 = new Encoder(false, CRLF, MIMELINEMAX, true); - - private final int outLength(int srclen) { - int len = 0; - if (doPadding) { - len = 4 * ((srclen + 2) / 3); - } else { - int n = srclen % 3; - len = 4 * (srclen / 3) + (n == 0 ? 0 : n + 1); - } - if (linemax > 0) // line separators - len += (len - 1) / linemax * newline.length; - return len; - } - - /** - * Encodes all bytes from the specified byte array into a newly-allocated - * byte array using the {@link Base64} encoding scheme. The returned byte - * array is of the length of the resulting bytes. - * - * @param src the byte array to encode - * @return A newly-allocated byte array containing the resulting encoded bytes. - */ - public byte[] encode(byte[] src) { - int len = outLength(src.length); // dst array size - byte[] dst = new byte[len]; - int ret = encode0(src, 0, src.length, dst); - if (ret != dst.length) - return Arrays.copyOf(dst, ret); - return dst; - } - - /** - * Encodes all bytes from the specified byte array using the - * {@link Base64} encoding scheme, writing the resulting bytes to the - * given output byte array, starting at offset 0. - * - *

It is the responsibility of the invoker of this method to make - * sure the output byte array {@code dst} has enough space for encoding - * all bytes from the input byte array. No bytes will be written to the - * output byte array if the output byte array is not big enough. - * - * @param src the byte array to encode - * @param dst the output byte array - * @return The number of bytes written to the output byte array - * @throws IllegalArgumentException if {@code dst} does not have enough space for encoding all input bytes. - */ - public int encode(byte[] src, byte[] dst) { - int len = outLength(src.length); // dst array size - if (dst.length < len) - throw new IllegalArgumentException( - "Output byte array is too small for encoding all input bytes"); - return encode0(src, 0, src.length, dst); - } - - /** - * Encodes the specified byte array into a String using the {@link Base64} - * encoding scheme. - * - *

This method first encodes all input bytes into a base64 encoded - * byte array and then constructs a new String by using the encoded byte - * array and the {@link StandardCharsets#ISO_8859_1 - * ISO-8859-1} charset. - * - *

In other words, an invocation of this method has exactly the same - * effect as invoking - * {@code new String(encode(src), StandardCharsets.ISO_8859_1)}. - * - * @param src the byte array to encode - * @return A String containing the resulting Base64 encoded characters - */ - @SuppressWarnings("deprecation") - public String encodeToString(byte[] src) { - byte[] encoded = encode(src); - return new String(encoded, 0, 0, encoded.length); - } - - /** - * Encodes all remaining bytes from the specified byte buffer into - * a newly-allocated ByteBuffer using the {@link Base64} encoding - * scheme. - * - * Upon return, the source buffer's position will be updated to - * its limit; its limit will not have been changed. The returned - * output buffer's position will be zero and its limit will be the - * number of resulting encoded bytes. - * - * @param buffer the source ByteBuffer to encode - * @return A newly-allocated byte buffer containing the encoded bytes. - */ - public ByteBuffer encode(ByteBuffer buffer) { - int len = outLength(buffer.remaining()); - byte[] dst = new byte[len]; - int ret = 0; - if (buffer.hasArray()) { - ret = encode0(buffer.array(), - buffer.arrayOffset() + buffer.position(), - buffer.arrayOffset() + buffer.limit(), - dst); - buffer.position(buffer.limit()); - } else { - byte[] src = new byte[buffer.remaining()]; - buffer.get(src); - ret = encode0(src, 0, src.length, dst); - } - if (ret != dst.length) - dst = Arrays.copyOf(dst, ret); - return ByteBuffer.wrap(dst); - } - - /** - * Wraps an output stream for encoding byte data using the {@link Base64} - * encoding scheme. - * - *

It is recommended to promptly close the returned output stream after - * use, during which it will flush all possible leftover bytes to the underlying - * output stream. Closing the returned output stream will close the underlying - * output stream. - * - * @param os the output stream. - * @return the output stream for encoding the byte data into the specified Base64 encoded format - */ - public OutputStream wrap(OutputStream os) { - Objects.requireNonNull(os); - return new EncOutputStream(os, isURL ? toBase64URL : toBase64, - newline, linemax, doPadding); - } - - /** - * Returns an encoder instance that encodes equivalently to this one, - * but without adding any padding character at the end of the encoded - * byte data. - * - *

The encoding scheme of this encoder instance is unaffected by - * this invocation. The returned encoder instance should be used for - * non-padding encoding operation. - * - * @return an equivalent encoder that encodes without adding any padding character at the end - */ - public Encoder withoutPadding() { - if (!doPadding) - return this; - return new Encoder(isURL, newline, linemax, false); - } - - private int encode0(byte[] src, int off, int end, byte[] dst) { - char[] base64 = isURL ? toBase64URL : toBase64; - int sp = off; - int slen = (end - off) / 3 * 3; - int sl = off + slen; - if (linemax > 0 && slen > linemax / 4 * 3) - slen = linemax / 4 * 3; - int dp = 0; - while (sp < sl) { - int sl0 = Math.min(sp + slen, sl); - for (int sp0 = sp, dp0 = dp; sp0 < sl0; ) { - int bits = (src[sp0++] & 0xff) << 16 | - (src[sp0++] & 0xff) << 8 | - (src[sp0++] & 0xff); - dst[dp0++] = (byte)base64[(bits >>> 18) & 0x3f]; - dst[dp0++] = (byte)base64[(bits >>> 12) & 0x3f]; - dst[dp0++] = (byte)base64[(bits >>> 6) & 0x3f]; - dst[dp0++] = (byte)base64[bits & 0x3f]; - } - int dlen = (sl0 - sp) / 3 * 4; - dp += dlen; - sp = sl0; - if (dlen == linemax && sp < end) { - for (byte b : newline) { - dst[dp++] = b; - } - } - } - if (sp < end) { // 1 or 2 leftover bytes - int b0 = src[sp++] & 0xff; - dst[dp++] = (byte)base64[b0 >> 2]; - if (sp == end) { - dst[dp++] = (byte)base64[(b0 << 4) & 0x3f]; - if (doPadding) { - dst[dp++] = PADDING_CHAR; - dst[dp++] = PADDING_CHAR; - } - } else { - int b1 = src[sp++] & 0xff; - dst[dp++] = (byte)base64[(b0 << 4) & 0x3f | (b1 >> 4)]; - dst[dp++] = (byte)base64[(b1 << 2) & 0x3f]; - if (doPadding) { - dst[dp++] = PADDING_CHAR; - } - } - } - return dp; - } - } - - /** - * This class implements a decoder for decoding byte data using the - * Base64 encoding scheme as specified in RFC 4648 and RFC 2045. - * - *

The Base64 padding character {@code PADDING_CHAR} is accepted and - * interpreted as the end of the encoded byte data, but is not - * required. So if the final unit of the encoded byte data only has - * two or three Base64 characters (without the corresponding padding - * character(s) padded), they are decoded as if followed by padding - * character(s). If there is a padding character present in the - * final unit, the correct number of padding character(s) must be - * present, otherwise {@code IllegalArgumentException} ( - * {@code IOException} when reading from a Base64 stream) is thrown - * during decoding. - * - *

Instances of {@link Decoder} class are safe for use by - * multiple concurrent threads. - * - *

Unless otherwise noted, passing a {@code null} argument to - * a method of this class will cause a - * {@link java.lang.NullPointerException NullPointerException} to - * be thrown. - * - * @see Encoder - * @since 1.8 - */ - public static class Decoder { - - private final boolean isURL; - private final boolean isMIME; - - private Decoder(boolean isURL, boolean isMIME) { - this.isURL = isURL; - this.isMIME = isMIME; - } - - /** - * Lookup table for decoding unicode characters drawn from the - * "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into - * their 6-bit positive integer equivalents. Characters that - * are not in the Base64 alphabet but fall within the bounds of - * the array are encoded to -1. - */ - private static final int[] fromBase64 = new int[256]; - - static { - Arrays.fill(fromBase64, -1); - for (int i = 0; i < Encoder.toBase64.length; i++) - fromBase64[Encoder.toBase64[i]] = i; - fromBase64[PADDING_CHAR] = -2; - } - - /** - * Lookup table for decoding "URL and Filename safe Base64 Alphabet" - * as specified in Table2 of the RFC 4648. - */ - private static final int[] fromBase64URL = new int[256]; - - static { - Arrays.fill(fromBase64URL, -1); - for (int i = 0; i < Encoder.toBase64URL.length; i++) - fromBase64URL[Encoder.toBase64URL[i]] = i; - fromBase64URL[PADDING_CHAR] = -2; - } - - static final Decoder RFC4648 = new Decoder(false, false); - static final Decoder RFC4648_URLSAFE = new Decoder(true, false); - static final Decoder RFC2045 = new Decoder(false, true); - - /** - * Decodes all bytes from the input byte array using the {@link Base64} - * encoding scheme, writing the results into a newly-allocated output - * byte array. The returned byte array is of the length of the resulting - * bytes. - * - * @param src the byte array to decode - * @return A newly-allocated byte array containing the decoded bytes. - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme - */ - public byte[] decode(byte[] src) { - byte[] dst = new byte[outLength(src, 0, src.length)]; - int ret = decode0(src, 0, src.length, dst); - if (ret != dst.length) { - dst = Arrays.copyOf(dst, ret); - } - return dst; - } - - /** - * Decodes a Base64 encoded String into a newly-allocated byte array - * using the {@link Base64} encoding scheme. - * - *

An invocation of this method has exactly the same effect as invoking - * {@code decode(src.getBytes(StandardCharsets.ISO_8859_1))} - * - * @param src the string to decode - * @return A newly-allocated byte array containing the decoded bytes. - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme - */ - public byte[] decode(String src) { - return decode(src.getBytes(StandardCharsets.ISO_8859_1)); - } - - /** - * Decodes all bytes from the input byte array using the {@link Base64} - * encoding scheme, writing the results into the given output byte array, - * starting at offset 0. - * - *

It is the responsibility of the invoker of this method to make - * sure the output byte array {@code dst} has enough space for decoding - * all bytes from the input byte array. No bytes will be be written to - * the output byte array if the output byte array is not big enough. - * - *

If the input byte array is not in valid Base64 encoding scheme - * then some bytes may have been written to the output byte array before - * IllegalargumentException is thrown. - * - * @param src the byte array to decode - * @param dst the output byte array - * @return The number of bytes written to the output byte array - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme, or {@code dst} does not have - * enough space for decoding all input bytes. - */ - public int decode(byte[] src, byte[] dst) { - int len = outLength(src, 0, src.length); - if (dst.length < len) - throw new IllegalArgumentException( - "Output byte array is too small for decoding all input bytes"); - return decode0(src, 0, src.length, dst); - } - - /** - * Decodes all bytes from the input byte buffer using the {@link Base64} - * encoding scheme, writing the results into a newly-allocated ByteBuffer. - * - *

Upon return, the source buffer's position will be updated to - * its limit; its limit will not have been changed. The returned - * output buffer's position will be zero and its limit will be the - * number of resulting decoded bytes - * - *

{@code IllegalArgumentException} is thrown if the input buffer - * is not in valid Base64 encoding scheme. The position of the input - * buffer will not be advanced in this case. - * - * @param buffer the ByteBuffer to decode - * @return A newly-allocated byte buffer containing the decoded bytes - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme. - */ - public ByteBuffer decode(ByteBuffer buffer) { - int pos0 = buffer.position(); - try { - byte[] src; - int sp, sl; - if (buffer.hasArray()) { - src = buffer.array(); - sp = buffer.arrayOffset() + buffer.position(); - sl = buffer.arrayOffset() + buffer.limit(); - buffer.position(buffer.limit()); - } else { - src = new byte[buffer.remaining()]; - buffer.get(src); - sp = 0; - sl = src.length; - } - byte[] dst = new byte[outLength(src, sp, sl)]; - return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst)); - } catch (IllegalArgumentException iae) { - buffer.position(pos0); - throw iae; - } - } - - /** - * Returns an input stream for decoding {@link Base64} encoded byte stream. - * - *

The {@code read} methods of the returned {@code InputStream} will - * throw {@code IOException} when reading bytes that cannot be decoded. - * - *

Closing the returned input stream will close the underlying - * input stream. - * - * @param is the input stream - * @return the input stream for decoding the specified Base64 encoded byte stream - */ - public InputStream wrap(InputStream is) { - Objects.requireNonNull(is); - return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME); - } - - private int outLength(byte[] src, int sp, int sl) { - int[] base64 = isURL ? fromBase64URL : fromBase64; - int paddings = 0; - int len = sl - sp; - if (len == 0) - return 0; - if (len < 2) { - if (isMIME && base64[0] == -1) - return 0; - throw new IllegalArgumentException( - "Input byte[] should at least have 2 bytes for base64 bytes"); - } - if (isMIME) { - // scan all bytes to fill out all non-alphabet. a performance - // trade-off of pre-scan or Arrays.copyOf - int n = 0; - while (sp < sl) { - int b = src[sp++] & 0xff; - if (b == PADDING_CHAR) { - len -= (sl - sp + 1); - break; - } - if ((b = base64[b]) == -1) - n++; - } - len -= n; - } else { - if (src[sl - 1] == PADDING_CHAR) { - paddings++; - if (src[sl - 2] == PADDING_CHAR) - paddings++; - } - } - if (paddings == 0 && (len & 0x3) != 0) - paddings = 4 - (len & 0x3); - return 3 * ((len + 3) / 4) - paddings; - } - - private int decode0(byte[] src, int sp, int sl, byte[] dst) { - int[] base64 = isURL ? fromBase64URL : fromBase64; - int dp = 0; - int bits = 0; - int shiftto = 18; // pos of first byte of 4-byte atom - while (sp < sl) { - int b = src[sp++] & 0xff; - if ((b = base64[b]) < 0) { - if (b == -2) { // padding byte PADDING_CHAR - // = shiftto==18 unnecessary padding - // x= shiftto==12 a dangling single x - // x to be handled together with non-padding case - // xx= shiftto==6&&sp==sl missing last = - // xx=y shiftto==6 last is not = - if (shiftto == 6 && (sp == sl || src[sp++] != PADDING_CHAR) || - shiftto == 18) { - throw new IllegalArgumentException( - "Input byte array has wrong 4-byte ending unit"); - } - break; - } - if (isMIME) // skip if for rfc2045 - continue; - else - throw new IllegalArgumentException( - "Illegal base64 character " + - Integer.toString(src[sp - 1], 16)); - } - bits |= (b << shiftto); - shiftto -= 6; - if (shiftto < 0) { - dst[dp++] = (byte)(bits >> 16); - dst[dp++] = (byte)(bits >> 8); - dst[dp++] = (byte)(bits); - shiftto = 18; - bits = 0; - } - } - // reached end of byte array or hit padding PADDING_CHAR characters. - if (shiftto == 6) { - dst[dp++] = (byte)(bits >> 16); - } else if (shiftto == 0) { - dst[dp++] = (byte)(bits >> 16); - dst[dp++] = (byte)(bits >> 8); - } else if (shiftto == 12) { - // dangling single "x", incorrectly encoded. - throw new IllegalArgumentException( - "Last unit does not have enough valid bits"); - } - // anything left is invalid, if is not MIME. - // if MIME, ignore all non-base64 character - while (sp < sl) { - if (isMIME && base64[src[sp++]] < 0) - continue; - throw new IllegalArgumentException( - "Input byte array has incorrect ending byte at " + sp); - } - return dp; - } - } - - /* - * An output stream for encoding bytes into the Base64. - */ - private static class EncOutputStream extends FilterOutputStream { - - private int leftover = 0; - private int b0, b1, b2; - private boolean closed = false; - - private final char[] base64; // byte->base64 mapping - private final byte[] newline; // line separator, if needed - private final int linemax; - private final boolean doPadding;// whether or not to pad - private int linepos = 0; - - EncOutputStream(OutputStream os, char[] base64, - byte[] newline, int linemax, boolean doPadding) { - super(os); - this.base64 = base64; - this.newline = newline; - this.linemax = linemax; - this.doPadding = doPadding; - } - - @Override - public void write(int b) throws IOException { - byte[] buf = new byte[1]; - buf[0] = (byte)(b & 0xff); - write(buf, 0, 1); - } - - private void checkNewline() throws IOException { - if (linepos == linemax) { - out.write(newline); - linepos = 0; - } - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - if (closed) - throw new IOException("Stream is closed"); - if (off < 0 || len < 0 || len > b.length - off) - throw new ArrayIndexOutOfBoundsException(); - if (len == 0) - return; - if (leftover != 0) { - if (leftover == 1) { - b1 = b[off++] & 0xff; - len--; - if (len == 0) { - leftover++; - return; - } - } - b2 = b[off++] & 0xff; - len--; - checkNewline(); - out.write(base64[b0 >> 2]); - out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); - out.write(base64[(b1 << 2) & 0x3f | (b2 >> 6)]); - out.write(base64[b2 & 0x3f]); - linepos += 4; - } - int nBits24 = len / 3; - leftover = len - (nBits24 * 3); - while (nBits24-- > 0) { - checkNewline(); - int bits = (b[off++] & 0xff) << 16 | - (b[off++] & 0xff) << 8 | - (b[off++] & 0xff); - out.write(base64[(bits >>> 18) & 0x3f]); - out.write(base64[(bits >>> 12) & 0x3f]); - out.write(base64[(bits >>> 6) & 0x3f]); - out.write(base64[bits & 0x3f]); - linepos += 4; - } - if (leftover == 1) { - b0 = b[off++] & 0xff; - } else if (leftover == 2) { - b0 = b[off++] & 0xff; - b1 = b[off++] & 0xff; - } - } - - @Override - public void close() throws IOException { - if (!closed) { - closed = true; - if (leftover == 1) { - checkNewline(); - out.write(base64[b0 >> 2]); - out.write(base64[(b0 << 4) & 0x3f]); - if (doPadding) { - out.write(PADDING_CHAR); - out.write(PADDING_CHAR); - } - } else if (leftover == 2) { - checkNewline(); - out.write(base64[b0 >> 2]); - out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); - out.write(base64[(b1 << 2) & 0x3f]); - if (doPadding) { - out.write(PADDING_CHAR); - } - } - leftover = 0; - out.close(); - } - } - } - - /* - * An input stream for decoding Base64 bytes - */ - private static class DecInputStream extends InputStream { - - private final InputStream is; - private final boolean isMIME; - private final int[] base64; // base64 -> byte mapping - private int bits = 0; // 24-bit buffer for decoding - private int nextin = 18; // next available "off" in "bits" for input; - // -> 18, 12, 6, 0 - private int nextout = -8; // next available "off" in "bits" for output; - // -> 8, 0, -8 (no byte for output) - private boolean eof = false; - private boolean closed = false; - - DecInputStream(InputStream is, int[] base64, boolean isMIME) { - this.is = is; - this.base64 = base64; - this.isMIME = isMIME; - } - - private byte[] sbBuf = new byte[1]; - - @Override - public int read() throws IOException { - return read(sbBuf, 0, 1) == -1 ? -1 : sbBuf[0] & 0xff; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - if (closed) - throw new IOException("Stream is closed"); - if (eof && nextout < 0) // eof and no leftover - return -1; - if (off < 0 || len < 0 || len > b.length - off) - throw new IndexOutOfBoundsException(); - int oldOff = off; - if (nextout >= 0) { // leftover output byte(s) in bits buf - do { - if (len == 0) - return off - oldOff; - b[off++] = (byte)(bits >> nextout); - len--; - nextout -= 8; - } - while (nextout >= 0); - bits = 0; - } - while (len > 0) { - int v = is.read(); - if (v == -1) { - eof = true; - if (nextin != 18) { - if (nextin == 12) - throw new IOException("Base64 stream has one un-decoded dangling byte."); - // treat ending xx/xxx without padding character legal. - // same logic as v == PADDING_CHAR below - b[off++] = (byte)(bits >> (16)); - len--; - if (nextin == 0) { // only one padding byte - if (len == 0) { // no enough output space - bits >>= 8; // shift to lowest byte - nextout = 0; - } else { - b[off++] = (byte)(bits >> 8); - } - } - } - if (off == oldOff) - return -1; - else - return off - oldOff; - } - if (v == PADDING_CHAR) { // padding byte(s) - // = shiftto==18 unnecessary padding - // x= shiftto==12 dangling x, invalid unit - // xx= shiftto==6 && missing last PADDING_CHAR - // xx=y or last is not PADDING_CHAR - if (nextin == 18 || nextin == 12 || - nextin == 6 && is.read() != PADDING_CHAR) { - throw new IOException("Illegal base64 ending sequence:" + nextin); - } - b[off++] = (byte)(bits >> (16)); - len--; - if (nextin == 0) { // only one padding byte - if (len == 0) { // no enough output space - bits >>= 8; // shift to lowest byte - nextout = 0; - } else { - b[off++] = (byte)(bits >> 8); - } - } - eof = true; - break; - } - if ((v = base64[v]) == -1) { - if (isMIME) // skip if for rfc2045 - continue; - else - throw new IOException("Illegal base64 character " + - Integer.toString(v, 16)); - } - bits |= (v << nextin); - if (nextin == 0) { - nextin = 18; // clear for next - nextout = 16; - while (nextout >= 0) { - b[off++] = (byte)(bits >> nextout); - len--; - nextout -= 8; - if (len == 0 && nextout >= 0) { // don't clean "bits" - return off - oldOff; - } - } - bits = 0; - } else { - nextin -= 6; - } - } - return off - oldOff; - } - - @Override - public int available() throws IOException { - if (closed) - throw new IOException("Stream is closed"); - return is.available(); // TBD: - } - - @Override - public void close() throws IOException { - if (!closed) { - closed = true; - is.close(); - } - } - } - - /** - * This is a tiny adjustment for BASE64 encode and decode. - * I replace the padding char of base64 to '*' from '='. - * - * We found that the dubbox's head didn't support '=' as a part of value. :( - */ - private static byte PADDING_CHAR = '*'; - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Objects.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Objects.java deleted file mode 100644 index 9e866c274ec8..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Objects.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids.base64; - -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -/** - * This class consists of {@code static} utility methods for operating - * on objects. These utilities include {@code null}-safe or {@code - * null}-tolerant methods for computing the hash code of an object, - * returning a string for an object, and comparing two objects. - * - * @since 1.7 - */ -public final class Objects { - private Objects() { - throw new AssertionError("No java.util.Objects instances for you!"); - } - - /** - * Returns {@code true} if the arguments are equal to each other - * and {@code false} otherwise. - * Consequently, if both arguments are {@code null}, {@code true} - * is returned and if exactly one argument is {@code null}, {@code - * false} is returned. Otherwise, equality is determined by using - * the {@link Object#equals equals} method of the first - * argument. - * - * @param a an object - * @param b an object to be compared with {@code a} for equality - * @return {@code true} if the arguments are equal to each other and {@code false} otherwise - * @see Object#equals(Object) - */ - public static boolean equals(Object a, Object b) { - return (a == b) || (a != null && a.equals(b)); - } - - /** - * Returns the hash code of a non-{@code null} argument and 0 for - * a {@code null} argument. - * - * @param o an object - * @return the hash code of a non-{@code null} argument and 0 for a {@code null} argument - * @see Object#hashCode - */ - public static int hashCode(Object o) { - return o != null ? o.hashCode() : 0; - } - - /** - * Generates a hash code for a sequence of input values. The hash - * code is generated as if all the input values were placed into an - * array, and that array were hashed by calling {@link - * Arrays#hashCode(Object[])}. - * - *

This method is useful for implementing {@link - * Object#hashCode()} on objects containing multiple fields. For - * example, if an object that has three fields, {@code x}, {@code - * y}, and {@code z}, one could write: - * - *

-     * @Override public int hashCode() {
-     *     return Objects.hash(x, y, z);
-     * }
-     * 
- * - * Warning: When a single object reference is supplied, the returned - * value does not equal the hash code of that object reference. This - * value can be computed by calling {@link #hashCode(Object)}. - * - * @param values the values to be hashed - * @return a hash value of the sequence of input values - * @see Arrays#hashCode(Object[]) - * @see List#hashCode - */ - public static int hash(Object... values) { - return Arrays.hashCode(values); - } - - /** - * Returns the result of calling {@code toString} for a non-{@code - * null} argument and {@code "null"} for a {@code null} argument. - * - * @param o an object - * @return the result of calling {@code toString} for a non-{@code null} argument and {@code "null"} for a {@code - * null} argument - * @see Object#toString - * @see String#valueOf(Object) - */ - public static String toString(Object o) { - return String.valueOf(o); - } - - /** - * Returns the result of calling {@code toString} on the first - * argument if the first argument is not {@code null} and returns - * the second argument otherwise. - * - * @param o an object - * @param nullDefault string to return if the first argument is {@code null} - * @return the result of calling {@code toString} on the first argument if it is not {@code null} and the second - * argument otherwise. - */ - public static String toString(Object o, String nullDefault) { - return (o != null) ? o.toString() : nullDefault; - } - - /** - * Returns 0 if the arguments are identical and {@code - * c.compare(a, b)} otherwise. - * Consequently, if both arguments are {@code null} 0 - * is returned. - * - *

Note that if one of the arguments is {@code null}, a {@code - * NullPointerException} may or may not be thrown depending on - * what ordering policy, if any, the {@link Comparator Comparator} - * chooses to have for {@code null} values. - * - * @param the type of the objects being compared - * @param a an object - * @param b an object to be compared with {@code a} - * @param c the {@code Comparator} to compare the first two arguments - * @return 0 if the arguments are identical and {@code c.compare(a, b)} otherwise. - * @see Comparable - * @see Comparator - */ - public static int compare(T a, T b, Comparator c) { - return (a == b) ? 0 : c.compare(a, b); - } - - /** - * Checks that the specified object reference is not {@code null}. This - * method is designed primarily for doing parameter validation in methods - * and constructors, as demonstrated below: - *

-     * public Foo(Bar bar) {
-     *     this.bar = Objects.requireNonNull(bar);
-     * }
-     * 
- * - * @param obj the object reference to check for nullity - * @param the type of the reference - * @return {@code obj} if not {@code null} - * @throws NullPointerException if {@code obj} is {@code null} - */ - public static T requireNonNull(T obj) { - if (obj == null) - throw new NullPointerException(); - return obj; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/StandardCharsets.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/StandardCharsets.java deleted file mode 100644 index 3fb20b782cdb..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/StandardCharsets.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.ids.base64; - -import java.nio.charset.Charset; - -/** - * Constant definitions for the standard {@link Charset Charsets}. These - * charsets are guaranteed to be available on every implementation of the Java - * platform. - * - * @see Standard Charsets - * @since 1.7 - */ -public final class StandardCharsets { - - private StandardCharsets() { - throw new AssertionError("No java.nio.charset.StandardCharsets instances for you!"); - } - - /** - * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the - * Unicode character set - */ - public static final Charset US_ASCII = Charset.forName("US-ASCII"); - /** - * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1 - */ - public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); - /** - * Eight-bit UCS Transformation Format - */ - public static final Charset UTF_8 = Charset.forName("UTF-8"); - /** - * Sixteen-bit UCS Transformation Format, big-endian byte order - */ - public static final Charset UTF_16BE = Charset.forName("UTF-16BE"); - /** - * Sixteen-bit UCS Transformation Format, little-endian byte order - */ - public static final Charset UTF_16LE = Charset.forName("UTF-16LE"); - /** - * Sixteen-bit UCS Transformation Format, byte order identified by an - * optional byte-order mark - */ - public static final Charset UTF_16 = Charset.forName("UTF-16"); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/AbstractTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/AbstractTag.java deleted file mode 100644 index a4e812ea41f0..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/AbstractTag.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.tag; - -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; - -public abstract class AbstractTag { - /** - * The key of this Tag. - */ - protected final String key; - - public AbstractTag(String tagKey) { - this.key = tagKey; - } - - protected abstract void set(AbstractSpan span, T tagValue); - - /** - * @return the key of this tag. - */ - public String key() { - return this.key; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java deleted file mode 100644 index 0b93c11a3753..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.tag; - -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; - -/** - * A subclass of {@link AbstractTag}, - * represent a tag with a {@link String} value. - *

- * Created by wusheng on 2017/2/17. - */ -public class StringTag extends AbstractTag { - public StringTag(String tagKey) { - super(tagKey); - } - - @Override - public void set(AbstractSpan span, String tagValue) { - span.tag(key, tagValue); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java deleted file mode 100644 index 81c1547e9eb8..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.tag; - -/** - * The span tags are supported by sky-walking engine. - * As default, all tags will be stored, but these ones have particular meanings. - *

- * Created by wusheng on 2017/2/17. - */ -public final class Tags { - private Tags() { - } - - /** - * URL records the url of the incoming request. - */ - public static final StringTag URL = new StringTag("url"); - - /** - * STATUS_CODE records the http status code of the response. - */ - public static final StringTag STATUS_CODE = new StringTag("status_code"); - - /** - * DB_TYPE records database type, such as sql, redis, cassandra and so on. - */ - public static final StringTag DB_TYPE = new StringTag("db.type"); - - /** - * DB_INSTANCE records database instance name. - */ - public static final StringTag DB_INSTANCE = new StringTag("db.instance"); - - /** - * DB_STATEMENT records the sql statement of the database access. - */ - public static final StringTag DB_STATEMENT = new StringTag("db.statement"); - - /** - * DB_BIND_VARIABLES records the bind variables of sql statement. - */ - public static final StringTag DB_BIND_VARIABLES = new StringTag("db.bind_vars"); - - public static final class HTTP { - public static final StringTag METHOD = new StringTag("http.method"); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java deleted file mode 100644 index aa6bc4ed463b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -import java.util.Map; -import org.skywalking.apm.network.trace.component.Component; - -/** - * The AbstractSpan represents the span's skeleton, which contains all open methods. - * - * @author wusheng - */ -public interface AbstractSpan { - /** - * Set the component id, which defines in {@link org.skywalking.apm.network.trace.component.ComponentsDefine} - * - * @param component - * @return the span for chaining. - */ - AbstractSpan setComponent(Component component); - - /** - * Only use this method in explicit instrumentation, like opentracing-skywalking-bridge. It it higher recommend - * don't use this for performance consideration. - * - * @param componentName - * @return the span for chaining. - */ - AbstractSpan setComponent(String componentName); - - AbstractSpan setLayer(SpanLayer layer); - - /** - * Set a key:value tag on the Span. - * - * @return this Span instance, for chaining - */ - AbstractSpan tag(String key, String value); - - /** - * Record an exception event of the current walltime timestamp. - * - * @param t any subclass of {@link Throwable}, which occurs in this span. - * @return the Span, for chaining - */ - AbstractSpan log(Throwable t); - - AbstractSpan errorOccurred(); - - /** - * @return true if the actual span is an entry span. - */ - boolean isEntry(); - - /** - * @return true if the actual span is an exit span. - */ - boolean isExit(); - - /** - * Record an event at a specific timestamp. - * - * @param timestamp The explicit timestamp for the log record. - * @param event the events - * @return the Span, for chaining - */ - AbstractSpan log(long timestamp, Map event); - - /** - * Sets the string name for the logical operation this span represents. - * - * @return this Span instance, for chaining - */ - AbstractSpan setOperationName(String operationName); - - /** - * Start a span. - * - * @return this Span instance, for chaining - */ - AbstractSpan start(); - - /** - * Get the id of span - * - * @return id value. - */ - int getSpanId(); - - int getOperationId(); - - String getOperationName(); - - AbstractSpan setOperationId(int operationId); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java deleted file mode 100644 index 8c649d8ae396..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -/** - * The LocalSpan represents a normal tracing point, such as a local method. - * - * @author wusheng - */ -public class LocalSpan extends AbstractTracingSpan { - - public LocalSpan(int spanId, int parentSpanId, int operationId) { - super(spanId, parentSpanId, operationId); - } - - public LocalSpan(int spanId, int parentSpanId, String operationName) { - super(spanId, parentSpanId, operationName); - } - - @Override - public LocalSpan tag(String key, String value) { - super.tag(key, value); - return this; - } - - @Override - public LocalSpan log(Throwable t) { - super.log(t); - return this; - } - - @Override public boolean isEntry() { - return false; - } - - @Override public boolean isExit() { - return false; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java deleted file mode 100644 index 2fbf2a63e26b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.network.proto.LogMessage; - -/** - * The LogDataEntity represents a collection of {@link KeyValuePair}, - * contains several fields of a logging operation. - * - * @author wusheng - */ -public class LogDataEntity { - private long timestamp = 0; - private List logs; - - private LogDataEntity(long timestamp, List logs) { - this.timestamp = timestamp; - this.logs = logs; - } - - public List getLogs() { - return logs; - } - - public static class Builder { - protected List logs; - - public Builder() { - logs = new LinkedList(); - } - - public Builder add(KeyValuePair... fields) { - for (KeyValuePair field : fields) { - logs.add(field); - } - return this; - } - - public LogDataEntity build(long timestamp) { - return new LogDataEntity(timestamp, logs); - } - } - - public LogMessage transform() { - LogMessage.Builder logMessageBuilder = LogMessage.newBuilder(); - for (KeyValuePair log : logs) { - logMessageBuilder.addData(log.transform()); - } - logMessageBuilder.setTime(timestamp); - return logMessageBuilder.build(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopExitSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopExitSpan.java deleted file mode 100644 index 4890593c4fd8..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopExitSpan.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -public class NoopExitSpan extends NoopSpan implements WithPeerInfo { - - private String peer; - private int peerId; - - public NoopExitSpan(int peerId) { - this.peerId = peerId; - } - - public NoopExitSpan(String peer) { - this.peer = peer; - } - - @Override - public int getPeerId() { - return peerId; - } - - @Override - public String getPeer() { - return peer; - } - - @Override - public boolean isExit() { - return true; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java deleted file mode 100644 index ade33f06071c..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -import java.util.Map; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.network.trace.component.Component; - -/** - * The NoopSpan represents a span implementation without any actual operation. - * This span implementation is for {@link IgnoredTracerContext}, - * for keeping the memory and gc cost as low as possible. - * - * @author wusheng - */ -public class NoopSpan implements AbstractSpan { - public NoopSpan() { - } - - @Override - public AbstractSpan log(Throwable t) { - return this; - } - - @Override public AbstractSpan errorOccurred() { - return this; - } - - public void finish() { - - } - - @Override public AbstractSpan setComponent(Component component) { - return this; - } - - @Override public AbstractSpan setComponent(String componentName) { - return this; - } - - @Override public AbstractSpan setLayer(SpanLayer layer) { - return this; - } - - @Override - public AbstractSpan tag(String key, String value) { - return this; - } - - @Override public boolean isEntry() { - return false; - } - - @Override public boolean isExit() { - return false; - } - - @Override public AbstractSpan log(long timestamp, Map event) { - return this; - } - - @Override public AbstractSpan setOperationName(String operationName) { - return this; - } - - @Override public AbstractSpan start() { - return this; - } - - @Override public int getSpanId() { - return 0; - } - - @Override public int getOperationId() { - return 0; - } - - @Override public String getOperationName() { - return ""; - } - - @Override public AbstractSpan setOperationId(int operationId) { - return this; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/SpanLayer.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/SpanLayer.java deleted file mode 100644 index 4e1f98643b39..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/SpanLayer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -/** - * @author wusheng - */ -public enum SpanLayer { - DB(1), - RPC_FRAMEWORK(2), - HTTP(3), - MQ(4); - - private int code; - - SpanLayer(int code) { - this.code = code; - } - - public int getCode() { - return code; - } - - public static void asDB(AbstractSpan span) { - span.setLayer(SpanLayer.DB); - } - - public static void asRPCFramework(AbstractSpan span) { - span.setLayer(SpanLayer.RPC_FRAMEWORK); - } - - public static void asHttp(AbstractSpan span) { - span.setLayer(SpanLayer.HTTP); - } - - public static void asMQ(AbstractSpan span) { - span.setLayer(SpanLayer.MQ); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java deleted file mode 100644 index 005383ce1196..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -import org.skywalking.apm.agent.core.dictionary.DictionaryManager; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.agent.core.dictionary.PossibleFound; - -/** - * The StackBasedTracingSpan represents a span with an inside stack construction. - * - * This kind of span can start and finish multi times in a stack-like invoke line. - * - * @author wusheng - */ -public abstract class StackBasedTracingSpan extends AbstractTracingSpan { - protected int stackDepth; - - protected StackBasedTracingSpan(int spanId, int parentSpanId, String operationName) { - super(spanId, parentSpanId, operationName); - this.stackDepth = 0; - } - - protected StackBasedTracingSpan(int spanId, int parentSpanId, int operationId) { - super(spanId, parentSpanId, operationId); - this.stackDepth = 0; - } - - @Override - public boolean finish(TraceSegment owner) { - if (--stackDepth == 0) { - if (this.operationId == DictionaryUtil.nullValue()) { - this.operationId = (Integer)DictionaryManager.findOperationNameCodeSection() - .findOrPrepare4Register(owner.getApplicationId(), operationName) - .doInCondition( - new PossibleFound.FoundAndObtain() { - @Override public Object doProcess(int value) { - return value; - } - }, - new PossibleFound.NotFoundAndObtain() { - @Override public Object doProcess() { - return DictionaryUtil.nullValue(); - } - } - ); - } - return super.finish(owner); - } else { - return false; - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java deleted file mode 100644 index fd4c3f6d174e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.ids.DistributedTraceId; -import org.skywalking.apm.agent.core.context.ids.DistributedTraceIds; -import org.skywalking.apm.agent.core.context.ids.GlobalIdGenerator; -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.context.ids.NewDistributedTraceId; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.proto.UpstreamSegment; - -/** - * {@link TraceSegment} is a segment or fragment of the distributed trace. {@see https://github.com/opentracing/specification/blob/master/specification.md#the-opentracing-data-model} - * A {@link TraceSegment} means the segment, which exists in current {@link Thread}. And the distributed trace is formed - * by multi {@link TraceSegment}s, because the distributed trace crosses multi-processes, multi-threads.

- * - * @author wusheng - */ -public class TraceSegment { - /** - * The id of this trace segment. Every segment has its unique-global-id. - */ - private ID traceSegmentId; - - /** - * The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one - * element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment, - * we use this {@link #refs} to link them. - * - * This field will not be serialized. Keeping this field is only for quick accessing. - */ - private List refs; - - /** - * The spans belong to this trace segment. They all have finished. All active spans are hold and controlled by - * "skywalking-api" module. - */ - private List spans; - - /** - * The relatedGlobalTraces represent a set of all related trace. Most time it contains only one - * element, because only one parent {@link TraceSegment} exists, but, in batch scenario, the num becomes greater - * than 1, also meaning multi-parents {@link TraceSegment}.

The difference between - * relatedGlobalTraces and {@link #refs} is: {@link #refs} targets this {@link TraceSegment}'s direct - * parent,

and

relatedGlobalTraces targets this {@link TraceSegment}'s related call chain, a - * call chain contains multi {@link TraceSegment}s, only using {@link #refs} is not enough for analysis and ui. - */ - private DistributedTraceIds relatedGlobalTraces; - - private boolean ignore = false; - - private boolean isSizeLimited = false; - - /** - * Create a default/empty trace segment, with current time as start time, and generate a new segment id. - */ - public TraceSegment() { - this.traceSegmentId = GlobalIdGenerator.generate(); - this.spans = new LinkedList(); - this.relatedGlobalTraces = new DistributedTraceIds(); - this.relatedGlobalTraces.append(new NewDistributedTraceId()); - } - - /** - * Establish the link between this segment and its parents. - * - * @param refSegment {@link TraceSegmentRef} - */ - public void ref(TraceSegmentRef refSegment) { - if (refs == null) { - refs = new LinkedList(); - } - if (!refs.contains(refSegment)) { - refs.add(refSegment); - } - } - - /** - * Establish the line between this segment and all relative global trace ids. - */ - public void relatedGlobalTraces(DistributedTraceId distributedTraceId) { - relatedGlobalTraces.append(distributedTraceId); - } - - /** - * After {@link AbstractSpan} is finished, as be controller by "skywalking-api" module, notify the {@link - * TraceSegment} to archive it. - * - * @param finishedSpan - */ - public void archive(AbstractTracingSpan finishedSpan) { - spans.add(finishedSpan); - } - - /** - * Finish this {@link TraceSegment}.

return this, for chaining - */ - public TraceSegment finish(boolean isSizeLimited) { - this.isSizeLimited = isSizeLimited; - return this; - } - - public ID getTraceSegmentId() { - return traceSegmentId; - } - - public int getApplicationId() { - return RemoteDownstreamConfig.Agent.APPLICATION_ID; - } - - public boolean hasRef() { - return !(refs == null || refs.size() == 0); - } - - public List getRefs() { - return refs; - } - - public List getRelatedGlobalTraces() { - return relatedGlobalTraces.getRelatedGlobalTraces(); - } - - public boolean isSingleSpanSegment() { - return this.spans != null && this.spans.size() == 1; - } - - public boolean isIgnore() { - return ignore; - } - - public void setIgnore(boolean ignore) { - this.ignore = ignore; - } - - /** - * This is a high CPU cost method, only called when sending to collector or test cases. - * - * @return the segment as GRPC service parameter - */ - public UpstreamSegment transform() { - UpstreamSegment.Builder upstreamBuilder = UpstreamSegment.newBuilder(); - for (DistributedTraceId distributedTraceId : getRelatedGlobalTraces()) { - upstreamBuilder = upstreamBuilder.addGlobalTraceIds(distributedTraceId.toUniqueId()); - } - TraceSegmentObject.Builder traceSegmentBuilder = TraceSegmentObject.newBuilder(); - /** - * Trace Segment - */ - traceSegmentBuilder.setTraceSegmentId(this.traceSegmentId.transform()); - // Don't serialize TraceSegmentReference - - // SpanObject - for (AbstractTracingSpan span : this.spans) { - traceSegmentBuilder.addSpans(span.transform()); - } - traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID); - traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID); - traceSegmentBuilder.setIsSizeLimited(this.isSizeLimited); - - upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString()); - return upstreamBuilder.build(); - } - - @Override - public String toString() { - return "TraceSegment{" + - "traceSegmentId='" + traceSegmentId + '\'' + - ", refs=" + refs + - ", spans=" + spans + - ", relatedGlobalTraces=" + relatedGlobalTraces + - '}'; - } - - public int getApplicationInstanceId() { - return RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java deleted file mode 100644 index d733aebef21a..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.trace; - -/** - * @author wusheng - */ -public interface WithPeerInfo { - int getPeerId(); - - String getPeer(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java deleted file mode 100644 index 858fcb054117..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -import org.skywalking.apm.network.proto.KeyWithStringValue; - -/** - * The KeyValuePair represents a object which contains a string key and a string value. - * - * @author wusheng - */ -public class KeyValuePair { - private String key; - private String value; - - public KeyValuePair(String key, String value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public String getValue() { - return value; - } - - public KeyWithStringValue transform() { - KeyWithStringValue.Builder keyValueBuilder = KeyWithStringValue.newBuilder(); - keyValueBuilder.setKey(key); - if (value != null) { - keyValueBuilder.setValue(value); - } - return keyValueBuilder.build(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/ThrowableTransformer.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/ThrowableTransformer.java deleted file mode 100644 index 5899c1e2fa79..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/ThrowableTransformer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -/** - * {@link ThrowableTransformer} is responsible for transferring stack trace of throwable. - */ -public enum ThrowableTransformer { - INSTANCE; - - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - - public String convert2String(Throwable throwable, final int maxLength) { - final StringBuilder stackMessage = new StringBuilder(); - Throwable causeException = throwable; - while (causeException != null) { - stackMessage.append(printExceptionInfo(causeException)); - - boolean overMaxLength = printStackElement(throwable.getStackTrace(), new AppendListener() { - public void append(String value) { - stackMessage.append(value); - } - - public boolean overMaxLength() { - return stackMessage.length() > maxLength; - } - }); - - if (overMaxLength) { - break; - } - - causeException = throwable.getCause(); - } - - return stackMessage.toString(); - } - - private String printExceptionInfo(Throwable causeException) { - return causeException.toString() + LINE_SEPARATOR; - } - - private boolean printStackElement(StackTraceElement[] stackTrace, AppendListener printListener) { - for (StackTraceElement traceElement : stackTrace) { - printListener.append("at " + traceElement + LINE_SEPARATOR); - if (printListener.overMaxLength()) { - return true; - } - } - return false; - } - - private interface AppendListener { - void append(String value); - - boolean overMaxLength(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java deleted file mode 100644 index 59d6fef477d0..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.dictionary; - -import io.netty.util.internal.ConcurrentSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import org.skywalking.apm.network.proto.Application; -import org.skywalking.apm.network.proto.ApplicationMapping; -import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.skywalking.apm.network.proto.KeyWithIntegerValue; - -import static org.skywalking.apm.agent.core.conf.Config.Dictionary.APPLICATION_CODE_BUFFER_SIZE; - -/** - * Map of application id to application code, which is from the collector side. - * - * @author wusheng - */ -public enum ApplicationDictionary { - INSTANCE; - private Map applicationDictionary = new ConcurrentHashMap(); - private Set unRegisterApplications = new ConcurrentSet(); - - public PossibleFound find(String applicationCode) { - Integer applicationId = applicationDictionary.get(applicationCode); - if (applicationId != null) { - return new Found(applicationId); - } else { - if (applicationDictionary.size() + unRegisterApplications.size() < APPLICATION_CODE_BUFFER_SIZE) { - unRegisterApplications.add(applicationCode); - } - return new NotFound(); - } - } - - public void syncRemoteDictionary( - ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub applicationRegisterServiceBlockingStub) { - if (unRegisterApplications.size() > 0) { - ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.register( - Application.newBuilder().addAllApplicationCode(unRegisterApplications).build()); - if (applicationMapping.getApplicationCount() > 0) { - for (KeyWithIntegerValue keyWithIntegerValue : applicationMapping.getApplicationList()) { - unRegisterApplications.remove(keyWithIntegerValue.getKey()); - applicationDictionary.put(keyWithIntegerValue.getKey(), keyWithIntegerValue.getValue()); - } - } - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java deleted file mode 100644 index c4d23d12354e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.dictionary; - -/** - * @author wusheng - */ -public class DictionaryManager { - /** - * @return {@link ApplicationDictionary} to find application id for application code and network address. - */ - public static ApplicationDictionary findApplicationCodeSection() { - return ApplicationDictionary.INSTANCE; - } - - /** - * @return {@link OperationNameDictionary} to find service id. - */ - public static OperationNameDictionary findOperationNameCodeSection() { - return OperationNameDictionary.INSTANCE; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java deleted file mode 100644 index d1d5428c8ecb..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.dictionary; - -/** - * @author wusheng - */ -public class DictionaryUtil { - public static int nullValue() { - return 0; - } - - public static boolean isNull(int id) { - return id == nullValue(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java deleted file mode 100644 index 04e054968e1b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.dictionary; - -/** - * @author wusheng - */ -public class Found extends PossibleFound { - public Found(int value) { - super(value); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java deleted file mode 100644 index 5b4d4a0fcf0d..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.dictionary; - -/** - * @author wusheng - */ -public class NotFound extends PossibleFound { - public NotFound() { - super(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java deleted file mode 100644 index 69107f71e32f..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.dictionary; - -/** - * The PossibleFound represents a value, which may needEnhance or not. - * - * @author wusheng - */ -public abstract class PossibleFound { - private boolean found; - private int value; - - PossibleFound(int value) { - this.found = true; - this.value = value; - } - - PossibleFound() { - this.found = false; - } - - public void doInCondition(Found condition1, NotFound condition2) { - if (found) { - condition1.doProcess(value); - } else { - condition2.doProcess(); - } - } - - public Object doInCondition(FoundAndObtain condition1, NotFoundAndObtain condition2) { - if (found) { - return condition1.doProcess(value); - } else { - return condition2.doProcess(); - } - } - - public interface Found { - void doProcess(int value); - } - - public interface NotFound { - void doProcess(); - } - - public interface FoundAndObtain { - Object doProcess(int value); - } - - public interface NotFoundAndObtain { - Object doProcess(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java deleted file mode 100644 index 2ba2e49ff593..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm; - -import io.grpc.ManagedChannel; -import java.util.LinkedList; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.agent.core.jvm.cpu.CPUProvider; -import org.skywalking.apm.agent.core.jvm.gc.GCProvider; -import org.skywalking.apm.agent.core.jvm.memory.MemoryProvider; -import org.skywalking.apm.agent.core.jvm.memorypool.MemoryPoolProvider; -import org.skywalking.apm.agent.core.remote.GRPCChannelListener; -import org.skywalking.apm.agent.core.remote.GRPCChannelManager; -import org.skywalking.apm.agent.core.remote.GRPCChannelStatus; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.network.proto.JVMMetric; -import org.skywalking.apm.network.proto.JVMMetrics; -import org.skywalking.apm.network.proto.JVMMetricsServiceGrpc; - -import static org.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED; - -/** - * The JVMService represents a timer, - * which collectors JVM cpu, memory, memorypool and gc info, - * and send the collected info to Collector through the channel provided by {@link GRPCChannelManager} - * - * @author wusheng - */ -public class JVMService implements BootService, Runnable { - private static final ILog logger = LogManager.getLogger(JVMService.class); - private LinkedBlockingQueue queue; - private volatile ScheduledFuture collectMetricFuture; - private volatile ScheduledFuture sendMetricFuture; - private Sender sender; - @Override - public void beforeBoot() throws Throwable { - queue = new LinkedBlockingQueue(Config.Jvm.BUFFER_SIZE); - sender = new Sender(); - ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(sender); - } - - @Override - public void boot() throws Throwable { - collectMetricFuture = Executors - .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-produce")) - .scheduleAtFixedRate(this, 0, 1, TimeUnit.SECONDS); - sendMetricFuture = Executors - .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-consume")) - .scheduleAtFixedRate(sender, 0, 1, TimeUnit.SECONDS); - } - - @Override - public void afterBoot() throws Throwable { - - } - - @Override - public void shutdown() throws Throwable { - collectMetricFuture.cancel(true); - sendMetricFuture.cancel(true); - } - - @Override - public void run() { - if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue() - && RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue() - ) { - long currentTimeMillis = System.currentTimeMillis(); - try { - JVMMetric.Builder jvmBuilder = JVMMetric.newBuilder(); - jvmBuilder.setTime(currentTimeMillis); - jvmBuilder.setCpu(CPUProvider.INSTANCE.getCpuMetric()); - jvmBuilder.addAllMemory(MemoryProvider.INSTANCE.getMemoryMetricList()); - jvmBuilder.addAllMemoryPool(MemoryPoolProvider.INSTANCE.getMemoryPoolMetricList()); - jvmBuilder.addAllGc(GCProvider.INSTANCE.getGCList()); - - JVMMetric jvmMetric = jvmBuilder.build(); - if (!queue.offer(jvmMetric)) { - queue.poll(); - queue.offer(jvmMetric); - } - } catch (Exception e) { - logger.error(e, "Collect JVM info fail."); - } - } - } - - private class Sender implements Runnable, GRPCChannelListener { - private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT; - private volatile JVMMetricsServiceGrpc.JVMMetricsServiceBlockingStub stub = null; - - @Override - public void run() { - if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue() - && RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue() - ) { - if (status == GRPCChannelStatus.CONNECTED) { - try { - JVMMetrics.Builder builder = JVMMetrics.newBuilder(); - LinkedList buffer = new LinkedList(); - queue.drainTo(buffer); - if (buffer.size() > 0) { - builder.addAllMetrics(buffer); - builder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID); - stub.collect(builder.build()); - } - } catch (Throwable t) { - logger.error(t, "send JVM metrics to Collector fail."); - } - } - } - } - - @Override - public void statusChanged(GRPCChannelStatus status) { - if (CONNECTED.equals(status)) { - ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel(); - stub = JVMMetricsServiceGrpc.newBlockingStub(channel); - } - this.status = status; - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java deleted file mode 100644 index be2255988c05..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUMetricAccessor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.cpu; - -import org.skywalking.apm.network.proto.CPU; - -/** - * @author wusheng - */ -public abstract class CPUMetricAccessor { - private long lastCPUTimeNs; - private long lastSampleTimeNs; - private final int cpuCoreNum; - - public CPUMetricAccessor(int cpuCoreNum) { - this.cpuCoreNum = cpuCoreNum; - } - - protected void init() { - lastCPUTimeNs = this.getCpuTime(); - this.lastSampleTimeNs = System.nanoTime(); - } - - protected abstract long getCpuTime(); - - public CPU getCPUMetric() { - long cpuTime = this.getCpuTime(); - long cpuCost = cpuTime - lastCPUTimeNs; - long now = System.nanoTime(); - - CPU.Builder cpuBuilder = CPU.newBuilder(); - return cpuBuilder.setUsagePercent(cpuCost * 1.0d / ((now - lastSampleTimeNs) * cpuCoreNum)).build(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java deleted file mode 100644 index 281ea45e5a1d..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/CPUProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.cpu; - -import org.skywalking.apm.agent.core.os.ProcessorUtil; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.network.proto.CPU; - -/** - * @author wusheng - */ -public enum CPUProvider { - INSTANCE; - private CPUMetricAccessor cpuMetricAccessor; - - CPUProvider() { - int processorNum = ProcessorUtil.getNumberOfProcessors(); - try { - this.cpuMetricAccessor = - (CPUMetricAccessor)CPUProvider.class.getClassLoader().loadClass("org.skywalking.apm.agent.core.jvm.cpu.SunCpuAccessor") - .getConstructor(int.class).newInstance(processorNum); - } catch (Exception e) { - this.cpuMetricAccessor = new NoSupportedCPUAccessor(processorNum); - ILog logger = LogManager.getLogger(CPUProvider.class); - logger.error(e, "Only support accessing CPU metric in SUN JVM platform."); - } - } - - public CPU getCpuMetric() { - return cpuMetricAccessor.getCPUMetric(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java deleted file mode 100644 index b21912104da0..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/NoSupportedCPUAccessor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.cpu; - -/** - * @author wusheng - */ -public class NoSupportedCPUAccessor extends CPUMetricAccessor { - public NoSupportedCPUAccessor(int cpuCoreNum) { - super(cpuCoreNum); - } - - @Override - protected long getCpuTime() { - return 0; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java deleted file mode 100644 index c1ee9d36ba7d..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/cpu/SunCpuAccessor.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.cpu; - -import com.sun.management.OperatingSystemMXBean; -import java.lang.management.ManagementFactory; - -/** - * @author wusheng - */ -public class SunCpuAccessor extends CPUMetricAccessor { - private final OperatingSystemMXBean osMBean; - - public SunCpuAccessor(int cpuCoreNum) { - super(cpuCoreNum); - this.osMBean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); - this.init(); - } - - @Override - protected long getCpuTime() { - return osMBean.getProcessCpuTime(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java deleted file mode 100644 index 35d26f001c3b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.lang.management.GarbageCollectorMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class CMSGCModule extends GCModule { - public CMSGCModule(List beans) { - super(beans); - } - - @Override protected String getOldGCName() { - return "ConcurrentMarkSweep"; - } - - @Override protected String getNewGCName() { - return "ParNew"; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java deleted file mode 100644 index 66086810cb09..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.lang.management.GarbageCollectorMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class G1GCModule extends GCModule { - public G1GCModule(List beans) { - super(beans); - } - - @Override protected String getOldGCName() { - return "G1 Old Generation"; - } - - @Override protected String getNewGCName() { - return "G1 Young Generation"; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java deleted file mode 100644 index 07a1cdc0497e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.util.List; -import org.skywalking.apm.network.proto.GC; - -/** - * @author wusheng - */ -public interface GCMetricAccessor { - List getGCList(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java deleted file mode 100644 index 89e022d6d814..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.lang.management.GarbageCollectorMXBean; -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.network.proto.GC; -import org.skywalking.apm.network.proto.GCPhrase; - -/** - * @author wusheng - */ -public abstract class GCModule implements GCMetricAccessor { - private List beans; - - public GCModule(List beans) { - this.beans = beans; - } - - @Override - public List getGCList() { - List gcList = new LinkedList(); - for (GarbageCollectorMXBean bean : beans) { - String name = bean.getName(); - GCPhrase phrase; - if (name.equals(getNewGCName())) { - phrase = GCPhrase.NEW; - } else if (name.equals(getOldGCName())) { - phrase = GCPhrase.OLD; - } else { - continue; - } - - gcList.add( - GC.newBuilder().setPhrase(phrase) - .setCount(bean.getCollectionCount()) - .setTime(bean.getCollectionTime()) - .build() - ); - } - - return gcList; - } - - protected abstract String getOldGCName(); - - protected abstract String getNewGCName(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java deleted file mode 100644 index 6cba40e2d87a..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.lang.management.GarbageCollectorMXBean; -import java.lang.management.ManagementFactory; -import java.util.List; -import org.skywalking.apm.network.proto.GC; - -/** - * @author wusheng - */ -public enum GCProvider { - INSTANCE; - - private GCMetricAccessor metricAccessor; - private List beans; - - GCProvider() { - beans = ManagementFactory.getGarbageCollectorMXBeans(); - for (GarbageCollectorMXBean bean : beans) { - String name = bean.getName(); - GCMetricAccessor accessor = findByBeanName(name); - if (accessor != null) { - metricAccessor = accessor; - break; - } - } - - if (metricAccessor == null) { - this.metricAccessor = new UnknowGC(); - } - } - - public List getGCList() { - return metricAccessor.getGCList(); - } - - private GCMetricAccessor findByBeanName(String name) { - if (name.indexOf("PS") > -1) { - //Parallel (Old) collector ( -XX:+UseParallelOldGC ) - return new ParallelGCModule(beans); - } else if (name.indexOf("ConcurrentMarkSweep") > -1) { - // CMS collector ( -XX:+UseConcMarkSweepGC ) - return new CMSGCModule(beans); - } else if (name.indexOf("G1") > -1) { - // G1 collector ( -XX:+UseG1GC ) - return new G1GCModule(beans); - } else if (name.equals("MarkSweepCompact")) { - // Serial collector ( -XX:+UseSerialGC ) - return new SerialGCModule(beans); - } else { - // Unknown - return null; - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java deleted file mode 100644 index 4b1ed84ae450..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.lang.management.GarbageCollectorMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class ParallelGCModule extends GCModule { - public ParallelGCModule(List beans) { - super(beans); - } - - @Override protected String getOldGCName() { - return "PS MarkSweep"; - } - - @Override protected String getNewGCName() { - return "PS Scavenge"; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java deleted file mode 100644 index 78047686defe..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.lang.management.GarbageCollectorMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class SerialGCModule extends GCModule { - public SerialGCModule(List beans) { - super(beans); - } - - @Override protected String getOldGCName() { - return "MarkSweepCompact"; - } - - @Override protected String getNewGCName() { - return "Copy"; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java deleted file mode 100644 index 0214fae7e574..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.gc; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.network.proto.GC; -import org.skywalking.apm.network.proto.GCPhrase; - -/** - * @author wusheng - */ -public class UnknowGC implements GCMetricAccessor { - @Override - public List getGCList() { - List gcList = new LinkedList(); - gcList.add(GC.newBuilder().setPhrase(GCPhrase.NEW).build()); - gcList.add(GC.newBuilder().setPhrase(GCPhrase.OLD).build()); - return gcList; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java deleted file mode 100644 index 424a4855f121..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memory/MemoryProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memory; - -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryMXBean; -import java.lang.management.MemoryUsage; -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.network.proto.Memory; - -/** - * @author wusheng - */ -public enum MemoryProvider { - INSTANCE; - private final MemoryMXBean memoryMXBean; - - MemoryProvider() { - this.memoryMXBean = ManagementFactory.getMemoryMXBean(); - } - - public List getMemoryMetricList() { - List memoryList = new LinkedList(); - - MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); - Memory.Builder heapMemoryBuilder = Memory.newBuilder(); - heapMemoryBuilder.setIsHeap(true); - heapMemoryBuilder.setInit(heapMemoryUsage.getInit()); - heapMemoryBuilder.setUsed(heapMemoryUsage.getUsed()); - heapMemoryBuilder.setCommitted(heapMemoryUsage.getCommitted()); - heapMemoryBuilder.setMax(heapMemoryUsage.getMax()); - memoryList.add(heapMemoryBuilder.build()); - - MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); - Memory.Builder nonHeapMemoryBuilder = Memory.newBuilder(); - nonHeapMemoryBuilder.setIsHeap(false); - nonHeapMemoryBuilder.setInit(nonHeapMemoryUsage.getInit()); - nonHeapMemoryBuilder.setUsed(nonHeapMemoryUsage.getUsed()); - nonHeapMemoryBuilder.setCommitted(nonHeapMemoryUsage.getCommitted()); - nonHeapMemoryBuilder.setMax(nonHeapMemoryUsage.getMax()); - memoryList.add(nonHeapMemoryBuilder.build()); - - return memoryList; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java deleted file mode 100644 index 5736f93dec9a..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.lang.management.MemoryPoolMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class CMSCollectorModule extends MemoryPoolModule { - public CMSCollectorModule(List beans) { - super(beans); - } - - @Override protected String[] getPermNames() { - return new String[] {"CMS Perm Gen", "Compressed Class Space"}; - } - - @Override protected String[] getCodeCacheNames() { - return new String[] {"Code Cache"}; - } - - @Override protected String[] getEdenNames() { - return new String[] {"Par Eden Space"}; - } - - @Override protected String[] getOldNames() { - return new String[] {"CMS Old Gen"}; - } - - @Override protected String[] getSurvivorNames() { - return new String[] {"Par Survivor Space"}; - } - - @Override protected String[] getMetaspaceNames() { - return new String[] {"Metaspace"}; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java deleted file mode 100644 index 7500caa03cc9..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.lang.management.MemoryPoolMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class G1CollectorModule extends MemoryPoolModule { - public G1CollectorModule(List beans) { - super(beans); - } - - @Override protected String[] getPermNames() { - return new String[] {"G1 Perm Gen", "Compressed Class Space"}; - } - - @Override protected String[] getCodeCacheNames() { - return new String[] {"Code Cache"}; - } - - @Override protected String[] getEdenNames() { - return new String[] {"G1 Eden Space"}; - } - - @Override protected String[] getOldNames() { - return new String[] {"G1 Old Gen"}; - } - - @Override protected String[] getSurvivorNames() { - return new String[] {"G1 Survivor Space"}; - } - - @Override protected String[] getMetaspaceNames() { - return new String[] {"Metaspace"}; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java deleted file mode 100644 index 79ed42b0b6cf..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolMetricAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.util.List; -import org.skywalking.apm.network.proto.MemoryPool; - -/** - * @author wusheng - */ -public interface MemoryPoolMetricAccessor { - List getMemoryPoolMetricList(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java deleted file mode 100644 index 50896a1ad1bc..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryPoolMXBean; -import java.util.List; -import org.skywalking.apm.network.proto.MemoryPool; - -/** - * @author wusheng - */ -public enum MemoryPoolProvider { - INSTANCE; - - private MemoryPoolMetricAccessor metricAccessor; - private List beans; - - MemoryPoolProvider() { - beans = ManagementFactory.getMemoryPoolMXBeans(); - for (MemoryPoolMXBean bean : beans) { - String name = bean.getName(); - MemoryPoolMetricAccessor accessor = findByBeanName(name); - if (accessor != null) { - metricAccessor = accessor; - break; - } - } - if (metricAccessor == null) { - metricAccessor = new UnknownMemoryPool(); - } - } - - public List getMemoryPoolMetricList() { - return metricAccessor.getMemoryPoolMetricList(); - } - - private MemoryPoolMetricAccessor findByBeanName(String name) { - if (name.indexOf("PS") > -1) { - //Parallel (Old) collector ( -XX:+UseParallelOldGC ) - return new ParallelCollectorModule(beans); - } else if (name.indexOf("CMS") > -1) { - // CMS collector ( -XX:+UseConcMarkSweepGC ) - return new CMSCollectorModule(beans); - } else if (name.indexOf("G1") > -1) { - // G1 collector ( -XX:+UseG1GC ) - return new G1CollectorModule(beans); - } else if (name.equals("Survivor Space")) { - // Serial collector ( -XX:+UseSerialGC ) - return new SerialCollectorModule(beans); - } else { - // Unknown - return null; - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java deleted file mode 100644 index aaa4502bdaa2..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.lang.management.MemoryPoolMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class ParallelCollectorModule extends MemoryPoolModule { - - public ParallelCollectorModule(List beans) { - super(beans); - } - - @Override protected String[] getPermNames() { - return new String[] {"PS Perm Gen", "Compressed Class Space"}; - } - - @Override protected String[] getCodeCacheNames() { - return new String[] {"Code Cache"}; - } - - @Override protected String[] getEdenNames() { - return new String[] {"PS Eden Space"}; - } - - @Override protected String[] getOldNames() { - return new String[] {"PS Old Gen"}; - } - - @Override protected String[] getSurvivorNames() { - return new String[] {"PS Survivor Space"}; - } - - @Override protected String[] getMetaspaceNames() { - return new String[] {"Metaspace"}; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java deleted file mode 100644 index b6d072921c2f..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/SerialCollectorModule.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.lang.management.MemoryPoolMXBean; -import java.util.List; - -/** - * @author wusheng - */ -public class SerialCollectorModule extends MemoryPoolModule { - public SerialCollectorModule(List beans) { - super(beans); - } - - @Override protected String[] getPermNames() { - return new String[] {"Perm Gen", "Compressed Class Space"}; - } - - @Override protected String[] getCodeCacheNames() { - return new String[] {"Code Cache"}; - } - - @Override protected String[] getEdenNames() { - return new String[] {"Eden Space"}; - } - - @Override protected String[] getOldNames() { - return new String[] {"Tenured Gen"}; - } - - @Override protected String[] getSurvivorNames() { - return new String[] {"Survivor Space"}; - } - - @Override protected String[] getMetaspaceNames() { - return new String[] {"Metaspace"}; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java deleted file mode 100644 index 7b9e7381936d..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.jvm.memorypool; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.network.proto.MemoryPool; -import org.skywalking.apm.network.proto.PoolType; - -/** - * @author wusheng - */ -public class UnknownMemoryPool implements MemoryPoolMetricAccessor { - @Override - public List getMemoryPoolMetricList() { - List poolList = new LinkedList(); - poolList.add(MemoryPool.newBuilder().setType(PoolType.CODE_CACHE_USAGE).build()); - poolList.add(MemoryPool.newBuilder().setType(PoolType.NEWGEN_USAGE).build()); - poolList.add(MemoryPool.newBuilder().setType(PoolType.OLDGEN_USAGE).build()); - poolList.add(MemoryPool.newBuilder().setType(PoolType.SURVIVOR_USAGE).build()); - poolList.add(MemoryPool.newBuilder().setType(PoolType.PERMGEN_USAGE).build()); - poolList.add(MemoryPool.newBuilder().setType(PoolType.METASPACE_USAGE).build()); - return new LinkedList(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/ILog.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/ILog.java deleted file mode 100644 index 250e0493e46b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/ILog.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.api; - -/** - * The Log interface. - * It's very easy to understand, like any other log-component. - * Do just like log4j or log4j2 does. - *

- * Created by xin on 2016/11/10. - */ -public interface ILog { - void info(String format); - - void info(String format, Object... arguments); - - void warn(String format, Object... arguments); - - void error(String format, Throwable e); - - void error(Throwable e, String format, Object... arguments); - - boolean isDebugEnable(); - - boolean isInfoEnable(); - - boolean isWarnEnable(); - - boolean isErrorEnable(); - - void debug(String format); - - void debug(String format, Object... arguments); - - void error(String format); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogManager.java deleted file mode 100644 index e55bf42d0a8c..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.api; - -import org.skywalking.apm.agent.core.logging.core.EasyLogResolver; - -/** - * LogManager is the {@link LogResolver} implementation manager. By using {@link LogResolver}, {@link - * LogManager#getLogger(Class)} returns a {@link ILog} implementation. This module use this class as the main entrance, - * and block the implementation detail about log-component. In different modules, like server or sniffer, it will use - * different implementations.

If no {@link LogResolver} is registered, return {@link NoopLogger#INSTANCE} to avoid - * {@link NullPointerException}. If {@link LogManager#setLogResolver(LogResolver)} is called twice, the second will - * override the first without any warning or exception.

Created by xin on 2016/11/10. - */ -public class LogManager { - private static LogResolver RESOLVER = new EasyLogResolver(); - - public static void setLogResolver(LogResolver resolver) { - LogManager.RESOLVER = resolver; - } - - public static ILog getLogger(Class clazz) { - if (RESOLVER == null) { - return NoopLogger.INSTANCE; - } - return LogManager.RESOLVER.getLogger(clazz); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogResolver.java deleted file mode 100644 index 3f7a0a2cdbf6..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/LogResolver.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.api; - -/** - * {@link LogResolver} just do only one thing: return the {@link ILog} implementation. - *

- * Created by xin on 2016/11/10. - */ -public interface LogResolver { - /** - * @param clazz, the class is showed in log message. - * @return {@link ILog} implementation. - */ - ILog getLogger(Class clazz); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/NoopLogger.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/NoopLogger.java deleted file mode 100644 index 820422c7013b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/api/NoopLogger.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.api; - -/** - * No operation logger implementation. - * Just implement {@link ILog} interface, but do nothing. - *

- * Created by xin on 2016/11/10. - */ -public enum NoopLogger implements ILog { - INSTANCE { - - }; - - @Override - public void info(String message) { - - } - - @Override - public void info(String format, Object... arguments) { - - } - - @Override - public void warn(String format, Object... arguments) { - - } - - @Override - public void error(String format, Throwable e) { - - } - - @Override - public boolean isDebugEnable() { - return false; - } - - @Override - public boolean isInfoEnable() { - return false; - } - - @Override - public boolean isWarnEnable() { - return false; - } - - @Override - public boolean isErrorEnable() { - return false; - } - - @Override - public void debug(String format) { - - } - - @Override - public void debug(String format, Object... arguments) { - - } - - @Override - public void error(String format) { - - } - - @Override - public void error(Throwable e, String format, Object... arguments) { - - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolver.java deleted file mode 100644 index 53057c3eab1c..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolver.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogResolver; - -/** - * Created by wusheng on 2016/11/26. - */ -public class EasyLogResolver implements LogResolver { - @Override - public ILog getLogger(Class clazz) { - return new EasyLogger(clazz); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/IWriter.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/IWriter.java deleted file mode 100644 index e5468c6ae2fa..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/IWriter.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -public interface IWriter { - void write(String message); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogLevel.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogLevel.java deleted file mode 100644 index e034097b69a9..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogLevel.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -/** - * Created by xin on 2016/12/7. - */ -public enum LogLevel { - DEBUG, INFO, WARN, ERROR, OFF -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogMessageHolder.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogMessageHolder.java deleted file mode 100644 index 607c01f100b5..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/LogMessageHolder.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -/** - * The LogMessageHolder is a {@link String} holder, - * in order to in-process propagation String across the disruptor queue. - * - * @author wusheng - */ -public class LogMessageHolder { - private String message; - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriter.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriter.java deleted file mode 100644 index c90d17d46832..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -import java.io.PrintStream; - -public enum SystemOutWriter implements IWriter { - INSTANCE; - - /** - * Tricky codes for avoiding style-check. - * Because, in here, "system.out.println" is the only choice to output logs. - * - * @param message - */ - @Override - public void write(String message) { - PrintStream out = System.out; - out.println(message); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/WriterFactory.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/WriterFactory.java deleted file mode 100644 index 892ccc97f028..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/logging/core/WriterFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.util.StringUtil; - -public class WriterFactory { - public static IWriter getLogWriter() { - if (AgentPackagePath.isPathFound()) { - if (StringUtil.isEmpty(Config.Logging.DIR)) { - try { - Config.Logging.DIR = AgentPackagePath.getPath() + "/logs"; - } catch (AgentPackageNotFoundException e) { - e.printStackTrace(); - } - } - return FileWriter.get(); - } else { - return SystemOutWriter.INSTANCE; - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/ProcessorUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/ProcessorUtil.java deleted file mode 100644 index 0f37da723461..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/os/ProcessorUtil.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.os; - -import java.lang.management.ManagementFactory; - -/** - * @author wusheng - */ -public class ProcessorUtil { - public static int getNumberOfProcessors() { - return ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/EnhanceContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/EnhanceContext.java deleted file mode 100644 index a893ddc8d4e9..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/EnhanceContext.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -/** - * The EnhanceContext represents the context or status for processing a class. - * - * Based on this context, the plugin core {@link org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine} - * knows how to process the specific steps for every particular plugin. - * - * @author wusheng - */ -public class EnhanceContext { - private boolean isEnhanced = false; - /** - * The object has already been enhanced or extended. - * e.g. added the new field, or implemented the new interface - */ - private boolean objectExtended = false; - - public boolean isEnhanced() { - return isEnhanced; - } - - public void initializationStageCompleted() { - isEnhanced = true; - } - - public boolean isObjectExtended() { - return objectExtended; - } - - public void extendObjectCompleted() { - objectExtended = true; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java deleted file mode 100644 index f20a18ffdd58..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.plugin.loader.AgentClassLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; - -/** - * Plugins finder. - * Use {@link PluginResourcesResolver} to find all plugins, - * and ask {@link PluginCfg} to load all plugin definitions. - * - * @author wusheng - */ -public class PluginBootstrap { - private static final ILog logger = LogManager.getLogger(PluginBootstrap.class); - - /** - * load all plugins. - * - * @return plugin definition list. - */ - public List loadPlugins() throws AgentPackageNotFoundException { - AgentClassLoader.initDefaultLoader(); - - PluginResourcesResolver resolver = new PluginResourcesResolver(); - List resources = resolver.getResources(); - - if (resources == null || resources.size() == 0) { - logger.info("no plugin files (skywalking-plugin.def) found, continue to start application."); - return new ArrayList(); - } - - for (URL pluginUrl : resources) { - try { - PluginCfg.INSTANCE.load(pluginUrl.openStream()); - } catch (Throwable t) { - logger.error(t, "plugin file [{}] init failure.", pluginUrl); - } - } - - List pluginClassList = PluginCfg.INSTANCE.getPluginClassList(); - - List plugins = new ArrayList(); - for (PluginDefine pluginDefine : pluginClassList) { - try { - logger.debug("loading plugin class {}.", pluginDefine.getDefineClass()); - AbstractClassEnhancePluginDefine plugin = - (AbstractClassEnhancePluginDefine)Class.forName(pluginDefine.getDefineClass(), - true, - AgentClassLoader.getDefault()) - .newInstance(); - plugins.add(plugin); - } catch (Throwable t) { - logger.error(t, "load plugin [{}] failure.", pluginDefine.getDefineClass()); - } - } - - return plugins; - - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java deleted file mode 100644 index 787e1740cd91..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -public enum PluginCfg { - INSTANCE; - - private static final ILog logger = LogManager.getLogger(PluginCfg.class); - - private List pluginClassList = new ArrayList(); - - void load(InputStream input) throws IOException { - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(input)); - String pluginDefine = null; - while ((pluginDefine = reader.readLine()) != null) { - try { - if (pluginDefine == null || pluginDefine.trim().length() == 0) { - continue; - } - PluginDefine plugin = PluginDefine.build(pluginDefine); - pluginClassList.add(plugin); - } catch (IllegalPluginDefineException e) { - logger.error(e, "Failed to format plugin({}) define.", pluginDefine); - } - } - } finally { - input.close(); - } - } - - public List getPluginClassList() { - return pluginClassList; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginDefine.java deleted file mode 100644 index 4a503052a87e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginDefine.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException; -import org.skywalking.apm.util.StringUtil; - -public class PluginDefine { - /** - * Plugin name. - */ - private String name; - - /** - * The class name of plugin defined. - */ - private String defineClass; - - private PluginDefine(String name, String defineClass) { - this.name = name; - this.defineClass = defineClass; - } - - public static PluginDefine build(String define) throws IllegalPluginDefineException { - if (StringUtil.isEmpty(define)) { - throw new IllegalPluginDefineException(define); - } - - String[] pluginDefine = define.split("="); - if (pluginDefine.length != 2) { - throw new IllegalPluginDefineException(define); - } - - String pluginName = pluginDefine[0]; - String defineClass = pluginDefine[1]; - return new PluginDefine(pluginName, defineClass); - } - - public String getDefineClass() { - return defineClass; - } -} - - diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginException.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginException.java deleted file mode 100644 index 1ee08560936b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -public class PluginException extends RuntimeException { - private static final long serialVersionUID = -6020188711867490724L; - - public PluginException(String message) { - super(message); - } - - public PluginException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java deleted file mode 100644 index 4a293946f7d6..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import org.skywalking.apm.agent.core.plugin.loader.AgentClassLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; - -/** - * Use the current classloader to read all plugin define file. - * The file must be named 'skywalking-plugin.def' - * - * @author wusheng - */ -public class PluginResourcesResolver { - private static final ILog logger = LogManager.getLogger(PluginResourcesResolver.class); - - public List getResources() { - List cfgUrlPaths = new ArrayList(); - Enumeration urls; - try { - urls = AgentClassLoader.getDefault().getResources("skywalking-plugin.def"); - - while (urls.hasMoreElements()) { - URL pluginUrl = urls.nextElement(); - cfgUrlPaths.add(pluginUrl); - logger.info("find skywalking plugin define in {}", pluginUrl); - } - - return cfgUrlPaths; - } catch (IOException e) { - logger.error("read resources failure.", e); - } - return null; - } - - /** - * Get the classloader. - * First getDefault current thread's classloader, - * if fail, getDefault {@link PluginResourcesResolver}'s classloader. - * - * @return the classloader to find plugin definitions. - */ - private ClassLoader getDefaultClassLoader() { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - } catch (Throwable ex) { - // Cannot access thread context ClassLoader - falling back to system class loader... - } - if (cl == null) { - // No thread context class loader -> use class loader of this class. - cl = PluginResourcesResolver.class.getClassLoader(); - } - return cl; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/WitnessClassFinder.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/WitnessClassFinder.java deleted file mode 100644 index 4e780331d13e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/WitnessClassFinder.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin; - -import java.util.HashMap; -import java.util.Map; -import net.bytebuddy.pool.TypePool; - -/** - * The WitnessClassFinder represents a pool of {@link TypePool}s, - * each {@link TypePool} matches a {@link ClassLoader}, - * which helps to find the class define existed or not. - * - * @author wusheng - */ -public enum WitnessClassFinder { - INSTANCE; - - private Map poolMap = new HashMap(); - - /** - * @param witnessClass - * @param classLoader for finding the witnessClass - * @return true, if the given witnessClass exists, through the given classLoader. - */ - public boolean exist(String witnessClass, ClassLoader classLoader) { - ClassLoader mappingKey = classLoader == null ? NullClassLoader.INSTANCE : classLoader; - if (!poolMap.containsKey(mappingKey)) { - synchronized (poolMap) { - if (!poolMap.containsKey(mappingKey)) { - TypePool classTypePool = classLoader == null ? TypePool.Default.ofClassPath() : TypePool.Default.of(classLoader); - poolMap.put(mappingKey, classTypePool); - } - } - } - TypePool typePool = poolMap.get(mappingKey); - TypePool.Resolution witnessClassResolution = typePool.describe(witnessClass); - return witnessClassResolution.isResolved(); - } -} - -final class NullClassLoader extends ClassLoader { - static NullClassLoader INSTANCE = new NullClassLoader(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java deleted file mode 100644 index 4a2d7b64d184..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.bytebuddy; - -import net.bytebuddy.matcher.ElementMatcher; - -/** - * Created by wusheng on 16/7/31. - */ -public abstract class AbstractJunction implements ElementMatcher.Junction { - @Override - public Junction and(ElementMatcher other) { - return new Conjunction(this, other); - } - - @Override - public Junction or(ElementMatcher other) { - return new Disjunction(this, other); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java deleted file mode 100644 index 1229711b1277..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.exception; - -/** - * Thrown to indicate that a illegal format plugin definition has been defined in skywalking-plugin.define. - */ -public class IllegalPluginDefineException extends Exception { - public IllegalPluginDefineException(String define) { - super("Illegal plugin define : " + define); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java deleted file mode 100644 index 9395a3112570..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/ConstructorInterceptPoint.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -/** - * One of the three "Intercept Point". - * "Intercept Point" is a definition about where and how intercept happens. - * In this "Intercept Point", the definition targets class's constructors, and the interceptor. - *

- * ref to two others: {@link StaticMethodsInterceptPoint} and {@link InstanceMethodsInterceptPoint} - *

- * Created by wusheng on 2016/11/29. - */ -public interface ConstructorInterceptPoint { - /** - * Constructor matcher - * - * @return matcher instance. - */ - ElementMatcher getConstructorMatcher(); - - /** - * @return represents a class name, the class instance must be a instance of {@link - * org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor} - */ - String getConstructorInterceptor(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java deleted file mode 100644 index fa1c1f37d37a..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/EnhanceException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor; - -import org.skywalking.apm.agent.core.plugin.PluginException; - -public class EnhanceException extends PluginException { - private static final long serialVersionUID = -2234782755784217255L; - - public EnhanceException(String message) { - super(message); - } - - public EnhanceException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java deleted file mode 100644 index 625393e8482e..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -/** - * One of the three "Intercept Point". - * "Intercept Point" is a definition about where and how intercept happens. - * In this "Intercept Point", the definition targets class's instance methods, and the interceptor. - *

- * ref to two others: {@link ConstructorInterceptPoint} and {@link StaticMethodsInterceptPoint} - *

- * Created by wusheng on 2016/11/29. - */ -public interface InstanceMethodsInterceptPoint { - /** - * class instance methods matcher. - * - * @return methods matcher - */ - ElementMatcher getMethodsMatcher(); - - /** - * @return represents a class name, the class instance must instanceof InstanceMethodsAroundInterceptor. - */ - String getMethodsInterceptor(); - - boolean isOverrideArgs(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java deleted file mode 100644 index 1bd76488fe8b..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/InterceptorException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor; - -public class InterceptorException extends RuntimeException { - private static final long serialVersionUID = 7846035239994885019L; - - public InterceptorException(String message) { - super(message); - } - - public InterceptorException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java deleted file mode 100644 index 99e2eb6e2007..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -/** - * One of the three "Intercept Point". - * "Intercept Point" is a definition about where and how intercept happens. - * In this "Intercept Point", the definition targets class's static methods, and the interceptor. - *

- * ref to two others: {@link ConstructorInterceptPoint} and {@link InstanceMethodsInterceptPoint} - *

- * Created by wusheng on 2016/11/29. - */ -public interface StaticMethodsInterceptPoint { - /** - * static methods matcher. - * - * @return matcher instance. - */ - ElementMatcher getMethodsMatcher(); - - /** - * @return represents a class name, the class instance must instanceof StaticMethodsAroundInterceptor. - */ - String getMethodsInterceptor(); - - boolean isOverrideArgs(); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java deleted file mode 100644 index a48c31247a10..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; - -/** - * Plugins, which only need enhance class static methods. Actually, inherit from {@link - * ClassInstanceMethodsEnhancePluginDefine} has no differences with inherit from {@link ClassEnhancePluginDefine}. Just - * override {@link ClassEnhancePluginDefine#getStaticMethodsInterceptPoints}, and return {@link null}, which means - * nothing to enhance. - * - * @author wusheng - */ -public abstract class ClassInstanceMethodsEnhancePluginDefine extends ClassEnhancePluginDefine { - - /** - * @return null, means enhance no static methods. - */ - @Override - protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return null; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java deleted file mode 100644 index 1e02f67b2553..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; - -/** - * Plugins, which only need enhance class static methods. Actually, inherit from {@link - * ClassStaticMethodsEnhancePluginDefine} has no differences with inherit from {@link ClassEnhancePluginDefine}. Just - * override {@link ClassEnhancePluginDefine#getConstructorsInterceptPoints} and {@link - * ClassEnhancePluginDefine#getInstanceMethodsInterceptPoints}, and return {@link null}, which means nothing to - * enhance. - * - * @author wusheng - */ -public abstract class ClassStaticMethodsEnhancePluginDefine extends ClassEnhancePluginDefine { - - /** - * @return null, means enhance no constructors. - */ - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - /** - * @return null, means enhance no instance methods. - */ - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return null; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java deleted file mode 100644 index 52f8c5deb1a8..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/ConstructorInter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -import net.bytebuddy.implementation.bind.annotation.AllArguments; -import net.bytebuddy.implementation.bind.annotation.RuntimeType; -import net.bytebuddy.implementation.bind.annotation.This; -import org.skywalking.apm.agent.core.plugin.PluginException; -import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; - -/** - * The actual byte-buddy's interceptor to intercept constructor methods. - * In this class, it provide a bridge between byte-buddy and sky-walking plugin. - * - * @author wusheng - */ -public class ConstructorInter { - private static final ILog logger = LogManager.getLogger(ConstructorInter.class); - - /** - * An {@link InstanceConstructorInterceptor} - * This name should only stay in {@link String}, the real {@link Class} type will trigger classloader failure. - * If you want to know more, please check on books about Classloader or Classloader appointment mechanism. - */ - private InstanceConstructorInterceptor interceptor; - - /** - * @param constructorInterceptorClassName class full name. - */ - public ConstructorInter(String constructorInterceptorClassName, ClassLoader classLoader) throws PluginException { - try { - interceptor = InterceptorInstanceLoader.load(constructorInterceptorClassName, classLoader); - } catch (Throwable t) { - throw new PluginException("Can't create InstanceConstructorInterceptor.", t); - } - } - - /** - * Intercept the target constructor. - * - * @param obj target class instance. - * @param allArguments all constructor arguments - */ - @RuntimeType - public void intercept(@This Object obj, - @AllArguments Object[] allArguments) { - try { - EnhancedInstance targetObject = (EnhancedInstance)obj; - - interceptor.onConstruct(targetObject, allArguments); - } catch (Throwable t) { - logger.error("ConstructorInter failure.", t); - } - - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java deleted file mode 100644 index 6deb0bf82150..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -/** - * @author wusheng - */ -public interface EnhancedInstance { - Object getSkyWalkingDynamicField(); - - void setSkyWalkingDynamicField(Object value); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java deleted file mode 100644 index 3a5122ff4075..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -/** - * The instance constructor's interceptor interface. - * Any plugin, which wants to intercept constructor, must implement this interface. - *

- * - * @author wusheng - */ -public interface InstanceConstructorInterceptor { - /** - * Called before the origin constructor invocation. - */ - void onConstruct(EnhancedInstance objInst, Object[] allArguments); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java deleted file mode 100644 index 185e02cbe855..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -import java.lang.reflect.Method; - -/** - * A interceptor, which intercept method's invocation. The target methods will be defined in {@link - * ClassEnhancePluginDefine}'s subclass, most likely in {@link ClassInstanceMethodsEnhancePluginDefine} - * - * @author wusheng - */ -public interface InstanceMethodsAroundInterceptor { - /** - * called before target method invocation. - * - * @param method - * @param result change this result, if you want to truncate the method. - * @throws Throwable - */ - void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable; - - /** - * called after target method invocation. Even method's invocation triggers an exception. - * - * @param method - * @param ret the method's original return value. - * @return the method's actual return value. - * @throws Throwable - */ - Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable; - - /** - * called when occur exception. - * - * @param method - * @param t the exception occur. - */ - void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - Throwable t); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java deleted file mode 100644 index e952d77cb060..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -/** - * This is a method return value manipulator. When a interceptor's method, such as {@link - * InstanceMethodsAroundInterceptor#beforeMethod(org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext, - * InstanceMethodInvokeContext, MethodInterceptResult)}, has this as a method argument, the interceptor can manipulate - * the method's return value.

The new value set to this object, by {@link MethodInterceptResult#defineReturnValue(Object)}, - * will override the origin return value. - * - * @author wusheng - */ -public class MethodInterceptResult { - private boolean isContinue = true; - - private Object ret = null; - - /** - * define the new return value. - * - * @param ret new return value. - */ - public void defineReturnValue(Object ret) { - this.isContinue = false; - this.ret = ret; - } - - /** - * @return true, will trigger method interceptor({@link InstMethodsInter} and {@link StaticMethodsInter}) to invoke - * the origin method. Otherwise, not. - */ - public boolean isContinue() { - return isContinue; - } - - /** - * @return the new return value. - */ - Object _ret() { - return ret; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java deleted file mode 100644 index 2429f4186b96..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/OverrideCallable.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -/** - * @author wusheng - */ -public interface OverrideCallable { - Object call(Object[] args); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java deleted file mode 100644 index 852b6b8012b2..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.interceptor.enhance; - -import java.lang.reflect.Method; - -/** - * The static method's interceptor interface. - * Any plugin, which wants to intercept static methods, must implement this interface. - * - * @author wusheng - */ -public interface StaticMethodsAroundInterceptor { - /** - * called before target method invocation. - * - * @param method - * @param result change this result, if you want to truncate the method. - */ - void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - MethodInterceptResult result); - - /** - * called after target method invocation. Even method's invocation triggers an exception. - * - * @param method - * @param ret the method's original return value. - * @return the method's actual return value. - */ - Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, Object ret); - - /** - * called when occur exception. - * - * @param method - * @param t the exception occur. - */ - void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Throwable t); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassMatch.java deleted file mode 100644 index e71afdfee062..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/ClassMatch.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.match; - -/** - * @author wusheng - */ -public interface ClassMatch { -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/IndirectMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/IndirectMatch.java deleted file mode 100644 index 5e41b9ab07ed..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/IndirectMatch.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.match; - -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatcher; - -/** - * All implementations can't direct match the class like {@link NameMatch} did. - * - * @author wusheng - */ -public interface IndirectMatch extends ClassMatch { - ElementMatcher.Junction buildJunction(); - - boolean isMatch(TypeDescription typeDescription); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/NameMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/NameMatch.java deleted file mode 100644 index 00ad62e8c9e5..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/match/NameMatch.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.plugin.match; - -/** - * Match the class with an explicit class name. - * - * @author wusheng - */ -public class NameMatch implements ClassMatch { - private String className; - - private NameMatch(String className) { - this.className = className; - } - - public String getClassName() { - return className; - } - - public static NameMatch byName(String className) { - return new NameMatch(className); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java deleted file mode 100644 index 4683ac7640b0..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -import io.grpc.ManagedChannel; -import java.util.UUID; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.dictionary.ApplicationDictionary; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.agent.core.dictionary.OperationNameDictionary; -import org.skywalking.apm.agent.core.os.OSUtil; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.network.proto.Application; -import org.skywalking.apm.network.proto.ApplicationInstance; -import org.skywalking.apm.network.proto.ApplicationInstanceHeartbeat; -import org.skywalking.apm.network.proto.ApplicationInstanceMapping; -import org.skywalking.apm.network.proto.ApplicationInstanceRecover; -import org.skywalking.apm.network.proto.ApplicationMapping; -import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc; -import org.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; - -import static org.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED; - -/** - * @author wusheng - */ -public class AppAndServiceRegisterClient implements BootService, GRPCChannelListener, Runnable, TracingContextListener { - private static final ILog logger = LogManager.getLogger(AppAndServiceRegisterClient.class); - private static final String PROCESS_UUID = UUID.randomUUID().toString().replaceAll("-", ""); - - private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT; - private volatile ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub applicationRegisterServiceBlockingStub; - private volatile InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceBlockingStub instanceDiscoveryServiceBlockingStub; - private volatile ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceBlockingStub serviceNameDiscoveryServiceBlockingStub; - private volatile ScheduledFuture applicationRegisterFuture; - private volatile boolean needRegisterRecover = false; - private volatile long lastSegmentTime = -1; - - @Override - public void statusChanged(GRPCChannelStatus status) { - if (CONNECTED.equals(status)) { - ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel(); - applicationRegisterServiceBlockingStub = ApplicationRegisterServiceGrpc.newBlockingStub(channel); - instanceDiscoveryServiceBlockingStub = InstanceDiscoveryServiceGrpc.newBlockingStub(channel); - if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()) { - needRegisterRecover = true; - } - serviceNameDiscoveryServiceBlockingStub = ServiceNameDiscoveryServiceGrpc.newBlockingStub(channel); - } else { - applicationRegisterServiceBlockingStub = null; - instanceDiscoveryServiceBlockingStub = null; - serviceNameDiscoveryServiceBlockingStub = null; - } - this.status = status; - } - - @Override - public void beforeBoot() throws Throwable { - ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(this); - } - - @Override - public void boot() throws Throwable { - applicationRegisterFuture = Executors - .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("AppAndServiceRegisterClient")) - .scheduleAtFixedRate(this, 0, Config.Collector.APP_AND_SERVICE_REGISTER_CHECK_INTERVAL, TimeUnit.SECONDS); - } - - @Override - public void afterBoot() throws Throwable { - TracingContext.ListenerManager.add(this); - } - - @Override - public void shutdown() throws Throwable { - applicationRegisterFuture.cancel(true); - } - - @Override - public void run() { - logger.debug("AppAndServiceRegisterClient running, status:{}.",status); - boolean shouldTry = true; - while (CONNECTED.equals(status) && shouldTry) { - shouldTry = false; - try { - if (RemoteDownstreamConfig.Agent.APPLICATION_ID == DictionaryUtil.nullValue()) { - if (applicationRegisterServiceBlockingStub != null) { - ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.register( - Application.newBuilder().addApplicationCode(Config.Agent.APPLICATION_CODE).build()); - if (applicationMapping.getApplicationCount() > 0) { - RemoteDownstreamConfig.Agent.APPLICATION_ID = applicationMapping.getApplication(0).getValue(); - shouldTry = true; - } - } - } else { - if (instanceDiscoveryServiceBlockingStub != null) { - if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID == DictionaryUtil.nullValue()) { - - ApplicationInstanceMapping instanceMapping = instanceDiscoveryServiceBlockingStub.register(ApplicationInstance.newBuilder() - .setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID) - .setAgentUUID(PROCESS_UUID) - .setRegisterTime(System.currentTimeMillis()) - .setOsinfo(OSUtil.buildOSInfo()) - .build()); - if (instanceMapping.getApplicationInstanceId() != DictionaryUtil.nullValue()) { - RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID - = instanceMapping.getApplicationInstanceId(); - } - } else { - if (needRegisterRecover) { - instanceDiscoveryServiceBlockingStub.registerRecover(ApplicationInstanceRecover.newBuilder() - .setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID) - .setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID) - .setRegisterTime(System.currentTimeMillis()) - .setOsinfo(OSUtil.buildOSInfo()) - .build()); - needRegisterRecover = false; - } else { - if (lastSegmentTime - System.currentTimeMillis() > 60 * 1000) { - instanceDiscoveryServiceBlockingStub.heartbeat(ApplicationInstanceHeartbeat.newBuilder() - .setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID) - .setHeartbeatTime(System.currentTimeMillis()) - .build()); - } - } - - ApplicationDictionary.INSTANCE.syncRemoteDictionary(applicationRegisterServiceBlockingStub); - OperationNameDictionary.INSTANCE.syncRemoteDictionary(serviceNameDiscoveryServiceBlockingStub); - } - } - } - } catch (Throwable t) { - logger.error(t, "AppAndServiceRegisterClient execute fail."); - ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(t); - } - } - } - - @Override - public void afterFinished(TraceSegment traceSegment) { - lastSegmentTime = System.currentTimeMillis(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java deleted file mode 100644 index ed795061c58c..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; -import org.skywalking.apm.agent.core.conf.Config; - -/** - * The CollectorDiscoveryService is responsible for start {@link DiscoveryRestServiceClient}. - * - * @author wusheng - */ -public class CollectorDiscoveryService implements BootService { - private ScheduledFuture future; - - @Override - public void beforeBoot() throws Throwable { - - } - - @Override - public void boot() throws Throwable { - future = Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("CollectorDiscoveryService")) - .scheduleAtFixedRate(new DiscoveryRestServiceClient(), 0, - Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS); - } - - @Override - public void afterBoot() throws Throwable { - - } - - @Override - public void shutdown() throws Throwable { - future.cancel(true); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelListener.java deleted file mode 100644 index 4456a23bf60c..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -/** - * @author wusheng - */ -public interface GRPCChannelListener { - void statusChanged(GRPCChannelStatus status); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelStatus.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelStatus.java deleted file mode 100644 index 5be5b7f61361..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelStatus.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -/** - * @author wusheng - */ -public enum GRPCChannelStatus { - CONNECTED, - DISCONNECT -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java deleted file mode 100644 index 67e95f6bbe0f..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCStreamServiceStatus.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -/** - * @author wusheng - */ -public class GRPCStreamServiceStatus { - private volatile boolean status; - - public GRPCStreamServiceStatus(boolean status) { - this.status = status; - } - - public boolean isStatus() { - return status; - } - - public void finished() { - this.status = true; - } - - /** - * @param maxTimeout max wait time, milliseconds. - */ - public boolean wait4Finish(long maxTimeout) { - long time = 0; - while (!status) { - if (time > maxTimeout) { - break; - } - try2Sleep(5); - time += 5; - } - return status; - } - - /** - * Try to sleep, and ignore the {@link InterruptedException} - * - * @param millis the length of time to sleep in milliseconds - */ - private void try2Sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - - } - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/RESTResponseStatusError.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/RESTResponseStatusError.java deleted file mode 100644 index d088e146dd92..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/RESTResponseStatusError.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -/** - * The RESTResponseStatusError represents the REST-Service discovery got an unexpected response code. - * Most likely, the response code is not 200. - * - * @author wusheng - */ -class RESTResponseStatusError extends Exception { - RESTResponseStatusError(int responseCode) { - super("Unexpected service response code: " + responseCode); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java deleted file mode 100644 index b44012e12123..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -import io.grpc.ManagedChannel; -import io.grpc.stub.StreamObserver; -import java.util.List; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.commons.datacarrier.DataCarrier; -import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy; -import org.skywalking.apm.commons.datacarrier.consumer.IConsumer; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.network.proto.Downstream; -import org.skywalking.apm.network.proto.TraceSegmentServiceGrpc; -import org.skywalking.apm.network.proto.UpstreamSegment; - -import static org.skywalking.apm.agent.core.conf.Config.Buffer.BUFFER_SIZE; -import static org.skywalking.apm.agent.core.conf.Config.Buffer.CHANNEL_SIZE; -import static org.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED; - -/** - * @author wusheng - */ -public class TraceSegmentServiceClient implements BootService, IConsumer, TracingContextListener, GRPCChannelListener { - private static final ILog logger = LogManager.getLogger(TraceSegmentServiceClient.class); - private static final int TIMEOUT = 30 * 1000; - - private long lastLogTime; - private long segmentUplinkedCounter; - private long segmentAbandonedCounter; - private volatile DataCarrier carrier; - private volatile TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub; - private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT; - - @Override - public void beforeBoot() throws Throwable { - ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(this); - } - - @Override - public void boot() throws Throwable { - lastLogTime = System.currentTimeMillis(); - segmentUplinkedCounter = 0; - segmentAbandonedCounter = 0; - carrier = new DataCarrier(CHANNEL_SIZE, BUFFER_SIZE); - carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE); - carrier.consume(this, 1); - } - - @Override - public void afterBoot() throws Throwable { - TracingContext.ListenerManager.add(this); - } - - @Override - public void shutdown() throws Throwable { - carrier.shutdownConsumers(); - } - - @Override - public void init() { - - } - - @Override - public void consume(List data) { - if (CONNECTED.equals(status)) { - final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false); - StreamObserver upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver() { - @Override - public void onNext(Downstream downstream) { - - } - - @Override - public void onError(Throwable throwable) { - status.finished(); - if (logger.isErrorEnable()) { - logger.error(throwable, "Send UpstreamSegment to collector fail with a grpc internal exception."); - } - ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable); - } - - @Override - public void onCompleted() { - status.finished(); - } - }); - - for (TraceSegment segment : data) { - try { - UpstreamSegment upstreamSegment = segment.transform(); - upstreamSegmentStreamObserver.onNext(upstreamSegment); - } catch (Throwable t) { - logger.error(t, "Transform and send UpstreamSegment to collector fail."); - } - } - upstreamSegmentStreamObserver.onCompleted(); - - if (status.wait4Finish(TIMEOUT)) { - segmentUplinkedCounter += data.size(); - } - } else { - segmentAbandonedCounter += data.size(); - } - - printUplinkStatus(); - } - - private void printUplinkStatus() { - long currentTimeMillis = System.currentTimeMillis(); - if (currentTimeMillis - lastLogTime > 30 * 1000) { - lastLogTime = currentTimeMillis; - if (segmentUplinkedCounter > 0) { - logger.debug("{} trace segments have been sent to collector.", segmentUplinkedCounter); - segmentUplinkedCounter = 0; - } - if (segmentAbandonedCounter > 0) { - logger.debug("{} trace segments have been abandoned, cause by no available channel.", segmentAbandonedCounter); - segmentAbandonedCounter = 0; - } - } - } - - @Override - public void onError(List data, Throwable t) { - logger.error(t, "Try to send {} trace segments to collector, with unexpected exception.", data.size()); - } - - @Override - public void onExit() { - - } - - @Override - public void afterFinished(TraceSegment traceSegment) { - if (traceSegment.isIgnore()) { - return; - } - if (!carrier.produce(traceSegment)) { - if (logger.isDebugEnable()) { - logger.debug("One trace segment has been abandoned, cause by buffer is full."); - } - } - } - - @Override - public void statusChanged(GRPCChannelStatus status) { - if (CONNECTED.equals(status)) { - ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel(); - serviceStub = TraceSegmentServiceGrpc.newStub(channel); - } - this.status = status; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService new file mode 100644 index 000000000000..4f1652d0338c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -0,0 +1,78 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + + +# +# Copyright 2017, OpenSkywalking Organization All rights reserved. +# +# 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. +# +# Repositories: https://github.com/OpenSkywalking/skywalking +# + +# +# Copyright 2017, Skywalking Authors All rights reserved. +# +# 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. +# + +# +# /* +# * Copyright 2017, Skywalking Authors All rights reserved. +# * +# * 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. +# */ +# + +org.apache.skywalking.apm.agent.core.remote.TraceSegmentServiceClient +org.apache.skywalking.apm.agent.core.context.ContextManager +org.apache.skywalking.apm.agent.core.remote.CollectorDiscoveryService +org.apache.skywalking.apm.agent.core.sampling.SamplingService +org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager +org.apache.skywalking.apm.agent.core.jvm.JVMService +org.apache.skywalking.apm.agent.core.remote.AppAndServiceRegisterClient diff --git a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.skywalking.apm.agent.core.boot.BootService deleted file mode 100644 index 215b897875df..000000000000 --- a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.skywalking.apm.agent.core.boot.BootService +++ /dev/null @@ -1,95 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Project repository: https://github.com/OpenSkywalking/skywalking -# - -# -# Copyright 2017, OpenSkywalking Organization All rights reserved. -# -# 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. -# -# Repositories: https://github.com/OpenSkywalking/skywalking -# - -# -# Copyright 2017, Skywalking Authors All rights reserved. -# -# 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. -# - -# -# /* -# * Copyright 2017, Skywalking Authors All rights reserved. -# * -# * 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. -# */ -# - -org.skywalking.apm.agent.core.remote.TraceSegmentServiceClient -org.skywalking.apm.agent.core.context.ContextManager -org.skywalking.apm.agent.core.remote.CollectorDiscoveryService -org.skywalking.apm.agent.core.sampling.SamplingService -org.skywalking.apm.agent.core.remote.GRPCChannelManager -org.skywalking.apm.agent.core.jvm.JVMService -org.skywalking.apm.agent.core.remote.AppAndServiceRegisterClient diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java new file mode 100644 index 000000000000..2cb097fb5540 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +/** + * @author zhangkewei + */ +public class DefaultNamedThreadFactoryTest { + + @Test + public void testNamedThread() throws Exception { + Thread newThread = new DefaultNamedThreadFactory("DefaultNamedThreadFactoryTest").newThread(new Runnable() { + @Override + public void run() { + + } + }); + newThread.start(); + assertNotNull(newThread.getName()); + Assert.assertTrue(newThread.getName().contains("DefaultNamedThreadFactoryTest")); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/ServiceManagerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/ServiceManagerTest.java new file mode 100644 index 000000000000..e5b167909585 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/boot/ServiceManagerTest.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.boot; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.List; + +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule; +import org.junit.AfterClass; +import org.junit.Rule; +import org.junit.Test; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; +import org.apache.skywalking.apm.agent.core.jvm.JVMService; +import org.apache.skywalking.apm.agent.core.remote.CollectorDiscoveryService; +import org.apache.skywalking.apm.agent.core.remote.GRPCChannelListener; +import org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager; +import org.apache.skywalking.apm.agent.core.remote.TraceSegmentServiceClient; +import org.apache.skywalking.apm.agent.core.sampling.SamplingService; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ServiceManagerTest { + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @AfterClass + public static void afterClass() { + ServiceManager.INSTANCE.shutdown(); + } + + @Test + public void testServiceDependencies() throws Exception { + HashMap registryService = getFieldValue(ServiceManager.INSTANCE, "bootedServices"); + + assertThat(registryService.size(), is(7)); + + assertTraceSegmentServiceClient(ServiceManager.INSTANCE.findService(TraceSegmentServiceClient.class)); + assertContextManager(ServiceManager.INSTANCE.findService(ContextManager.class)); + assertCollectorDiscoveryService(ServiceManager.INSTANCE.findService(CollectorDiscoveryService.class)); + assertGRPCChannelManager(ServiceManager.INSTANCE.findService(GRPCChannelManager.class)); + assertSamplingService(ServiceManager.INSTANCE.findService(SamplingService.class)); + assertJVMService(ServiceManager.INSTANCE.findService(JVMService.class)); + + assertTracingContextListener(); + assertIgnoreTracingContextListener(); + } + + private void assertIgnoreTracingContextListener() throws Exception { + List listeners = getFieldValue(IgnoredTracerContext.ListenerManager.class, "LISTENERS"); + assertThat(listeners.size(), is(1)); + + assertThat(listeners.contains(ServiceManager.INSTANCE.findService(ContextManager.class)), is(true)); + } + + private void assertTracingContextListener() throws Exception { + List listeners = getFieldValue(TracingContext.ListenerManager.class, "LISTENERS"); + assertThat(listeners.size(), is(3)); + + assertThat(listeners.contains(ServiceManager.INSTANCE.findService(ContextManager.class)), is(true)); + assertThat(listeners.contains(ServiceManager.INSTANCE.findService(TraceSegmentServiceClient.class)), is(true)); + } + + private void assertJVMService(JVMService service) { + assertNotNull(service); + } + + private void assertGRPCChannelManager(GRPCChannelManager service) throws Exception { + assertNotNull(service); + + List listeners = getFieldValue(service, "listeners"); + assertEquals(listeners.size(), 3); + } + + private void assertSamplingService(SamplingService service) { + assertNotNull(service); + } + + private void assertCollectorDiscoveryService(CollectorDiscoveryService service) { + assertNotNull(service); + } + + private void assertContextManager(ContextManager service) { + assertNotNull(service); + } + + private void assertTraceSegmentServiceClient(TraceSegmentServiceClient service) { + assertNotNull(service); + } + + private T getFieldValue(Object instance, String fieldName) throws Exception { + Field field = instance.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(instance); + } + + private T getFieldValue(Class clazz, String fieldName) throws Exception { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(clazz); + } + +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java new file mode 100644 index 000000000000..9eb4706ffcfe --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.conf; + +import org.junit.AfterClass; +import org.junit.Test; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.logging.core.LogLevel; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public class SnifferConfigInitializerTest { + + @Test + public void testLoadConfigFromJavaAgentDir() throws AgentPackageNotFoundException, ConfigNotFoundException { + System.setProperty("skywalking.agent.application_code", "testApp"); + System.setProperty("skywalking.collector.servers", "127.0.0.1:8090"); + System.setProperty("skywalking.logging.level", "info"); + SnifferConfigInitializer.initialize(); + assertThat(Config.Agent.APPLICATION_CODE, is("testApp")); + assertThat(Config.Collector.SERVERS, is("127.0.0.1:8090")); + assertThat(Config.Logging.LEVEL, is(LogLevel.INFO)); + } + + @AfterClass + public static void clear() { + Config.Logging.LEVEL = LogLevel.DEBUG; + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/ContextManagerTest.java similarity index 81% rename from apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java rename to apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/ContextManagerTest.java index d8ed9609575b..132e724acac6 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/ContextManagerTest.java @@ -16,39 +16,58 @@ * */ -package org.skywalking.apm.agent.core.context; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; import com.google.protobuf.InvalidProtocolBufferException; import java.util.List; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.AbstractTracingSpanHelper; +import org.apache.skywalking.apm.agent.core.context.util.SegmentHelper; +import org.apache.skywalking.apm.agent.core.context.util.TraceSegmentRefHelper; +import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.core.test.tools.TracingSegmentRunner; +import org.hamcrest.MatcherAssert; import org.junit.*; import org.junit.runner.RunWith; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.context.util.AbstractTracingSpanHelper; -import org.skywalking.apm.agent.core.context.util.SegmentHelper; -import org.skywalking.apm.agent.core.context.util.SpanHelper; -import org.skywalking.apm.agent.core.context.util.TraceSegmentRefHelper; -import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; -import org.skywalking.apm.agent.core.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.core.test.tools.SegmentStorage; -import org.skywalking.apm.agent.core.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.core.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.proto.KeyWithStringValue; -import org.skywalking.apm.network.proto.LogMessage; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.proto.SpanType; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.proto.TraceSegmentReference; -import org.skywalking.apm.network.proto.UpstreamSegment; -import org.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.context.util.SpanHelper; +import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.apache.skywalking.apm.agent.core.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.core.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.network.proto.KeyWithStringValue; +import org.apache.skywalking.apm.network.proto.LogMessage; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.SpanType; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.TraceSegmentReference; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -97,7 +116,7 @@ public void createSpanWithInvalidateContextCarrier() { AbstractTracingSpan actualEntrySpan = spanList.get(0); assertThat(actualEntrySpan.getOperationName(), is("/testEntrySpan")); assertThat(actualEntrySpan.getSpanId(), is(0)); - assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1)); + MatcherAssert.assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1)); } @Test @@ -134,7 +153,7 @@ public void createMultipleEntrySpan() { assertThat(actualSegment.getRefs().size(), is(1)); TraceSegmentRef ref = actualSegment.getRefs().get(0); - assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080")); + MatcherAssert.assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080")); assertThat(ref.getEntryOperationName(), is("/portal/")); assertThat(ref.getEntryOperationId(), is(0)); diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java new file mode 100644 index 000000000000..3de1009aaf89 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context; + +import java.util.LinkedList; + +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.NoopSpan; +import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.core.test.tools.TracingSegmentRunner; +import org.junit.*; +import org.junit.runner.RunWith; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.core.test.tools.SegmentStoragePoint; + +import static junit.framework.TestCase.assertNull; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith(TracingSegmentRunner.class) +public class IgnoredTracerContextTest { + + @SegmentStoragePoint + private SegmentStorage storage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Before + public void setUp() throws Exception { + RemoteDownstreamConfig.Agent.APPLICATION_ID = 1; + RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1; + } + + @AfterClass + public static void afterClass() { + ServiceManager.INSTANCE.shutdown(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void ignoredTraceContextWithSampling() { + Config.Agent.SAMPLE_N_PER_3_SECS = 1; + ServiceManager.INSTANCE.boot(); + ContextManager.createLocalSpan("/test1"); + ContextManager.stopSpan(); + + ContextManager.createLocalSpan("/test2"); + ContextManager.stopSpan(); + + ContextManager.createLocalSpan("/test3"); + ContextManager.stopSpan(); + + ContextManager.createLocalSpan("/test4"); + ContextManager.stopSpan(); + + assertThat(storage.getIgnoredTracerContexts().size(), is(3)); + assertThat(storage.getTraceSegments().size(), is(1)); + + } + + @Test + public void ignoredTraceContextWithExcludeOperationName() { + AbstractSpan abstractSpan = ContextManager.createEntrySpan("test.js", null); + ContextManager.stopSpan(); + + assertThat(abstractSpan.getClass().getName(), is(NoopSpan.class.getName())); + LinkedList ignoredTracerContexts = storage.getIgnoredTracerContexts(); + assertThat(ignoredTracerContexts.size(), is(1)); + } + + @Test + public void ignoredTraceContextWithEmptyOperationName() { + ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan abstractSpan = ContextManager.createExitSpan("", contextCarrier, "127.0.0.1:2181"); + ContextManager.stopSpan(); + + assertThat(abstractSpan.getClass().getName(), is(NoopSpan.class.getName())); + assertNull(contextCarrier.getEntryOperationName()); + assertThat(contextCarrier.getSpanId(), is(-1)); + assertNull(contextCarrier.getPeerHost()); + + LinkedList ignoredTracerContexts = storage.getIgnoredTracerContexts(); + assertThat(ignoredTracerContexts.size(), is(1)); + } + +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java new file mode 100644 index 000000000000..3d4d51938af2 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +import java.util.Collections; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; + +public class AbstractTracingSpanHelper { + public static int getParentSpanId(AbstractTracingSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "parentSpanId"); + } catch (Exception e) { + } + + return -9999; + } + + public static List getLogs(AbstractTracingSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "logs"); + } catch (Exception e) { + } + + return Collections.emptyList(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/FieldGetter.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/FieldGetter.java new file mode 100644 index 000000000000..18264e6ea42f --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/FieldGetter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +import java.lang.reflect.Field; + +public class FieldGetter { + public static T getValue(Object instance, + String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(instance); + } + + public static T get2LevelParentFieldValue(Object instance, + String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getClass().getSuperclass().getSuperclass().getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(instance); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SegmentHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SegmentHelper.java new file mode 100644 index 000000000000..d39f2c63fa46 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SegmentHelper.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; + +public class SegmentHelper { + + public static List getSpan(TraceSegment traceSegment) { + try { + return FieldGetter.getValue(traceSegment, "spans"); + } catch (Exception e) { + } + + return null; + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SpanHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SpanHelper.java new file mode 100644 index 000000000000..5675670c55cb --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/SpanHelper.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; + +public class SpanHelper { + + public static SpanLayer getLayer(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "layer"); + } catch (Exception e) { + } + + return null; + } + + public static int getComponentId(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "componentId"); + } catch (Exception e) { + } + + return -1; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java new file mode 100644 index 000000000000..f1a08268592c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.context.util; + +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; + +public class TraceSegmentRefHelper { + public static String getPeerHost(TraceSegmentRef ref) { + try { + return FieldGetter.getValue(ref, "peerHost"); + } catch (Exception e) { + } + + return null; + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java new file mode 100644 index 000000000000..3d74798e1d47 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by wusheng on 2017/2/28. + */ +public class EasyLogResolverTest { + @Test + public void testGetLogger() { + Assert.assertTrue(new EasyLogResolver().getLogger(EasyLogResolverTest.class) instanceof EasyLogger); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java rename to apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java index 761bf8e7487a..a3fc212d581a 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/EasyLoggerTest.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.agent.core.logging.core; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; -import org.skywalking.apm.agent.core.conf.Constants; +import org.apache.skywalking.apm.agent.core.conf.Constants; import java.io.PrintStream; @@ -116,7 +134,7 @@ public void testFormat() { String formatLines = logger.format(exception); String[] lines = formatLines.split(Constants.LINE_SEPARATOR); Assert.assertEquals("java.lang.NullPointerException", lines[1]); - Assert.assertEquals("\tat org.skywalking.apm.agent.core.logging.core.EasyLoggerTest.testFormat(EasyLoggerTest.java:114)", lines[2]); + Assert.assertEquals("\tat org.apache.skywalking.apm.agent.core.logging.core.EasyLoggerTest.testFormat(EasyLoggerTest.java:132)", lines[2]); } @AfterClass diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriterTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriterTest.java new file mode 100644 index 000000000000..cb8eb286f38d --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriterTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.conf.Constants; + +import java.io.File; +import java.io.IOException; + +/** + * @author wusheng + */ +public class FileWriterTest { + + @BeforeClass + public static void beforeTestFile() throws IOException { + Config.Logging.MAX_FILE_SIZE = 10; + File directory = new File(""); + Config.Logging.DIR = directory.getCanonicalPath() + Constants.PATH_SEPARATOR + "/log-test/"; + } + + @Test + public void testWriteFile() throws InterruptedException { + FileWriter writer = FileWriter.get(); + for (int i = 0; i < 100; i++) { + writer.write("abcd"); + } + + Thread.sleep(10000L); + } + + @AfterClass + public static void clear() { + Config.Logging.MAX_FILE_SIZE = 300 * 1024 * 1024; + deleteDir(new File(Config.Logging.DIR)); + Config.Logging.DIR = ""; + } + + private static boolean deleteDir(File dir) { + if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i = 0; i < children.length; i++) { + boolean success = deleteDir(new File(dir, children[i])); + if (!success) { + return false; + } + } + } + return dir.delete(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java new file mode 100644 index 000000000000..5a8cd5719be2 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.logging.core; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.PrintStream; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.times; + +/** + * Created by wusheng on 2017/2/28. + */ +public class SystemOutWriterTest { + private static PrintStream OUT_REF; + + @BeforeClass + public static void initAndHoldOut() { + OUT_REF = System.out; + } + + @Test + public void testWrite() { + PrintStream mockStream = Mockito.mock(PrintStream.class); + System.setOut(mockStream); + + SystemOutWriter.INSTANCE.write("hello"); + + Mockito.verify(mockStream, times(1)).println(anyString()); + } + + @AfterClass + public static void reset() { + System.setOut(OUT_REF); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java similarity index 79% rename from apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java rename to apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java index 7f248eda6015..c136686ac774 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java @@ -16,17 +16,36 @@ * */ -package org.skywalking.apm.agent.core.remote; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.io.IOException; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule; +import org.hamcrest.MatcherAssert; import org.junit.*; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.core.conf.Config; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -81,7 +100,7 @@ public void setUpBeforeClass() { public void testWithoutCollectorServer() throws RESTResponseStatusError, IOException { client = new DiscoveryRestServiceClient(); client.run(); - assertThat(RemoteDownstreamConfig.Collector.GRPC_SERVERS.size(), is(0)); + MatcherAssert.assertThat(RemoteDownstreamConfig.Collector.GRPC_SERVERS.size(), is(0)); } @Test diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java similarity index 81% rename from apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java rename to apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java index cedf851aa2e0..72db4538b66b 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent.core.remote; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; import io.grpc.NameResolver; import io.grpc.Status; @@ -25,6 +43,7 @@ import io.grpc.testing.GrpcServerRule; import java.util.ArrayList; import java.util.List; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,8 +52,7 @@ import org.mockito.Spy; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.conf.Config; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java new file mode 100644 index 000000000000..ececfd029fb1 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.remote; + +import com.google.protobuf.InvalidProtocolBufferException; +import io.grpc.stub.StreamObserver; +import io.grpc.testing.GrpcServerRule; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.core.test.tools.TracingSegmentRunner; +import org.junit.*; +import org.junit.runner.RunWith; +import org.powermock.reflect.Whitebox; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.core.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.network.proto.Downstream; +import org.apache.skywalking.apm.network.proto.SpanObject; +import org.apache.skywalking.apm.network.proto.SpanType; +import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc; +import org.apache.skywalking.apm.network.proto.UpstreamSegment; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.spy; + +@RunWith(TracingSegmentRunner.class) +public class TraceSegmentServiceClientTest { + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Rule + public GrpcServerRule grpcServerRule = new GrpcServerRule().directExecutor(); + + @SegmentStoragePoint + private SegmentStorage storage; + + private TraceSegmentServiceClient serviceClient = new TraceSegmentServiceClient(); + private List upstreamSegments; + + private TraceSegmentServiceGrpc.TraceSegmentServiceImplBase serviceImplBase = new TraceSegmentServiceGrpc.TraceSegmentServiceImplBase() { + @Override + public StreamObserver collect(final StreamObserver responseObserver) { + return new StreamObserver() { + @Override + public void onNext(UpstreamSegment value) { + upstreamSegments.add(value); + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onCompleted() { + responseObserver.onNext(Downstream.getDefaultInstance()); + responseObserver.onCompleted(); + } + }; + } + }; + + @BeforeClass + public static void setUpBeforeClass() { + RemoteDownstreamConfig.Agent.APPLICATION_ID = 1; + RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1; + } + + @AfterClass + public static void afterClass() { + ServiceManager.INSTANCE.shutdown(); + } + + @Before + public void setUp() throws Throwable { + Whitebox.setInternalState(ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect", false); + spy(serviceClient); + + Whitebox.setInternalState(serviceClient, "serviceStub", + TraceSegmentServiceGrpc.newStub(grpcServerRule.getChannel())); + Whitebox.setInternalState(serviceClient, "status", GRPCChannelStatus.CONNECTED); + + upstreamSegments = new ArrayList(); + } + + @Test + public void testSendTraceSegmentWithoutException() throws InvalidProtocolBufferException { + grpcServerRule.getServiceRegistry().addService(serviceImplBase); + + AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null); + firstEntrySpan.setComponent(ComponentsDefine.TOMCAT); + Tags.HTTP.METHOD.set(firstEntrySpan, "GET"); + Tags.URL.set(firstEntrySpan, "127.0.0.1:8080"); + SpanLayer.asHttp(firstEntrySpan); + ContextManager.stopSpan(); + + serviceClient.consume(storage.getTraceSegments()); + + assertThat(upstreamSegments.size(), is(1)); + UpstreamSegment upstreamSegment = upstreamSegments.get(0); + assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1)); + TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment()); + assertThat(traceSegmentObject.getSpans(0).getRefsCount(), is(0)); + assertThat(traceSegmentObject.getSpansCount(), is(1)); + + SpanObject spanObject = traceSegmentObject.getSpans(0); + assertThat(spanObject.getSpanType(), is(SpanType.Entry)); + assertThat(spanObject.getSpanId(), is(0)); + assertThat(spanObject.getParentSpanId(), is(-1)); + } + + @Test + public void testSendTraceSegmentWithException() throws InvalidProtocolBufferException { + grpcServerRule.getServiceRegistry().addService(serviceImplBase); + + AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null); + firstEntrySpan.setComponent(ComponentsDefine.TOMCAT); + Tags.HTTP.METHOD.set(firstEntrySpan, "GET"); + Tags.URL.set(firstEntrySpan, "127.0.0.1:8080"); + SpanLayer.asHttp(firstEntrySpan); + ContextManager.stopSpan(); + grpcServerRule.getServer().shutdownNow(); + serviceClient.consume(storage.getTraceSegments()); + + assertThat(upstreamSegments.size(), is(0)); + + boolean reconnect = Whitebox.getInternalState(ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect"); + assertThat(reconnect, is(true)); + + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/AgentServiceRule.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/AgentServiceRule.java new file mode 100644 index 000000000000..213d5db32e4e --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/AgentServiceRule.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.test.tools; + +import java.util.HashMap; +import java.util.LinkedList; +import org.junit.rules.ExternalResource; +import org.powermock.reflect.Whitebox; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; + +public class AgentServiceRule extends ExternalResource { + + @Override + protected void after() { + super.after(); + Whitebox.setInternalState(ServiceManager.INSTANCE, "bootedServices", new HashMap()); + Whitebox.setInternalState(TracingContext.ListenerManager.class, "LISTENERS", new LinkedList()); + Whitebox.setInternalState(IgnoredTracerContext.ListenerManager.class, "LISTENERS", new LinkedList()); + } + + @Override + protected void before() throws Throwable { + super.before(); + ServiceManager.INSTANCE.boot(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStorage.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStorage.java new file mode 100644 index 000000000000..81c66e850810 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStorage.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.test.tools; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; + +public class SegmentStorage { + private LinkedList traceSegments; + private LinkedList ignoredTracerContexts; + + public SegmentStorage() { + traceSegments = new LinkedList(); + ignoredTracerContexts = new LinkedList(); + } + + void addTraceSegment(TraceSegment segment) { + traceSegments.add(segment); + } + + public List getTraceSegments() { + return traceSegments; + } + + void addIgnoreTraceContext(IgnoredTracerContext context) { + this.ignoredTracerContexts.add(context); + } + + public LinkedList getIgnoredTracerContexts() { + return ignoredTracerContexts; + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java new file mode 100644 index 000000000000..a647530f72e1 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.test.tools; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface SegmentStoragePoint { +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java new file mode 100644 index 000000000000..aebf9b5ea915 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.core.test.tools; + +import java.lang.reflect.Field; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; +import org.apache.skywalking.apm.agent.core.context.IgnoreTracerContextListener; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; + +public class TracingSegmentRunner extends BlockJUnit4ClassRunner { + private TracingContextListener tracingContextListener; + private IgnoreTracerContextListener ignoreTracerContextListener; + private Field field; + private Object targetObject; + private SegmentStorage tracingData; + + public TracingSegmentRunner(Class klass) throws InitializationError { + super(klass); + for (Field field : klass.getDeclaredFields()) { + if (field.isAnnotationPresent(SegmentStoragePoint.class) && field.getType().equals(SegmentStorage.class)) { + this.field = field; + this.field.setAccessible(true); + break; + } + } + } + + @Override + protected Object createTest() throws Exception { + targetObject = super.createTest(); + return targetObject; + } + + @Override protected Statement withAfters(FrameworkMethod method, Object target, final Statement statement) { + return new Statement() { + @Override public void evaluate() throws Throwable { + if (field != null) { + try { + tracingData = new SegmentStorage(); + field.set(targetObject, tracingData); + } catch (IllegalAccessException e) { + } + } + tracingContextListener = new TracingContextListener() { + @Override + public void afterFinished(TraceSegment traceSegment) { + tracingData.addTraceSegment(traceSegment); + } + }; + + ignoreTracerContextListener = new IgnoreTracerContextListener() { + @Override + public void afterFinished(IgnoredTracerContext tracerContext) { + tracingData.addIgnoreTraceContext(tracerContext); + } + }; + + TracingContext.ListenerManager.add(tracingContextListener); + IgnoredTracerContext.ListenerManager.add(ignoreTracerContextListener); + try { + statement.evaluate(); + } finally { + TracingContext.ListenerManager.remove(tracingContextListener); + IgnoredTracerContext.ListenerManager.remove(ignoreTracerContextListener); + } + } + }; + } +} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java deleted file mode 100644 index 919061c0b8a1..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/DefaultNamedThreadFactoryTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.boot; - -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; - -/** - * @author zhangkewei - */ -public class DefaultNamedThreadFactoryTest { - - @Test - public void testNamedThread() throws Exception { - Thread newThread = new DefaultNamedThreadFactory("DefaultNamedThreadFactoryTest").newThread(new Runnable() { - @Override - public void run() { - - } - }); - newThread.start(); - assertNotNull(newThread.getName()); - Assert.assertTrue(newThread.getName().contains("DefaultNamedThreadFactoryTest")); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/ServiceManagerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/ServiceManagerTest.java deleted file mode 100644 index 985e0b2b5744..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/ServiceManagerTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.boot; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.List; - -import org.junit.AfterClass; -import org.junit.Rule; -import org.junit.Test; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; -import org.skywalking.apm.agent.core.jvm.JVMService; -import org.skywalking.apm.agent.core.remote.CollectorDiscoveryService; -import org.skywalking.apm.agent.core.remote.GRPCChannelListener; -import org.skywalking.apm.agent.core.remote.GRPCChannelManager; -import org.skywalking.apm.agent.core.remote.TraceSegmentServiceClient; -import org.skywalking.apm.agent.core.sampling.SamplingService; -import org.skywalking.apm.agent.core.test.tools.AgentServiceRule; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class ServiceManagerTest { - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - @AfterClass - public static void afterClass() { - ServiceManager.INSTANCE.shutdown(); - } - - @Test - public void testServiceDependencies() throws Exception { - HashMap registryService = getFieldValue(ServiceManager.INSTANCE, "bootedServices"); - - assertThat(registryService.size(), is(7)); - - assertTraceSegmentServiceClient(ServiceManager.INSTANCE.findService(TraceSegmentServiceClient.class)); - assertContextManager(ServiceManager.INSTANCE.findService(ContextManager.class)); - assertCollectorDiscoveryService(ServiceManager.INSTANCE.findService(CollectorDiscoveryService.class)); - assertGRPCChannelManager(ServiceManager.INSTANCE.findService(GRPCChannelManager.class)); - assertSamplingService(ServiceManager.INSTANCE.findService(SamplingService.class)); - assertJVMService(ServiceManager.INSTANCE.findService(JVMService.class)); - - assertTracingContextListener(); - assertIgnoreTracingContextListener(); - } - - private void assertIgnoreTracingContextListener() throws Exception { - List listeners = getFieldValue(IgnoredTracerContext.ListenerManager.class, "LISTENERS"); - assertThat(listeners.size(), is(1)); - - assertThat(listeners.contains(ServiceManager.INSTANCE.findService(ContextManager.class)), is(true)); - } - - private void assertTracingContextListener() throws Exception { - List listeners = getFieldValue(TracingContext.ListenerManager.class, "LISTENERS"); - assertThat(listeners.size(), is(3)); - - assertThat(listeners.contains(ServiceManager.INSTANCE.findService(ContextManager.class)), is(true)); - assertThat(listeners.contains(ServiceManager.INSTANCE.findService(TraceSegmentServiceClient.class)), is(true)); - } - - private void assertJVMService(JVMService service) { - assertNotNull(service); - } - - private void assertGRPCChannelManager(GRPCChannelManager service) throws Exception { - assertNotNull(service); - - List listeners = getFieldValue(service, "listeners"); - assertEquals(listeners.size(), 3); - } - - private void assertSamplingService(SamplingService service) { - assertNotNull(service); - } - - private void assertCollectorDiscoveryService(CollectorDiscoveryService service) { - assertNotNull(service); - } - - private void assertContextManager(ContextManager service) { - assertNotNull(service); - } - - private void assertTraceSegmentServiceClient(TraceSegmentServiceClient service) { - assertNotNull(service); - } - - private T getFieldValue(Object instance, String fieldName) throws Exception { - Field field = instance.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(instance); - } - - private T getFieldValue(Class clazz, String fieldName) throws Exception { - Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(clazz); - } - -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java deleted file mode 100644 index 778f699199f6..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.conf; - -import org.junit.AfterClass; -import org.junit.Test; -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.logging.core.LogLevel; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class SnifferConfigInitializerTest { - - @Test - public void testLoadConfigFromJavaAgentDir() throws AgentPackageNotFoundException, ConfigNotFoundException { - System.setProperty("skywalking.agent.application_code", "testApp"); - System.setProperty("skywalking.collector.servers", "127.0.0.1:8090"); - System.setProperty("skywalking.logging.level", "info"); - SnifferConfigInitializer.initialize(); - assertThat(Config.Agent.APPLICATION_CODE, is("testApp")); - assertThat(Config.Collector.SERVERS, is("127.0.0.1:8090")); - assertThat(Config.Logging.LEVEL, is(LogLevel.INFO)); - } - - @AfterClass - public static void clear() { - Config.Logging.LEVEL = LogLevel.DEBUG; - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java deleted file mode 100644 index 8cd98a273b61..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context; - -import java.util.LinkedList; - -import org.junit.*; -import org.junit.runner.RunWith; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.NoopSpan; -import org.skywalking.apm.agent.core.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.core.test.tools.SegmentStorage; -import org.skywalking.apm.agent.core.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.core.test.tools.TracingSegmentRunner; - -import static junit.framework.TestCase.assertNull; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -@RunWith(TracingSegmentRunner.class) -public class IgnoredTracerContextTest { - - @SegmentStoragePoint - private SegmentStorage storage; - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - @Before - public void setUp() throws Exception { - RemoteDownstreamConfig.Agent.APPLICATION_ID = 1; - RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1; - } - - @AfterClass - public static void afterClass() { - ServiceManager.INSTANCE.shutdown(); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void ignoredTraceContextWithSampling() { - Config.Agent.SAMPLE_N_PER_3_SECS = 1; - ServiceManager.INSTANCE.boot(); - ContextManager.createLocalSpan("/test1"); - ContextManager.stopSpan(); - - ContextManager.createLocalSpan("/test2"); - ContextManager.stopSpan(); - - ContextManager.createLocalSpan("/test3"); - ContextManager.stopSpan(); - - ContextManager.createLocalSpan("/test4"); - ContextManager.stopSpan(); - - assertThat(storage.getIgnoredTracerContexts().size(), is(3)); - assertThat(storage.getTraceSegments().size(), is(1)); - - } - - @Test - public void ignoredTraceContextWithExcludeOperationName() { - AbstractSpan abstractSpan = ContextManager.createEntrySpan("test.js", null); - ContextManager.stopSpan(); - - assertThat(abstractSpan.getClass().getName(), is(NoopSpan.class.getName())); - LinkedList ignoredTracerContexts = storage.getIgnoredTracerContexts(); - assertThat(ignoredTracerContexts.size(), is(1)); - } - - @Test - public void ignoredTraceContextWithEmptyOperationName() { - ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan abstractSpan = ContextManager.createExitSpan("", contextCarrier, "127.0.0.1:2181"); - ContextManager.stopSpan(); - - assertThat(abstractSpan.getClass().getName(), is(NoopSpan.class.getName())); - assertNull(contextCarrier.getEntryOperationName()); - assertThat(contextCarrier.getSpanId(), is(-1)); - assertNull(contextCarrier.getPeerHost()); - - LinkedList ignoredTracerContexts = storage.getIgnoredTracerContexts(); - assertThat(ignoredTracerContexts.size(), is(1)); - } - -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java deleted file mode 100644 index 3550a09c71f6..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -import java.util.Collections; -import java.util.List; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; - -public class AbstractTracingSpanHelper { - public static int getParentSpanId(AbstractTracingSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "parentSpanId"); - } catch (Exception e) { - } - - return -9999; - } - - public static List getLogs(AbstractTracingSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "logs"); - } catch (Exception e) { - } - - return Collections.emptyList(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java deleted file mode 100644 index 69bd4f7aa46b..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -import java.lang.reflect.Field; - -public class FieldGetter { - public static T getValue(Object instance, - String fieldName) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(instance); - } - - public static T get2LevelParentFieldValue(Object instance, - String fieldName) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getClass().getSuperclass().getSuperclass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(instance); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java deleted file mode 100644 index dae8496e54c1..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -import java.util.List; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public class SegmentHelper { - - public static List getSpan(TraceSegment traceSegment) { - try { - return FieldGetter.getValue(traceSegment, "spans"); - } catch (Exception e) { - } - - return null; - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SpanHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SpanHelper.java deleted file mode 100644 index e6cf74602b76..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SpanHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; - -public class SpanHelper { - - public static SpanLayer getLayer(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "layer"); - } catch (Exception e) { - } - - return null; - } - - public static int getComponentId(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "componentId"); - } catch (Exception e) { - } - - return -1; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java deleted file mode 100644 index a62dc1cd3266..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.context.util; - -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; - -public class TraceSegmentRefHelper { - public static String getPeerHost(TraceSegmentRef ref) { - try { - return FieldGetter.getValue(ref, "peerHost"); - } catch (Exception e) { - } - - return null; - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java deleted file mode 100644 index f5a8a457f501..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/EasyLogResolverTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by wusheng on 2017/2/28. - */ -public class EasyLogResolverTest { - @Test - public void testGetLogger() { - Assert.assertTrue(new EasyLogResolver().getLogger(EasyLogResolverTest.class) instanceof EasyLogger); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/FileWriterTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/FileWriterTest.java deleted file mode 100644 index dd9fdfb0a04c..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/FileWriterTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.Constants; - -import java.io.File; -import java.io.IOException; - -/** - * @author wusheng - */ -public class FileWriterTest { - - @BeforeClass - public static void beforeTestFile() throws IOException { - Config.Logging.MAX_FILE_SIZE = 10; - File directory = new File(""); - Config.Logging.DIR = directory.getCanonicalPath() + Constants.PATH_SEPARATOR + "/log-test/"; - } - - @Test - public void testWriteFile() throws InterruptedException { - FileWriter writer = FileWriter.get(); - for (int i = 0; i < 100; i++) { - writer.write("abcd"); - } - - Thread.sleep(10000L); - } - - @AfterClass - public static void clear() { - Config.Logging.MAX_FILE_SIZE = 300 * 1024 * 1024; - deleteDir(new File(Config.Logging.DIR)); - Config.Logging.DIR = ""; - } - - private static boolean deleteDir(File dir) { - if (dir.isDirectory()) { - String[] children = dir.list(); - for (int i = 0; i < children.length; i++) { - boolean success = deleteDir(new File(dir, children[i])); - if (!success) { - return false; - } - } - } - return dir.delete(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java deleted file mode 100644 index e967dcd628ad..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/logging/core/SystemOutWriterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.logging.core; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.Mockito; - -import java.io.PrintStream; - -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.times; - -/** - * Created by wusheng on 2017/2/28. - */ -public class SystemOutWriterTest { - private static PrintStream OUT_REF; - - @BeforeClass - public static void initAndHoldOut() { - OUT_REF = System.out; - } - - @Test - public void testWrite() { - PrintStream mockStream = Mockito.mock(PrintStream.class); - System.setOut(mockStream); - - SystemOutWriter.INSTANCE.write("hello"); - - Mockito.verify(mockStream, times(1)).println(anyString()); - } - - @AfterClass - public static void reset() { - System.setOut(OUT_REF); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java deleted file mode 100644 index 41f2a2daac60..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.remote; - -import com.google.protobuf.InvalidProtocolBufferException; -import io.grpc.stub.StreamObserver; -import io.grpc.testing.GrpcServerRule; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.*; -import org.junit.runner.RunWith; -import org.powermock.reflect.Whitebox; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.core.test.tools.SegmentStorage; -import org.skywalking.apm.agent.core.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.core.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.proto.Downstream; -import org.skywalking.apm.network.proto.SpanObject; -import org.skywalking.apm.network.proto.SpanType; -import org.skywalking.apm.network.proto.TraceSegmentObject; -import org.skywalking.apm.network.proto.TraceSegmentServiceGrpc; -import org.skywalking.apm.network.proto.UpstreamSegment; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.spy; - -@RunWith(TracingSegmentRunner.class) -public class TraceSegmentServiceClientTest { - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - @Rule - public GrpcServerRule grpcServerRule = new GrpcServerRule().directExecutor(); - - @SegmentStoragePoint - private SegmentStorage storage; - - private TraceSegmentServiceClient serviceClient = new TraceSegmentServiceClient(); - private List upstreamSegments; - - private TraceSegmentServiceGrpc.TraceSegmentServiceImplBase serviceImplBase = new TraceSegmentServiceGrpc.TraceSegmentServiceImplBase() { - @Override - public StreamObserver collect(final StreamObserver responseObserver) { - return new StreamObserver() { - @Override - public void onNext(UpstreamSegment value) { - upstreamSegments.add(value); - } - - @Override - public void onError(Throwable t) { - } - - @Override - public void onCompleted() { - responseObserver.onNext(Downstream.getDefaultInstance()); - responseObserver.onCompleted(); - } - }; - } - }; - - @BeforeClass - public static void setUpBeforeClass() { - RemoteDownstreamConfig.Agent.APPLICATION_ID = 1; - RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1; - } - - @AfterClass - public static void afterClass() { - ServiceManager.INSTANCE.shutdown(); - } - - @Before - public void setUp() throws Throwable { - Whitebox.setInternalState(ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect", false); - spy(serviceClient); - - Whitebox.setInternalState(serviceClient, "serviceStub", - TraceSegmentServiceGrpc.newStub(grpcServerRule.getChannel())); - Whitebox.setInternalState(serviceClient, "status", GRPCChannelStatus.CONNECTED); - - upstreamSegments = new ArrayList(); - } - - @Test - public void testSendTraceSegmentWithoutException() throws InvalidProtocolBufferException { - grpcServerRule.getServiceRegistry().addService(serviceImplBase); - - AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null); - firstEntrySpan.setComponent(ComponentsDefine.TOMCAT); - Tags.HTTP.METHOD.set(firstEntrySpan, "GET"); - Tags.URL.set(firstEntrySpan, "127.0.0.1:8080"); - SpanLayer.asHttp(firstEntrySpan); - ContextManager.stopSpan(); - - serviceClient.consume(storage.getTraceSegments()); - - assertThat(upstreamSegments.size(), is(1)); - UpstreamSegment upstreamSegment = upstreamSegments.get(0); - assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1)); - TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment()); - assertThat(traceSegmentObject.getSpans(0).getRefsCount(), is(0)); - assertThat(traceSegmentObject.getSpansCount(), is(1)); - - SpanObject spanObject = traceSegmentObject.getSpans(0); - assertThat(spanObject.getSpanType(), is(SpanType.Entry)); - assertThat(spanObject.getSpanId(), is(0)); - assertThat(spanObject.getParentSpanId(), is(-1)); - } - - @Test - public void testSendTraceSegmentWithException() throws InvalidProtocolBufferException { - grpcServerRule.getServiceRegistry().addService(serviceImplBase); - - AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null); - firstEntrySpan.setComponent(ComponentsDefine.TOMCAT); - Tags.HTTP.METHOD.set(firstEntrySpan, "GET"); - Tags.URL.set(firstEntrySpan, "127.0.0.1:8080"); - SpanLayer.asHttp(firstEntrySpan); - ContextManager.stopSpan(); - grpcServerRule.getServer().shutdownNow(); - serviceClient.consume(storage.getTraceSegments()); - - assertThat(upstreamSegments.size(), is(0)); - - boolean reconnect = Whitebox.getInternalState(ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect"); - assertThat(reconnect, is(true)); - - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/AgentServiceRule.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/AgentServiceRule.java deleted file mode 100644 index c846e0e46749..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/AgentServiceRule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.test.tools; - -import java.util.HashMap; -import java.util.LinkedList; -import org.junit.rules.ExternalResource; -import org.powermock.reflect.Whitebox; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; - -public class AgentServiceRule extends ExternalResource { - - @Override - protected void after() { - super.after(); - Whitebox.setInternalState(ServiceManager.INSTANCE, "bootedServices", new HashMap()); - Whitebox.setInternalState(TracingContext.ListenerManager.class, "LISTENERS", new LinkedList()); - Whitebox.setInternalState(IgnoredTracerContext.ListenerManager.class, "LISTENERS", new LinkedList()); - } - - @Override - protected void before() throws Throwable { - super.before(); - ServiceManager.INSTANCE.boot(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStorage.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStorage.java deleted file mode 100644 index 2069e97d1696..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStorage.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.test.tools; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public class SegmentStorage { - private LinkedList traceSegments; - private LinkedList ignoredTracerContexts; - - public SegmentStorage() { - traceSegments = new LinkedList(); - ignoredTracerContexts = new LinkedList(); - } - - void addTraceSegment(TraceSegment segment) { - traceSegments.add(segment); - } - - public List getTraceSegments() { - return traceSegments; - } - - void addIgnoreTraceContext(IgnoredTracerContext context) { - this.ignoredTracerContexts.add(context); - } - - public LinkedList getIgnoredTracerContexts() { - return ignoredTracerContexts; - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java deleted file mode 100644 index a6fb63a348d7..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.test.tools; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SegmentStoragePoint { -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java deleted file mode 100644 index 5184e4787090..000000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.core.test.tools; - -import java.lang.reflect.Field; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.Statement; -import org.skywalking.apm.agent.core.context.IgnoreTracerContextListener; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public class TracingSegmentRunner extends BlockJUnit4ClassRunner { - private TracingContextListener tracingContextListener; - private IgnoreTracerContextListener ignoreTracerContextListener; - private Field field; - private Object targetObject; - private SegmentStorage tracingData; - - public TracingSegmentRunner(Class klass) throws InitializationError { - super(klass); - for (Field field : klass.getDeclaredFields()) { - if (field.isAnnotationPresent(SegmentStoragePoint.class) && field.getType().equals(SegmentStorage.class)) { - this.field = field; - this.field.setAccessible(true); - break; - } - } - } - - @Override - protected Object createTest() throws Exception { - targetObject = super.createTest(); - return targetObject; - } - - @Override protected Statement withAfters(FrameworkMethod method, Object target, final Statement statement) { - return new Statement() { - @Override public void evaluate() throws Throwable { - if (field != null) { - try { - tracingData = new SegmentStorage(); - field.set(targetObject, tracingData); - } catch (IllegalAccessException e) { - } - } - tracingContextListener = new TracingContextListener() { - @Override - public void afterFinished(TraceSegment traceSegment) { - tracingData.addTraceSegment(traceSegment); - } - }; - - ignoreTracerContextListener = new IgnoreTracerContextListener() { - @Override - public void afterFinished(IgnoredTracerContext tracerContext) { - tracingData.addIgnoreTraceContext(tracerContext); - } - }; - - TracingContext.ListenerManager.add(tracingContextListener); - IgnoredTracerContext.ListenerManager.add(ignoreTracerContextListener); - try { - statement.evaluate(); - } finally { - TracingContext.ListenerManager.remove(tracingContextListener); - IgnoredTracerContext.ListenerManager.remove(ignoreTracerContextListener); - } - } - }; - } -} diff --git a/apm-sniffer/apm-agent-core/src/test/resources/skywalking-plugin.def b/apm-sniffer/apm-agent-core/src/test/resources/skywalking-plugin.def index 2b07edf843fd..0475679fba36 100644 --- a/apm-sniffer/apm-agent-core/src/test/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-agent-core/src/test/resources/skywalking-plugin.def @@ -1 +1 @@ -MOCKPLUGIN=org.skywalking.apm.agent.core.plugin.MockAbstractClassEnhancePluginDefine +MOCKPLUGIN=org.apache.skywalking.apm.agent.core.plugin.MockAbstractClassEnhancePluginDefine diff --git a/apm-sniffer/apm-agent/pom.xml b/apm-sniffer/apm-agent/pom.xml index 6c130230da91..d21766c7fa2c 100644 --- a/apm-sniffer/apm-agent/pom.xml +++ b/apm-sniffer/apm-agent/pom.xml @@ -34,7 +34,7 @@ UTF-8 - org.skywalking.apm.agent.SkyWalkingAgent + org.apache.skywalking.apm.agent.SkyWalkingAgent net.bytebuddy ${shade.package}.${shade.net.bytebuddy.source} @@ -123,11 +123,5 @@ - - - bintray-wu-sheng-sky-walking-repository - wu-sheng-sky-walking-repository - https://api.bintray.com/maven/wu-sheng/skywalking/org.skywalking.apm-agent/;publish=1 - - + diff --git a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java new file mode 100644 index 000000000000..ff8112a42bea --- /dev/null +++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent; + +import java.io.File; +import java.io.IOException; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.DynamicType; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; + +/** + * @author wu-sheng + */ +public enum InstrumentDebuggingClass { + INSTANCE; + + private static final ILog logger = LogManager.getLogger(InstrumentDebuggingClass.class); + private File debuggingClassesRootPath; + + public void log(TypeDescription typeDescription, DynamicType dynamicType) { + if (!Config.Agent.IS_OPEN_DEBUGGING_CLASS) { + return; + } + + /** + * try to do I/O things in synchronized way, to avoid unexpected situations. + */ + synchronized (INSTANCE) { + try { + if (debuggingClassesRootPath == null) { + try { + debuggingClassesRootPath = new File(AgentPackagePath.getPath(), "/debugging"); + if (!debuggingClassesRootPath.exists()) { + debuggingClassesRootPath.mkdir(); + } + } catch (AgentPackageNotFoundException e) { + logger.error(e, "Can't find the root path for creating /debugging folder."); + } + } + + try { + dynamicType.saveIn(debuggingClassesRootPath); + } catch (IOException e) { + logger.error(e, "Can't save class {} to file." + typeDescription.getActualName()); + } + } catch (Throwable t) { + logger.error(t, "Save debugging classes fail."); + } + } + } +} diff --git a/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/SkyWalkingAgent.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java similarity index 77% rename from apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/SkyWalkingAgent.java rename to apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java index af78eaec0312..fa3f7cfc2c12 100644 --- a/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/SkyWalkingAgent.java +++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.agent; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent; import java.lang.instrument.Instrumentation; import java.util.List; @@ -24,15 +42,15 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.utility.JavaModule; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.SnifferConfigInitializer; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; -import org.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.EnhanceContext; -import org.skywalking.apm.agent.core.plugin.PluginBootstrap; -import org.skywalking.apm.agent.core.plugin.PluginException; -import org.skywalking.apm.agent.core.plugin.PluginFinder; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext; +import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap; +import org.apache.skywalking.apm.agent.core.plugin.PluginException; +import org.apache.skywalking.apm.agent.core.plugin.PluginFinder; +import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer; /** * The main entrance of sky-waking agent, diff --git a/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/InstrumentDebuggingClass.java b/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/InstrumentDebuggingClass.java deleted file mode 100644 index 441e15569452..000000000000 --- a/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/InstrumentDebuggingClass.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent; - -import java.io.File; -import java.io.IOException; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.dynamic.DynamicType; -import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; - -/** - * @author wu-sheng - */ -public enum InstrumentDebuggingClass { - INSTANCE; - - private static final ILog logger = LogManager.getLogger(InstrumentDebuggingClass.class); - private File debuggingClassesRootPath; - - public void log(TypeDescription typeDescription, DynamicType dynamicType) { - if (!Config.Agent.IS_OPEN_DEBUGGING_CLASS) { - return; - } - - /** - * try to do I/O things in synchronized way, to avoid unexpected situations. - */ - synchronized (INSTANCE) { - try { - if (debuggingClassesRootPath == null) { - try { - debuggingClassesRootPath = new File(AgentPackagePath.getPath(), "/debugging"); - if (!debuggingClassesRootPath.exists()) { - debuggingClassesRootPath.mkdir(); - } - } catch (AgentPackageNotFoundException e) { - logger.error(e, "Can't find the root path for creating /debugging folder."); - } - } - - try { - dynamicType.saveIn(debuggingClassesRootPath); - } catch (IOException e) { - logger.error(e, "Can't save class {} to file." + typeDescription.getActualName()); - } - } catch (Throwable t) { - logger.error(t, "Save debugging classes fail."); - } - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInstrumentation.java b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInstrumentation.java new file mode 100644 index 000000000000..0bc3e5410266 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInstrumentation.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.dubbo; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link DubboInstrumentation} presents that skywalking intercepts {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(com.alibaba.dubbo.rpc.Invoker, + * com.alibaba.dubbo.rpc.Invocation)} by using {@link DubboInterceptor}. + * + * @author zhangxin + */ +public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter"; + private static final String INTERCEPT_CLASS = "DubboInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("invoke"); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInterceptor.java b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInterceptor.java similarity index 76% rename from apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInterceptor.java rename to apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInterceptor.java index 4c2c99bb1546..7830521c81ce 100644 --- a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/apache/skywalking/apm/plugin/dubbo/DubboInterceptor.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.dubbo; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.dubbo; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; @@ -24,16 +42,16 @@ import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcContext; import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** * {@link DubboInterceptor} define how to enhance class {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, @@ -117,7 +135,7 @@ private void dealException(Throwable throwable) { } /** - * Format operation name. e.g. org.skywalking.apm.plugin.test.Test.test(String) + * Format operation name. e.g. org.apache.skywalking.apm.plugin.test.Test.test(String) * * @return operation name. */ @@ -140,7 +158,7 @@ private String generateOperationName(URL requestURL, Invocation invocation) { /** * Format request url. - * e.g. dubbo://127.0.0.1:20880/org.skywalking.apm.plugin.test.Test.test(String). + * e.g. dubbo://127.0.0.1:20880/org.apache.skywalking.apm.plugin.test.Test.test(String). * * @return request url. */ diff --git a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInstrumentation.java b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInstrumentation.java deleted file mode 100644 index 9c27bc95eaac..000000000000 --- a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInstrumentation.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.dubbo; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link DubboInstrumentation} presents that skywalking intercepts {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(com.alibaba.dubbo.rpc.Invoker, - * com.alibaba.dubbo.rpc.Invocation)} by using {@link DubboInterceptor}. - * - * @author zhangxin - */ -public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter"; - private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.dubbo.DubboInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("invoke"); - } - - @Override - public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def index 8d1917a6dc4a..6d54724f7849 100644 --- a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -dubbo=org.skywalking.apm.plugin.dubbo.DubboInstrumentation \ No newline at end of file +dubbo=DubboInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/apache/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java similarity index 75% rename from apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/apache/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java index 4d8b3dcd7d9f..2a85dca34692 100644 --- a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/apache/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.dubbo; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.dubbo; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; @@ -24,6 +42,23 @@ import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcContext; import java.util.List; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Rule; @@ -34,23 +69,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNull; @@ -94,7 +112,7 @@ public void setUp() throws Exception { PowerMockito.mockStatic(RpcContext.class); - when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.skywalking.apm.test.TestDubboService")); + when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService")); when(invocation.getMethodName()).thenReturn("test"); when(invocation.getParameterTypes()).thenReturn(new Class[] {String.class}); when(invocation.getArguments()).thenReturn(new Object[] {"abc"}); @@ -192,9 +210,9 @@ private void assertConsumerSpan(AbstractTracingSpan span) { private void assertCommonsAttribute(AbstractTracingSpan span) { List tags = SpanHelper.getTags(span); assertThat(tags.size(), is(1)); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.RPC_FRAMEWORK)); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.RPC_FRAMEWORK)); assertThat(SpanHelper.getComponentId(span), is(3)); - assertThat(tags.get(0).getValue(), is("dubbo://127.0.0.1:20880/org.skywalking.apm.test.TestDubboService.test(String)")); - assertThat(span.getOperationName(), is("org.skywalking.apm.test.TestDubboService.test(String)")); + assertThat(tags.get(0).getValue(), is("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService.test(String)")); + assertThat(span.getOperationName(), is("org.apache.skywalking.apm.test.TestDubboService.test(String)")); } } diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java new file mode 100644 index 000000000000..b2ee9898cbeb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.esjob; + +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.executor.ShardingContexts; +import com.google.common.base.Strings; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link JobExecutorInterceptor} enhances {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor#process(ShardingContext)} + * ,creating a local span that records job execution. + * + * @author gaohongtao + */ +public class JobExecutorInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ShardingContexts shardingContexts = (ShardingContexts)allArguments[0]; + Integer item = (Integer)allArguments[1]; + ShardingContext shardingContext = new ShardingContext(shardingContexts, item); + String operateName = shardingContext.getJobName(); + if (!Strings.isNullOrEmpty(shardingContext.getShardingParameter())) { + operateName += "-" + shardingContext.getShardingParameter(); + } + AbstractSpan span = ContextManager.createLocalSpan(operateName); + span.setComponent(ComponentsDefine.ELASTIC_JOB); + span.tag("sharding_context", shardingContext.toString()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java new file mode 100644 index 000000000000..555d2107d891 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.esjob.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link JobExecutorInstrumentation} presents that skywalking intercepts {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor}. + * + * @author gaohongtao + */ +public class JobExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor"; + + private static final String JOB_EXECUTOR_INTERCEPTOR_CLASS = "JobExecutorInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + + @Override public ElementMatcher getMethodsMatcher() { + return takesArgumentWithType(2, "com.dangdang.ddframe.job.event.type.JobExecutionEvent"); + } + + @Override public String getMethodsInterceptor() { + return JOB_EXECUTOR_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java deleted file mode 100644 index 33fcfed1d59d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.esjob; - -import com.dangdang.ddframe.job.api.ShardingContext; -import com.dangdang.ddframe.job.executor.ShardingContexts; -import com.google.common.base.Strings; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link JobExecutorInterceptor} enhances {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor#process(ShardingContext)} - * ,creating a local span that records job execution. - * - * @author gaohongtao - */ -public class JobExecutorInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ShardingContexts shardingContexts = (ShardingContexts)allArguments[0]; - Integer item = (Integer)allArguments[1]; - ShardingContext shardingContext = new ShardingContext(shardingContexts, item); - String operateName = shardingContext.getJobName(); - if (!Strings.isNullOrEmpty(shardingContext.getShardingParameter())) { - operateName += "-" + shardingContext.getShardingParameter(); - } - AbstractSpan span = ContextManager.createLocalSpan(operateName); - span.setComponent(ComponentsDefine.ELASTIC_JOB); - span.tag("sharding_context", shardingContext.toString()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java deleted file mode 100644 index 18b491f8a1f4..000000000000 --- a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.esjob.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JobExecutorInstrumentation} presents that skywalking intercepts {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor}. - * - * @author gaohongtao - */ -public class JobExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor"; - - private static final String JOB_EXECUTOR_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.esjob.JobExecutorInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{ - new InstanceMethodsInterceptPoint() { - - @Override public ElementMatcher getMethodsMatcher() { - return takesArgumentWithType(2, "com.dangdang.ddframe.job.event.type.JobExecutionEvent"); - } - - @Override public String getMethodsInterceptor() { - return JOB_EXECUTOR_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/resources/skywalking-plugin.def index 7e8a4d7078b6..81ca96a13405 100644 --- a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -elastic-job-2.x=org.skywalking.apm.plugin.esjob.define.JobExecutorInstrumentation \ No newline at end of file +elastic-job-2.x=JobExecutorInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java similarity index 77% rename from apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java index 3d5ac8c8b1f5..be4a977dac46 100644 --- a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java @@ -16,26 +16,44 @@ * */ -package org.skywalking.apm.plugin.esjob; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.esjob; import com.dangdang.ddframe.job.executor.ShardingContexts; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java new file mode 100644 index 000000000000..ac49ab076088 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.feign.http.v9; + +import feign.Request; +import feign.Response; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.URL; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * {@link DefaultHttpClientInterceptor} intercept the default implementation of http calls by the Feign. + * + * @author peng-yongsheng + */ +public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterceptor { + + private static final String COMPONENT_NAME = "FeignDefaultHttp"; + + /** + * Get the {@link feign.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host, + * port, kind, component, url from {@link feign.Request}. + * Through the reflection of the way, set the http header of context data into {@link feign.Request#headers}. + * + * @param method + * @param result change this result, if you want to truncate the method. + * @throws Throwable + */ + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + Request request = (Request)allArguments[0]; + + URL url = new URL(request.url()); + ContextCarrier contextCarrier = new ContextCarrier(); + String remotePeer = url.getHost() + ":" + url.getPort(); + AbstractSpan span = ContextManager.createExitSpan(request.url(), contextCarrier, remotePeer); + span.setComponent(ComponentsDefine.FEIGN); + Tags.HTTP.METHOD.set(span, request.method()); + Tags.URL.set(span, url.getPath()); + SpanLayer.asHttp(span); + + Field headersField = Request.class.getDeclaredField("headers"); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL); + + headersField.setAccessible(true); + Map> headers = new LinkedHashMap>(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + List contextCollection = new LinkedList(); + contextCollection.add(next.getHeadValue()); + headers.put(next.getHeadKey(), contextCollection); + } + headers.putAll(request.headers()); + + headersField.set(request, Collections.unmodifiableMap(headers)); + } + + /** + * Get the status code from {@link Response}, when status code greater than 400, it means there was some errors in + * the server. + * Finish the {@link AbstractSpan}. + * + * @param method + * @param ret the method's original return value. + * @return + * @throws Throwable + */ + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Response response = (Response)ret; + if (response != null) { + int statusCode = response.status(); + + AbstractSpan span = ContextManager.activeSpan(); + if (statusCode >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, statusCode + ""); + } + } + + ContextManager.stopSpan(); + + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.log(t); + activeSpan.errorOccurred(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java new file mode 100644 index 000000000000..d6eb03b9ba46 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.feign.http.v9.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link DefaultHttpClientInstrumentation} presents that skywalking intercepts {@link + * feign.Client.Default#execute(feign.Request, feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}. + * If feign did't run in default mode, the instrumentation depend on the http discovery implementation. + * e.g. okhttp discovery implementation depend on okhttp-plugin. + * + * @author peng-yongsheng + */ +public class DefaultHttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "feign.Client$Default"; + + /** + * Intercept class. + */ + private static final String INTERCEPT_CLASS = "DefaultHttpClientInterceptor"; + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java deleted file mode 100644 index 130d73c6eeb8..000000000000 --- a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.feign.http.v9; - -import feign.Request; -import feign.Response; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.URL; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link DefaultHttpClientInterceptor} intercept the default implementation of http calls by the Feign. - * - * @author peng-yongsheng - */ -public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterceptor { - - private static final String COMPONENT_NAME = "FeignDefaultHttp"; - - /** - * Get the {@link feign.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host, - * port, kind, component, url from {@link feign.Request}. - * Through the reflection of the way, set the http header of context data into {@link feign.Request#headers}. - * - * @param method - * @param result change this result, if you want to truncate the method. - * @throws Throwable - */ - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - Request request = (Request)allArguments[0]; - - URL url = new URL(request.url()); - ContextCarrier contextCarrier = new ContextCarrier(); - String remotePeer = url.getHost() + ":" + url.getPort(); - AbstractSpan span = ContextManager.createExitSpan(request.url(), contextCarrier, remotePeer); - span.setComponent(ComponentsDefine.FEIGN); - Tags.HTTP.METHOD.set(span, request.method()); - Tags.URL.set(span, url.getPath()); - SpanLayer.asHttp(span); - - Field headersField = Request.class.getDeclaredField("headers"); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL); - - headersField.setAccessible(true); - Map> headers = new LinkedHashMap>(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - List contextCollection = new LinkedList(); - contextCollection.add(next.getHeadValue()); - headers.put(next.getHeadKey(), contextCollection); - } - headers.putAll(request.headers()); - - headersField.set(request, Collections.unmodifiableMap(headers)); - } - - /** - * Get the status code from {@link Response}, when status code greater than 400, it means there was some errors in - * the server. - * Finish the {@link AbstractSpan}. - * - * @param method - * @param ret the method's original return value. - * @return - * @throws Throwable - */ - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Response response = (Response)ret; - if (response != null) { - int statusCode = response.status(); - - AbstractSpan span = ContextManager.activeSpan(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, statusCode + ""); - } - } - - ContextManager.stopSpan(); - - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.log(t); - activeSpan.errorOccurred(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java deleted file mode 100644 index 465db6a8fd60..000000000000 --- a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/define/DefaultHttpClientInstrumentation.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.feign.http.v9.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link DefaultHttpClientInstrumentation} presents that skywalking intercepts {@link - * feign.Client.Default#execute(feign.Request, feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}. - * If feign did't run in default mode, the instrumentation depend on the http discovery implementation. - * e.g. okhttp discovery implementation depend on okhttp-plugin. - * - * @author peng-yongsheng - */ -public class DefaultHttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - /** - * Enhance class. - */ - private static final String ENHANCE_CLASS = "feign.Client$Default"; - - /** - * Intercept class. - */ - private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor"; - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/resources/skywalking-plugin.def index 060bcdc6fabf..24c3b8bb67eb 100644 --- a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -feign-default-http-9.x=org.skywalking.apm.plugin.feign.http.v9.define.DefaultHttpClientInstrumentation \ No newline at end of file +feign-default-http-9.x=DefaultHttpClientInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java similarity index 78% rename from apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java index ed4d59be1504..f32794251cec 100644 --- a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.feign.http.v9; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.feign.http.v9; import feign.Request; import feign.Response; @@ -25,6 +43,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; @@ -35,19 +60,12 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static junit.framework.TestCase.assertNotNull; import static org.hamcrest.CoreMatchers.is; @@ -141,7 +159,7 @@ public void testMethodsAroundError() throws Throwable { } private void assertSpan(AbstractTracingSpan span) { - assertThat(SpanHelper.getLayer(span), is(SpanLayer.HTTP)); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.HTTP)); assertThat(SpanHelper.getComponentId(span), is(11)); } diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java new file mode 100644 index 000000000000..d3297d80546c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.MethodDescriptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link ClientCallIConstructorInterceptor} pass the {@link GRPCDynamicFields} into the + * io.grpc.internal.ClientCallImpl instance for propagate the information of build span. + * + * @author zhangxin + */ +public class ClientCallIConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + GRPCDynamicFields dynamicFields = new GRPCDynamicFields(); + dynamicFields.setDescriptor((MethodDescriptor)allArguments[0]); + objInst.setSkyWalkingDynamicField(dynamicFields); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java new file mode 100644 index 000000000000..327066f577d1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.define.Constants; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link ClientCallOnNextInterceptor} create a local span when the client stream receive an message that send from + * server stream and record the value of OnNext.count tag. + * + * @author zhangxin + */ +public class ClientCallOnNextInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + Constants.STREAM_OPERATION_NAME_SUFFIX); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + + // record the call count of onNext method + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + cachedObjects.incrementOnNextCount(); + + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java new file mode 100644 index 000000000000..1b02f7013f9c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.Metadata; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +public class ClientCallStartInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + final Metadata headers = (Metadata)allArguments[1]; + + final ContextCarrier contextCarrier = new ContextCarrier(); + ContextManager.inject(contextCarrier); + CarrierItem contextItem = contextCarrier.items(); + while (contextItem.hasNext()) { + contextItem = contextItem.next(); + Metadata.Key headerKey = Metadata.Key.of(contextItem.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER); + headers.put(headerKey, contextItem.getHeadValue()); + } + + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + GRPCDynamicFields listenerCachedObject = new GRPCDynamicFields(); + listenerCachedObject.setSnapshot(ContextManager.capture()); + listenerCachedObject.setDescriptor(cachedObjects.getDescriptor()); + ((EnhancedInstance)allArguments[0]).setSkyWalkingDynamicField(listenerCachedObject); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java new file mode 100644 index 000000000000..7e4faf4310d8 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link ClientCallOnNextInterceptor} create a exist span when the grpc start call. it will stop span when the method + * type is non-unary. + * + * @author zhangxin + */ +public class ClientCallsMethodInterceptor + implements StaticMethodsAroundInterceptor { + + @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + MethodInterceptResult result) { + EnhancedInstance clientCall = (EnhancedInstance)allArguments[0]; + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)clientCall.getSkyWalkingDynamicField(); + + final AbstractSpan span = ContextManager.createExitSpan(cachedObjects.getRequestMethodName(), cachedObjects.getAuthority()); + span.setComponent(ComponentsDefine.GRPC); + SpanLayer.asRPCFramework(span); + } + + @Override public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Object ret) { + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java new file mode 100644 index 000000000000..d9adffd09350 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.internal.ManagedChannelImpl; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link ManagedChannelInterceptor} record the IP address of the GRPC server into {@link GRPCDynamicFields} for build + * span. + * + * @author zhangxin + */ +public class ManagedChannelInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)((EnhancedInstance)ret).getSkyWalkingDynamicField(); + cachedObjects.setAuthority(((ManagedChannelImpl)((Object)objInst)).authority()); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java new file mode 100644 index 000000000000..c904cbdf870f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.Metadata; +import io.grpc.ServerCall; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * {@link ServerCallHandlerInterceptor} record the {@link Metadata} argument into {@link GRPCDynamicFields} for + * propagate {@link ContextCarrier} and also record the {@link + * io.grpc.MethodDescriptor} into {@link GRPCDynamicFields} for building span. + * + * @author zhangxin + */ +public class ServerCallHandlerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + GRPCDynamicFields cachedObjects = new GRPCDynamicFields(); + cachedObjects.setMetadata((Metadata)allArguments[1]); + cachedObjects.setDescriptor(((ServerCall)allArguments[0]).getMethodDescriptor()); + ((EnhancedInstance)ret).setSkyWalkingDynamicField(cachedObjects); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java new file mode 100644 index 000000000000..5da9d924fc99 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.grpc.v1.define.Constants; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link ServerCallOnCancelInterceptor} stop the active span when the call cancelled. + * + * @author zhangxin + */ +public class ServerCallOnCancelInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + AbstractSpan abstractSpan = ContextManager.activeSpan(); + abstractSpan.tag(Constants.ON_NEXT_COUNT_TAG_KEY, String.valueOf(((GRPCDynamicFields)objInst.getSkyWalkingDynamicField()).getOnNextCount())); + + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java new file mode 100644 index 000000000000..2ca6bf5f2b0c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +import static org.apache.skywalking.apm.plugin.grpc.v1.define.Constants.ON_NEXT_COUNT_TAG_KEY; + +/** + * {@link ServerCallOnCloseInterceptor} stop the active span when the call end. + * + * @author zhangxin + */ +public class ServerCallOnCloseInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + AbstractSpan abstractSpan = ContextManager.activeSpan(); + abstractSpan.tag(ON_NEXT_COUNT_TAG_KEY, String.valueOf(((GRPCDynamicFields)objInst.getSkyWalkingDynamicField()).getOnNextCount())); + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java new file mode 100644 index 000000000000..1d4596146b15 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +import static org.apache.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_OPERATION_NAME_SUFFIX; + +/** + * {@link ServerCallOnMessageInterceptor} create a local span when the server stream receive a message that send by the + * client. + * + * @author zhangxin + */ +public class ServerCallOnMessageInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + STREAM_OPERATION_NAME_SUFFIX); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + + // record the call count of onNext method + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + cachedObjects.incrementOnNextCount(); + + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java new file mode 100644 index 000000000000..d9a3c7f6e732 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.Metadata; +import io.grpc.MethodDescriptor; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; +import org.apache.skywalking.apm.util.StringUtil; + +import static org.apache.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_CALL_OPERATION_NAME_SUFFIX; +import static org.apache.skywalking.apm.plugin.grpc.v1.define.Constants.BLOCK_CALL_OPERATION_NAME_SUFFIX; + +/** + * {@link ServerCallOnReadyInterceptor} create a entry span when the server side is ready for receive the message from + * the client side. + * + * @author zhangxin + */ +public class ServerCallOnReadyInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + Metadata headers = cachedObjects.getMetadata(); + Map headerMap = new HashMap(); + for (String key : headers.keys()) { + if (!key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { + String value = headers.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); + headerMap.put(key, value); + } + } + + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + String contextValue = headerMap.get(next.getHeadKey()); + if (!StringUtil.isEmpty(contextValue)) { + next.setHeadValue(contextValue); + } + } + + final AbstractSpan span = ContextManager.createEntrySpan(cachedObjects.getRequestMethodName() + (cachedObjects.getMethodType() != MethodDescriptor.MethodType.UNARY ? STREAM_CALL_OPERATION_NAME_SUFFIX : BLOCK_CALL_OPERATION_NAME_SUFFIX), contextCarrier); + span.setComponent(ComponentsDefine.GRPC); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java new file mode 100644 index 000000000000..81d76c677a0f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.Metadata; +import io.grpc.Status; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.grpc.v1.define.Constants; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link StreamClientOnCloseInterceptor} stop the active span when the call end. + * + * @author zhangxin + */ +public class StreamClientOnCloseInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Status status = (Status)allArguments[0]; + if (status.getCode() == Status.Code.UNAVAILABLE) { + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + AbstractSpan span = ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + Constants.STREAM_CALL_OPERATION_NAME_SUFFIX); + span.setComponent(ComponentsDefine.GRPC); + span.setLayer(SpanLayer.RPC_FRAMEWORK); + ContextManager.continued(cachedObjects.getSnapshot()); + } + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.tag(Constants.ON_NEXT_COUNT_TAG_KEY, String.valueOf(((GRPCDynamicFields)objInst.getSkyWalkingDynamicField()).getOnNextCount())); + + Status status = (Status)allArguments[0]; + if (status != Status.OK) { + activeSpan.errorOccurred().log(status.asRuntimeException((Metadata)allArguments[1])); + Tags.STATUS_CODE.set(activeSpan, status.getCode().toString()); + } + + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java new file mode 100644 index 000000000000..e06722389473 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.grpc.v1.define.Constants; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +/** + * {@link ServerCallOnReadyInterceptor} create a local span when the client side is ready for send the message to the + * server side. + * + * @author zhangxin + */ +public class StreamClientOnReadyInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); + AbstractSpan span = ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + Constants.STREAM_CALL_OPERATION_NAME_SUFFIX); + span.setComponent(ComponentsDefine.GRPC); + span.setLayer(SpanLayer.RPC_FRAMEWORK); + + ContextManager.continued(cachedObjects.getSnapshot()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java new file mode 100644 index 000000000000..a0be044c8aaf --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +/** + * {@link UnaryStreamToFutureConstructorInterceptor} stop the active span when the call end. + * + * @author zhangxin + */ +public class UnaryStreamToFutureConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java new file mode 100644 index 000000000000..f6b628252d14 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ClientCallInstrumentation} presents that skywalking intercept the start method in + * io.grpc.internal.ClientCallImpl class by ClientCallsMethodInterceptor + * and the constructor in io.grpc.internal.ClientCallImpl by ClientCallIConstructorInterceptor + * + * @author zhangxin + */ +public class ClientCallInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.internal.ClientCallImpl"; + private static final String ENHANCE_METHOD = "start"; + public static final String CONSTRUCTOR_CLASS = "ClientCallIConstructorInterceptor"; + public static final String START_METHOD_INTERCEPT_CLASS = "ClientCallStartInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return START_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return true; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java new file mode 100644 index 000000000000..9e09681efded --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; + +public class ClientCallsInstrumentation extends ClassStaticMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ClientCalls"; + + @Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[] { + new StaticMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return (named("asyncUnaryRequestCall").and(takesArgumentWithType(2,"io.grpc.ClientCall$Listener"))) + .or(named("asyncStreamingRequestCall")) + .or(named("blockingUnaryCall")) + .or(named("futureUnaryCall")); + } + + @Override public String getMethodsInterceptor() { + return "ClientCallsMethodInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/Constants.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/Constants.java new file mode 100644 index 000000000000..a2136e0e6f69 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/Constants.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +/** + * GRPC Plugin constants variables. + * + * @author zhangxin + */ +public final class Constants { + + public static final String STREAM_OPERATION_NAME_SUFFIX = "/ResponseStreamObserver/OnNext"; + + public static final String ON_NEXT_COUNT_TAG_KEY = "onNext.count"; + + public static final String STREAM_CALL_OPERATION_NAME_SUFFIX = "/StreamCall"; + + public static final String BLOCK_CALL_OPERATION_NAME_SUFFIX = "/BlockCall"; + +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java new file mode 100644 index 000000000000..0798716dcb81 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link ManagedChannelInstrumentation} presents that skywalking intercept the newCall method in + * io.grpc.internal.ManagedChannelImpl class by ManagedChannelInterceptor + * + * @author zhangxin + */ +public class ManagedChannelInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.internal.ManagedChannelImpl"; + private static final String ENHANCE_METHOD = "newCall"; + public static final String INTERCEPT_CLASS = "ManagedChannelInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java new file mode 100644 index 000000000000..3c2d68260cc7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the onReady method + * by ServerCallOnReadyInterceptor, the onHalfClose method + * by ServerCallOnCloseInterceptor and the onMessage method + * by ServerCallOnMessageInterceptor in + * io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener class + * + * @author zhangxin + */ +public class StreamObserverToCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter"; + public static final String ON_READY_METHOD = "onReady"; + public static final String ON_READY_INTERCEPT_CLASS = "StreamClientOnReadyInterceptor"; + public static final String ON_CLASS_METHOD = "onClose"; + public static final String ON_CLOSE_INTERCEPT_CLASS = "StreamClientOnCloseInterceptor"; + public static final String ON_MESSAGE_METHOD = "onMessage"; + public static final String ON_MESSAGE_INTERCEPT_CLASS = "ClientCallOnNextInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_READY_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_READY_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_CLASS_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_CLOSE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_MESSAGE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_MESSAGE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java new file mode 100644 index 000000000000..df66e8a56002 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the startCall + * method in io.grpc.stub.ServerCalls$UnaryServerCallHandler class by + * ServerCallHandlerInterceptor + * + * @author zhangxin + */ +public class StreamingServerCallHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$UnaryServerCallHandler"; + private static final String ENHANCE_METHOD = "startCall"; + public static final String INTERCEPT_CLASS = "ServerCallHandlerInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java new file mode 100644 index 000000000000..3123e361a29a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the onReady method + * by ServerCallOnReadyInterceptor, the onHalfClose method + * by ServerCallOnCloseInterceptor, the onMessage method by + * ServerCallOnMessageInterceptor and the onCancel method by + * ServerCallOnCancelInterceptor in + * io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener class + * + * @author zhangxin + */ +public class StreamingServerCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener"; + public static final String ON_READY_METHOD = "onReady"; + public static final String ON_READ_INTERCEPT_CLASS = "ServerCallOnReadyInterceptor"; + public static final String ON_HALF_CLOSE_METHOD = "onHalfClose"; + public static final String ON_HALF_CLOSE_INTERCEPT_CLASS = "ServerCallOnCloseInterceptor"; + public static final String ON_MESSAGE_METHOD = "onMessage"; + public static final String ON_MESSAGE_INTERCEPT_CLASS = "ServerCallOnMessageInterceptor"; + public static final String ON_CANCEL_METHOD = "onCancel"; + public static final String ON_CANCEL_INTERCEPT_CLASS = "ServerCallOnCancelInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_READY_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_READ_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_HALF_CLOSE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_HALF_CLOSE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_MESSAGE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_MESSAGE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_CANCEL_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_CANCEL_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java new file mode 100644 index 000000000000..989e76a57ead --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; + +/** + * {@link UnaryClientCallListenerInstrumentation} indicates that skywalking enhance the onClose method in + * io.grpc.stub.ClientCalls$UnaryStreamToFuture class by UnaryStreamToFutureConstructorInterceptor + * + * @author zhangxin + */ +public class UnaryClientCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ClientCalls$UnaryStreamToFuture"; + public static final String INTERCEPT_CLASS = "UnaryStreamToFutureConstructorInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return INTERCEPT_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[0]; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java new file mode 100644 index 000000000000..05b88f917f00 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link UnaryServerCallHandlerInstrumentation} indicates that skywalking enhance the startCall in + * io.grpc.stub.ServerCalls$StreamingServerCallHandler class by ServerCallHandlerInterceptor. + * + * @author zhangxin + */ +public class UnaryServerCallHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$StreamingServerCallHandler"; + private static final String ENHANCE_METHOD = "startCall"; + public static final String INTERCEPT_CLASS = "ServerCallHandlerInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java new file mode 100644 index 000000000000..99d89d34a11c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the onReady method + * by ServerCallOnReadyInterceptor, the onHalfClose method + * by ServerCallOnCloseInterceptor, the onMessage method by + * ServerCallOnMessageInterceptor and the onCancel method by + * ServerCallOnCancelInterceptor in + * io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener class + * + * @author zhangxin + */ +public class UnaryServerCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener"; + public static final String ON_CLOSE_METHOD = "onHalfClose"; + public static final String ON_CLOSE_INTERCEPT_CLASS = "ServerCallOnCloseInterceptor"; + public static final String ON_READY_METHOD = "onReady"; + public static final String ON_READY_INTERCEPT_CLASS = "ServerCallOnReadyInterceptor"; + public static final String ON_CANCEL_METHOD = "onCancel"; + public static final String ON_CANCEL_INTERCEPT_CLASS = "ServerCallOnCancelInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_CLOSE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_CLOSE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_READY_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_READY_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_CANCEL_METHOD); + } + + @Override public String getMethodsInterceptor() { + return ON_CANCEL_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java new file mode 100644 index 000000000000..4ac90179e671 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.vo; + +import io.grpc.Metadata; +import io.grpc.MethodDescriptor; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; + +/** + * {@link GRPCDynamicFields} contain the require information of span. + * + * @author zhangxin + */ +public class GRPCDynamicFields { + private ServiceDescriptor descriptor; + private Metadata metadata; + private String authority; + private ContextSnapshot snapshot; + private int onNextCount; + + public Metadata getMetadata() { + return metadata; + } + + public void setMetadata(Metadata metadata) { + this.metadata = metadata; + } + + public String getAuthority() { + return authority; + } + + public void setAuthority(String authority) { + this.authority = authority; + } + + public String getRequestMethodName() { + return descriptor.getServiceName(); + } + + public void setDescriptor(MethodDescriptor methodDescriptor) { + this.descriptor = new ServiceDescriptor(methodDescriptor); + } + + public void setDescriptor(ServiceDescriptor methodDescriptor) { + this.descriptor = methodDescriptor; + } + + public ServiceDescriptor getDescriptor() { + return descriptor; + } + + public ContextSnapshot getSnapshot() { + return snapshot; + } + + public void setSnapshot(ContextSnapshot snapshot) { + this.snapshot = snapshot; + } + + public MethodDescriptor.MethodType getMethodType() { + return descriptor.getMethodType(); + } + + public void incrementOnNextCount() { + onNextCount++; + } + + public int getOnNextCount() { + return onNextCount; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java new file mode 100644 index 000000000000..f41807d6160e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1.vo; + +import io.grpc.MethodDescriptor; + +/** + * {@link ServiceDescriptor} indicate the descriptor of an grpc service. it contains {@link #methodType} and + * {@link #serviceName}. + * + * @author zhangxin + */ +public class ServiceDescriptor { + private MethodDescriptor.MethodType methodType; + private String serviceName; + + public ServiceDescriptor(MethodDescriptor descriptor) { + this.methodType = descriptor.getType(); + String fullMethodName = descriptor.getFullMethodName(); + this.serviceName = formatServiceName(fullMethodName) + "." + formatMethodName(fullMethodName); + } + + private String formatServiceName(String requestMethodName) { + int splitIndex = requestMethodName.lastIndexOf("/"); + return requestMethodName.substring(0, splitIndex); + } + + private String formatMethodName(String requestMethodName) { + int splitIndex = requestMethodName.lastIndexOf("/"); + String methodName = requestMethodName.substring(splitIndex + 1); + methodName = methodName.substring(0, 1).toLowerCase() + methodName.substring(1); + return methodName; + } + + public MethodDescriptor.MethodType getMethodType() { + return methodType; + } + + public String getServiceName() { + return serviceName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java deleted file mode 100644 index 573b3590cc41..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptor.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.MethodDescriptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -/** - * {@link ClientCallIConstructorInterceptor} pass the {@link GRPCDynamicFields} into the - * io.grpc.internal.ClientCallImpl instance for propagate the information of build span. - * - * @author zhangxin - */ -public class ClientCallIConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - GRPCDynamicFields dynamicFields = new GRPCDynamicFields(); - dynamicFields.setDescriptor((MethodDescriptor)allArguments[0]); - objInst.setSkyWalkingDynamicField(dynamicFields); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java deleted file mode 100644 index 6c3f2abe9abb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_OPERATION_NAME_SUFFIX; - -/** - * {@link ClientCallOnNextInterceptor} create a local span when the client stream receive an message that send from - * server stream and record the value of OnNext.count tag. - * - * @author zhangxin - */ -public class ClientCallOnNextInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + STREAM_OPERATION_NAME_SUFFIX); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - - // record the call count of onNext method - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - cachedObjects.incrementOnNextCount(); - - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java deleted file mode 100644 index 00f2f467ddb2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallStartInterceptor.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.Metadata; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -public class ClientCallStartInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - final Metadata headers = (Metadata)allArguments[1]; - - final ContextCarrier contextCarrier = new ContextCarrier(); - ContextManager.inject(contextCarrier); - CarrierItem contextItem = contextCarrier.items(); - while (contextItem.hasNext()) { - contextItem = contextItem.next(); - Metadata.Key headerKey = Metadata.Key.of(contextItem.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER); - headers.put(headerKey, contextItem.getHeadValue()); - } - - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - GRPCDynamicFields listenerCachedObject = new GRPCDynamicFields(); - listenerCachedObject.setSnapshot(ContextManager.capture()); - listenerCachedObject.setDescriptor(cachedObjects.getDescriptor()); - ((EnhancedInstance)allArguments[0]).setSkyWalkingDynamicField(listenerCachedObject); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java deleted file mode 100644 index 7c089ee862be..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -/** - * {@link ClientCallOnNextInterceptor} create a exist span when the grpc start call. it will stop span when the method - * type is non-unary. - * - * @author zhangxin - */ -public class ClientCallsMethodInterceptor - implements StaticMethodsAroundInterceptor { - - @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - MethodInterceptResult result) { - EnhancedInstance clientCall = (EnhancedInstance)allArguments[0]; - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)clientCall.getSkyWalkingDynamicField(); - - final AbstractSpan span = ContextManager.createExitSpan(cachedObjects.getRequestMethodName(), cachedObjects.getAuthority()); - span.setComponent(ComponentsDefine.GRPC); - SpanLayer.asRPCFramework(span); - } - - @Override public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Object ret) { - ContextManager.stopSpan(); - return ret; - } - - @Override - public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java deleted file mode 100644 index 9ac3351e4bd5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ManagedChannelInterceptor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.internal.ManagedChannelImpl; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -/** - * {@link ManagedChannelInterceptor} record the IP address of the GRPC server into {@link GRPCDynamicFields} for build - * span. - * - * @author zhangxin - */ -public class ManagedChannelInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)((EnhancedInstance)ret).getSkyWalkingDynamicField(); - cachedObjects.setAuthority(((ManagedChannelImpl)((Object)objInst)).authority()); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java deleted file mode 100644 index e73dc9263b37..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.Metadata; -import io.grpc.ServerCall; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -/** - * {@link ServerCallHandlerInterceptor} record the {@link Metadata} argument into {@link GRPCDynamicFields} for - * propagate {@link org.skywalking.apm.agent.core.context.ContextCarrier} and also record the {@link - * io.grpc.MethodDescriptor} into {@link GRPCDynamicFields} for building span. - * - * @author zhangxin - */ -public class ServerCallHandlerInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - GRPCDynamicFields cachedObjects = new GRPCDynamicFields(); - cachedObjects.setMetadata((Metadata)allArguments[1]); - cachedObjects.setDescriptor(((ServerCall)allArguments[0]).getMethodDescriptor()); - ((EnhancedInstance)ret).setSkyWalkingDynamicField(cachedObjects); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java deleted file mode 100644 index 9bee7b9a251a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCancelInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.ON_NEXT_COUNT_TAG_KEY; - -/** - * {@link ServerCallOnCancelInterceptor} stop the active span when the call cancelled. - * - * @author zhangxin - */ -public class ServerCallOnCancelInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - AbstractSpan abstractSpan = ContextManager.activeSpan(); - abstractSpan.tag(ON_NEXT_COUNT_TAG_KEY, String.valueOf(((GRPCDynamicFields)objInst.getSkyWalkingDynamicField()).getOnNextCount())); - - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java deleted file mode 100644 index 4b5d4000eae9..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnCloseInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.ON_NEXT_COUNT_TAG_KEY; - -/** - * {@link ServerCallOnCloseInterceptor} stop the active span when the call end. - * - * @author zhangxin - */ -public class ServerCallOnCloseInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - AbstractSpan abstractSpan = ContextManager.activeSpan(); - abstractSpan.tag(ON_NEXT_COUNT_TAG_KEY, String.valueOf(((GRPCDynamicFields)objInst.getSkyWalkingDynamicField()).getOnNextCount())); - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java deleted file mode 100644 index 13e43ecae85f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_OPERATION_NAME_SUFFIX; - -/** - * {@link ServerCallOnMessageInterceptor} create a local span when the server stream receive a message that send by the - * client. - * - * @author zhangxin - */ -public class ServerCallOnMessageInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + STREAM_OPERATION_NAME_SUFFIX); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - - // record the call count of onNext method - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - cachedObjects.incrementOnNextCount(); - - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java deleted file mode 100644 index be0fc6b71b0e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptor.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; -import org.skywalking.apm.util.StringUtil; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_CALL_OPERATION_NAME_SUFFIX; -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.BLOCK_CALL_OPERATION_NAME_SUFFIX; - -/** - * {@link ServerCallOnReadyInterceptor} create a entry span when the server side is ready for receive the message from - * the client side. - * - * @author zhangxin - */ -public class ServerCallOnReadyInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - Metadata headers = cachedObjects.getMetadata(); - Map headerMap = new HashMap(); - for (String key : headers.keys()) { - if (!key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - String value = headers.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); - headerMap.put(key, value); - } - } - - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - String contextValue = headerMap.get(next.getHeadKey()); - if (!StringUtil.isEmpty(contextValue)) { - next.setHeadValue(contextValue); - } - } - - final AbstractSpan span = ContextManager.createEntrySpan(cachedObjects.getRequestMethodName() + (cachedObjects.getMethodType() != MethodDescriptor.MethodType.UNARY ? STREAM_CALL_OPERATION_NAME_SUFFIX : BLOCK_CALL_OPERATION_NAME_SUFFIX), contextCarrier); - span.setComponent(ComponentsDefine.GRPC); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java deleted file mode 100644 index d53e25161a6e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnCloseInterceptor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.Metadata; -import io.grpc.Status; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.ON_NEXT_COUNT_TAG_KEY; -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_CALL_OPERATION_NAME_SUFFIX; - -/** - * {@link StreamClientOnCloseInterceptor} stop the active span when the call end. - * - * @author zhangxin - */ -public class StreamClientOnCloseInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Status status = (Status)allArguments[0]; - if (status.getCode() == Status.Code.UNAVAILABLE) { - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - AbstractSpan span = ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + STREAM_CALL_OPERATION_NAME_SUFFIX); - span.setComponent(ComponentsDefine.GRPC); - span.setLayer(SpanLayer.RPC_FRAMEWORK); - ContextManager.continued(cachedObjects.getSnapshot()); - } - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.tag(ON_NEXT_COUNT_TAG_KEY, String.valueOf(((GRPCDynamicFields)objInst.getSkyWalkingDynamicField()).getOnNextCount())); - - Status status = (Status)allArguments[0]; - if (status != Status.OK) { - activeSpan.errorOccurred().log(status.asRuntimeException((Metadata)allArguments[1])); - Tags.STATUS_CODE.set(activeSpan, status.getCode().toString()); - } - - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java deleted file mode 100644 index ec563b5563c7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/StreamClientOnReadyInterceptor.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.skywalking.apm.plugin.grpc.v1.define.Constants.STREAM_CALL_OPERATION_NAME_SUFFIX; - -/** - * {@link ServerCallOnReadyInterceptor} create a local span when the client side is ready for send the message to the - * server side. - * - * @author zhangxin - */ -public class StreamClientOnReadyInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - GRPCDynamicFields cachedObjects = (GRPCDynamicFields)objInst.getSkyWalkingDynamicField(); - AbstractSpan span = ContextManager.createLocalSpan(cachedObjects.getRequestMethodName() + STREAM_CALL_OPERATION_NAME_SUFFIX); - span.setComponent(ComponentsDefine.GRPC); - span.setLayer(SpanLayer.RPC_FRAMEWORK); - - ContextManager.continued(cachedObjects.getSnapshot()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java deleted file mode 100644 index 6b00d6d78fa5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/UnaryStreamToFutureConstructorInterceptor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * {@link UnaryStreamToFutureConstructorInterceptor} stop the active span when the call end. - * - * @author zhangxin - */ -public class UnaryStreamToFutureConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java deleted file mode 100644 index 227904c972b0..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallInstrumentation.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link ClientCallInstrumentation} presents that skywalking intercept the start method in - * io.grpc.internal.ClientCallImpl class by org.skywalking.apm.plugin.grpc.v1.ClientCallsMethodInterceptor - * and the constructor in io.grpc.internal.ClientCallImpl by org.skywalking.apm.plugin.grpc.v1.ClientCallIConstructorInterceptor - * - * @author zhangxin - */ -public class ClientCallInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.internal.ClientCallImpl"; - private static final String ENHANCE_METHOD = "start"; - public static final String CONSTRUCTOR_CLASS = "org.skywalking.apm.plugin.grpc.v1.ClientCallIConstructorInterceptor"; - public static final String START_METHOD_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ClientCallStartInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override public String getConstructorInterceptor() { - return CONSTRUCTOR_CLASS; - } - } - }; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return START_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return true; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java deleted file mode 100644 index 96abb089cc67..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ClientCallsInstrumentation.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -public class ClientCallsInstrumentation extends ClassStaticMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ClientCalls"; - - @Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return new StaticMethodsInterceptPoint[] { - new StaticMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return (named("asyncUnaryRequestCall").and(takesArgumentWithType(2,"io.grpc.ClientCall$Listener"))) - .or(named("asyncStreamingRequestCall")) - .or(named("blockingUnaryCall")) - .or(named("futureUnaryCall")); - } - - @Override public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.grpc.v1.ClientCallsMethodInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/Constants.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/Constants.java deleted file mode 100644 index 6723ee495a54..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/Constants.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -/** - * GRPC Plugin constants variables. - * - * @author zhangxin - */ -public final class Constants { - - public static final String STREAM_OPERATION_NAME_SUFFIX = "/ResponseStreamObserver/OnNext"; - - public static final String ON_NEXT_COUNT_TAG_KEY = "onNext.count"; - - public static final String STREAM_CALL_OPERATION_NAME_SUFFIX = "/StreamCall"; - - public static final String BLOCK_CALL_OPERATION_NAME_SUFFIX = "/BlockCall"; - -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java deleted file mode 100644 index ea6fa27e47e1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/ManagedChannelInstrumentation.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link ManagedChannelInstrumentation} presents that skywalking intercept the newCall method in - * io.grpc.internal.ManagedChannelImpl class by org.skywalking.apm.plugin.grpc.v1.ManagedChannelInterceptor - * - * @author zhangxin - */ -public class ManagedChannelInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.internal.ManagedChannelImpl"; - private static final String ENHANCE_METHOD = "newCall"; - public static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ManagedChannelInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java deleted file mode 100644 index d708edbbda71..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamObserverToCallListenerInstrumentation.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the onReady method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnReadyInterceptor, the onHalfClose method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnCloseInterceptor and the onMessage method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnMessageInterceptor in - * io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener class - * - * @author zhangxin - */ -public class StreamObserverToCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter"; - public static final String ON_READY_METHOD = "onReady"; - public static final String ON_READY_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.StreamClientOnReadyInterceptor"; - public static final String ON_CLASS_METHOD = "onClose"; - public static final String ON_CLOSE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.StreamClientOnCloseInterceptor"; - public static final String ON_MESSAGE_METHOD = "onMessage"; - public static final String ON_MESSAGE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ClientCallOnNextInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_READY_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_READY_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_CLASS_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_CLOSE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_MESSAGE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_MESSAGE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java deleted file mode 100644 index 53895f56722d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallHandlerInstrumentation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the startCall - * method in io.grpc.stub.ServerCalls$UnaryServerCallHandler class by - * org.skywalking.apm.plugin.grpc.v1.ServerCallHandlerInterceptor - * - * @author zhangxin - */ -public class StreamingServerCallHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$UnaryServerCallHandler"; - private static final String ENHANCE_METHOD = "startCall"; - public static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallHandlerInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java deleted file mode 100644 index 0863760a906a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/StreamingServerCallListenerInstrumentation.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the onReady method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnReadyInterceptor, the onHalfClose method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnCloseInterceptor, the onMessage method by - * org.skywalking.apm.plugin.grpc.v1.ServerCallOnMessageInterceptor and the onCancel method by - * org.skywalking.apm.plugin.grpc.v1.ServerCallOnCancelInterceptor in - * io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener class - * - * @author zhangxin - */ -public class StreamingServerCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener"; - public static final String ON_READY_METHOD = "onReady"; - public static final String ON_READ_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnReadyInterceptor"; - public static final String ON_HALF_CLOSE_METHOD = "onHalfClose"; - public static final String ON_HALF_CLOSE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnCloseInterceptor"; - public static final String ON_MESSAGE_METHOD = "onMessage"; - public static final String ON_MESSAGE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnMessageInterceptor"; - public static final String ON_CANCEL_METHOD = "onCancel"; - public static final String ON_CANCEL_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnCancelInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_READY_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_READ_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_HALF_CLOSE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_HALF_CLOSE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_MESSAGE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_MESSAGE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_CANCEL_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_CANCEL_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java deleted file mode 100644 index a36ed89de988..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryClientCallListenerInstrumentation.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link UnaryClientCallListenerInstrumentation} indicates that skywalking enhance the onClose method in - * io.grpc.stub.ClientCalls$UnaryStreamToFuture class by org.skywalking.apm.plugin.grpc.v1.UnaryStreamToFutureConstructorInterceptor - * - * @author zhangxin - */ -public class UnaryClientCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ClientCalls$UnaryStreamToFuture"; - public static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.UnaryStreamToFutureConstructorInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override public String getConstructorInterceptor() { - return INTERCEPT_CLASS; - } - } - }; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[0]; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java deleted file mode 100644 index f249f68ce05b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallHandlerInstrumentation.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link UnaryServerCallHandlerInstrumentation} indicates that skywalking enhance the startCall in - * io.grpc.stub.ServerCalls$StreamingServerCallHandler class by org.skywalking.apm.plugin.grpc.v1.ServerCallHandlerInterceptor. - * - * @author zhangxin - */ -public class UnaryServerCallHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$StreamingServerCallHandler"; - private static final String ENHANCE_METHOD = "startCall"; - public static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallHandlerInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java deleted file mode 100644 index 8276782c917d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/define/UnaryServerCallListenerInstrumentation.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link StreamingServerCallHandlerInstrumentation} presents that skywalking intercept the onReady method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnReadyInterceptor, the onHalfClose method - * by org.skywalking.apm.plugin.grpc.v1.ServerCallOnCloseInterceptor, the onMessage method by - * org.skywalking.apm.plugin.grpc.v1.ServerCallOnMessageInterceptor and the onCancel method by - * org.skywalking.apm.plugin.grpc.v1.ServerCallOnCancelInterceptor in - * io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener class - * - * @author zhangxin - */ -public class UnaryServerCallListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener"; - public static final String ON_CLOSE_METHOD = "onHalfClose"; - public static final String ON_CLOSE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnCloseInterceptor"; - public static final String ON_READY_METHOD = "onReady"; - public static final String ON_READY_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnReadyInterceptor"; - public static final String ON_CANCEL_METHOD = "onCancel"; - public static final String ON_CANCEL_INTERCEPT_CLASS = "org.skywalking.apm.plugin.grpc.v1.ServerCallOnCancelInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_CLOSE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_CLOSE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_READY_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_READY_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_CANCEL_METHOD); - } - - @Override public String getMethodsInterceptor() { - return ON_CANCEL_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java deleted file mode 100644 index a7adb3114fcf..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/GRPCDynamicFields.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.vo; - -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; -import org.skywalking.apm.agent.core.context.ContextSnapshot; - -/** - * {@link GRPCDynamicFields} contain the require information of span. - * - * @author zhangxin - */ -public class GRPCDynamicFields { - private ServiceDescriptor descriptor; - private Metadata metadata; - private String authority; - private ContextSnapshot snapshot; - private int onNextCount; - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - - public String getAuthority() { - return authority; - } - - public void setAuthority(String authority) { - this.authority = authority; - } - - public String getRequestMethodName() { - return descriptor.getServiceName(); - } - - public void setDescriptor(MethodDescriptor methodDescriptor) { - this.descriptor = new ServiceDescriptor(methodDescriptor); - } - - public void setDescriptor(ServiceDescriptor methodDescriptor) { - this.descriptor = methodDescriptor; - } - - public ServiceDescriptor getDescriptor() { - return descriptor; - } - - public ContextSnapshot getSnapshot() { - return snapshot; - } - - public void setSnapshot(ContextSnapshot snapshot) { - this.snapshot = snapshot; - } - - public MethodDescriptor.MethodType getMethodType() { - return descriptor.getMethodType(); - } - - public void incrementOnNextCount() { - onNextCount++; - } - - public int getOnNextCount() { - return onNextCount; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java deleted file mode 100644 index c60a84130024..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/skywalking/apm/plugin/grpc/v1/vo/ServiceDescriptor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1.vo; - -import io.grpc.MethodDescriptor; - -/** - * {@link ServiceDescriptor} indicate the descriptor of an grpc service. it contains {@link #methodType} and - * {@link #serviceName}. - * - * @author zhangxin - */ -public class ServiceDescriptor { - private MethodDescriptor.MethodType methodType; - private String serviceName; - - public ServiceDescriptor(MethodDescriptor descriptor) { - this.methodType = descriptor.getType(); - String fullMethodName = descriptor.getFullMethodName(); - this.serviceName = formatServiceName(fullMethodName) + "." + formatMethodName(fullMethodName); - } - - private String formatServiceName(String requestMethodName) { - int splitIndex = requestMethodName.lastIndexOf("/"); - return requestMethodName.substring(0, splitIndex); - } - - private String formatMethodName(String requestMethodName) { - int splitIndex = requestMethodName.lastIndexOf("/"); - String methodName = requestMethodName.substring(splitIndex + 1); - methodName = methodName.substring(0, 1).toLowerCase() + methodName.substring(1); - return methodName; - } - - public MethodDescriptor.MethodType getMethodType() { - return methodType; - } - - public String getServiceName() { - return serviceName; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/resources/skywalking-plugin.def index afe83e6e8634..d6c13c17e6bf 100644 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,9 +1,9 @@ -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.ClientCallInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.UnaryClientCallListenerInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.UnaryServerCallListenerInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.UnaryServerCallHandlerInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.ClientCallsInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.ManagedChannelInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.StreamingServerCallHandlerInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.StreamingServerCallListenerInstrumentation -grpc-1.x=org.skywalking.apm.plugin.grpc.v1.define.StreamObserverToCallListenerInstrumentation +grpc-1.x=ClientCallInstrumentation +grpc-1.x=UnaryClientCallListenerInstrumentation +grpc-1.x=UnaryServerCallListenerInstrumentation +grpc-1.x=UnaryServerCallHandlerInstrumentation +grpc-1.x=ClientCallsInstrumentation +grpc-1.x=ManagedChannelInstrumentation +grpc-1.x=StreamingServerCallHandlerInstrumentation +grpc-1.x=StreamingServerCallListenerInstrumentation +grpc-1.x=StreamObserverToCallListenerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java new file mode 100644 index 000000000000..7213ba370678 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.MethodDescriptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(MethodDescriptor.class) +public class ClientCallIConstructorInterceptorTest { + + private ClientCallIConstructorInterceptor constructorInterceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + private Object[] arguments; + + @Before + public void setUp() { + constructorInterceptor = new ClientCallIConstructorInterceptor(); + + MethodDescriptor methodDescriptor = mock(MethodDescriptor.class); + when(methodDescriptor.getType()).thenReturn(MethodDescriptor.MethodType.UNARY); + when(methodDescriptor.getFullMethodName()).thenReturn("test/testMethod"); + + arguments = new Object[] {methodDescriptor}; + } + + @Test + public void testOnConstructor() { + constructorInterceptor.onConstruct(enhancedInstance, arguments); + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java new file mode 100644 index 000000000000..f800f4de1223 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ClientCallOnNextInterceptorTest { + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Mock + private EnhancedInstance clientCall; + + @Mock + private GRPCDynamicFields cachedObjects; + + private ClientCallOnNextInterceptor callOnNextInterceptor; + + @Before + public void setUp() { + when(cachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); + when(clientCall.getSkyWalkingDynamicField()).thenReturn(cachedObjects); + + callOnNextInterceptor = new ClientCallOnNextInterceptor(); + } + + @Test + public void testCallOnNext() throws Throwable { + callOnNextInterceptor.beforeMethod(clientCall, null, null, null, null); + callOnNextInterceptor.afterMethod(clientCall, null, null, null, null); + + verify(cachedObjects, times(1)).incrementOnNextCount(); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); + AbstractTracingSpan span = SegmentHelper.getSpans(traceSegment).get(0); + assertThat(span.getOperationName(), is("org.skywalking.test.grpc.GreetService.sayHello/ResponseStreamObserver/OnNext")); + assertThat(span.isEntry(), is(false)); + assertThat(span.isExit(), is(false)); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java new file mode 100644 index 000000000000..c3bcfa35c916 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.MethodDescriptor; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ClientCallsMethodInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + private ClientCallsMethodInterceptor clientCallStartInterceptor; + + @Mock + private EnhancedInstance clientCallImpl; + + @Mock + private EnhancedInstance clientCallListener; + + @Mock + private GRPCDynamicFields unaryCachedObjects; + + @Mock + private GRPCDynamicFields streamCachedObjects; + + private Object[] arguments; + private Class[] argumentTypes; + + @Before + public void setUp() { + when(unaryCachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); + when(unaryCachedObjects.getAuthority()).thenReturn("localhost:500051"); + when(unaryCachedObjects.getMethodType()).thenReturn(MethodDescriptor.MethodType.UNARY); + + when(streamCachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); + when(streamCachedObjects.getAuthority()).thenReturn("localhost:500051"); + when(streamCachedObjects.getMethodType()).thenReturn(MethodDescriptor.MethodType.SERVER_STREAMING); + + arguments = new Object[] {clientCallImpl, clientCallListener}; + argumentTypes = new Class[] {clientCallImpl.getClass(), clientCallListener.getClass()}; + + clientCallStartInterceptor = new ClientCallsMethodInterceptor(); + } + + @Test + public void testNormalUnaryCallStart() throws Throwable { + when(clientCallImpl.getSkyWalkingDynamicField()).thenReturn(unaryCachedObjects); + + clientCallStartInterceptor.beforeMethod(null, null, arguments, argumentTypes, null); + clientCallStartInterceptor.afterMethod(null, null, arguments, argumentTypes, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); + AbstractTracingSpan abstractTracingSpan = SegmentHelper.getSpans(traceSegment).get(0); + SpanAssert.assertComponent(abstractTracingSpan, ComponentsDefine.GRPC); + SpanAssert.assertLayer(abstractTracingSpan, SpanLayer.RPC_FRAMEWORK); + SpanAssert.assertOccurException(abstractTracingSpan, false); + } + + @Test + public void testNormalStreamCallStart() throws Throwable { + when(clientCallImpl.getSkyWalkingDynamicField()).thenReturn(streamCachedObjects); + + clientCallStartInterceptor.beforeMethod(null, null, arguments, argumentTypes, null); + clientCallStartInterceptor.afterMethod(null, null, arguments, argumentTypes, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); + AbstractTracingSpan abstractTracingSpan = SegmentHelper.getSpans(traceSegment).get(0); + SpanAssert.assertComponent(abstractTracingSpan, ComponentsDefine.GRPC); + SpanAssert.assertLayer(abstractTracingSpan, SpanLayer.RPC_FRAMEWORK); + SpanAssert.assertOccurException(abstractTracingSpan, false); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java new file mode 100644 index 000000000000..bc1d6283c260 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import io.grpc.Metadata; +import io.grpc.MethodDescriptor; +import io.grpc.ServerCall; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(MethodDescriptor.class) +public class ServerCallHandlerInterceptorTest { + @Mock + private EnhancedInstance enhancedInstance; + + private ServerCallHandlerInterceptor callHandlerInterceptor; + + @Mock + private ServerCall serverCall; + @Mock + private MethodDescriptor methodDescriptor; + + private Metadata metadata; + + private Object[] arguments; + private Class[] argumentTypes; + + @Before + public void setUp() { + when(methodDescriptor.getFullMethodName()).thenReturn("org.skywalking.test.GreetService/SayHello"); + when(serverCall.getMethodDescriptor()).thenReturn(methodDescriptor); + + callHandlerInterceptor = new ServerCallHandlerInterceptor(); + metadata = new Metadata(); + arguments = new Object[] {serverCall, metadata}; + argumentTypes = new Class[] {serverCall.getClass(), metadata.getClass()}; + } + + @Test + public void testSetCachedObjects() throws Throwable { + callHandlerInterceptor.afterMethod(null, null, arguments, argumentTypes, enhancedInstance); + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java new file mode 100644 index 000000000000..737eb01a4f46 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ServerCallOnMessageInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Mock + private EnhancedInstance clientCall; + + @Mock + private GRPCDynamicFields cachedObjects; + + private ServerCallOnMessageInterceptor serverCallOnMessageInterceptor; + + @Before + public void setUp() { + when(cachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); + when(clientCall.getSkyWalkingDynamicField()).thenReturn(cachedObjects); + + serverCallOnMessageInterceptor = new ServerCallOnMessageInterceptor(); + } + + @Test + public void testCallOnNext() throws Throwable { + serverCallOnMessageInterceptor.beforeMethod(clientCall, null, null, null, null); + serverCallOnMessageInterceptor.afterMethod(clientCall, null, null, null, null); + + verify(cachedObjects, times(1)).incrementOnNextCount(); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); + AbstractTracingSpan span = SegmentHelper.getSpans(traceSegment).get(0); + assertThat(span.getOperationName(), is("org.skywalking.test.grpc.GreetService.sayHello/ResponseStreamObserver/OnNext")); + assertThat(span.isEntry(), is(false)); + assertThat(span.isExit(), is(false)); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java similarity index 79% rename from apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java index 001009066a4a..ccfc562ebe10 100644 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/grpc/v1/ServerCallOnReadyInterceptorTest.java @@ -16,10 +16,31 @@ * */ -package org.skywalking.apm.plugin.grpc.v1; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.grpc.v1; import io.grpc.Metadata; import io.grpc.MethodDescriptor; +import org.apache.skywalking.apm.agent.test.tools.SegmentRefAssert; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -27,17 +48,14 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentRefAssert; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java deleted file mode 100644 index 08d0ca7a35ce..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallIConstructorInterceptorTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.MethodDescriptor; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(MethodDescriptor.class) -public class ClientCallIConstructorInterceptorTest { - - private ClientCallIConstructorInterceptor constructorInterceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - private Object[] arguments; - - @Before - public void setUp() { - constructorInterceptor = new ClientCallIConstructorInterceptor(); - - MethodDescriptor methodDescriptor = mock(MethodDescriptor.class); - when(methodDescriptor.getType()).thenReturn(MethodDescriptor.MethodType.UNARY); - when(methodDescriptor.getFullMethodName()).thenReturn("test/testMethod"); - - arguments = new Object[] {methodDescriptor}; - } - - @Test - public void testOnConstructor() { - constructorInterceptor.onConstruct(enhancedInstance, arguments); - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java deleted file mode 100644 index 9e5729749f50..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallOnNextInterceptorTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ClientCallOnNextInterceptorTest { - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - @Mock - private EnhancedInstance clientCall; - - @Mock - private GRPCDynamicFields cachedObjects; - - private ClientCallOnNextInterceptor callOnNextInterceptor; - - @Before - public void setUp() { - when(cachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); - when(clientCall.getSkyWalkingDynamicField()).thenReturn(cachedObjects); - - callOnNextInterceptor = new ClientCallOnNextInterceptor(); - } - - @Test - public void testCallOnNext() throws Throwable { - callOnNextInterceptor.beforeMethod(clientCall, null, null, null, null); - callOnNextInterceptor.afterMethod(clientCall, null, null, null, null); - - verify(cachedObjects, times(1)).incrementOnNextCount(); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); - AbstractTracingSpan span = SegmentHelper.getSpans(traceSegment).get(0); - assertThat(span.getOperationName(), is("org.skywalking.test.grpc.GreetService.sayHello/ResponseStreamObserver/OnNext")); - assertThat(span.isEntry(), is(false)); - assertThat(span.isExit(), is(false)); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java deleted file mode 100644 index 37d33521d433..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ClientCallsMethodInterceptorTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.MethodDescriptor; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.SpanAssert; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ClientCallsMethodInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - private ClientCallsMethodInterceptor clientCallStartInterceptor; - - @Mock - private EnhancedInstance clientCallImpl; - - @Mock - private EnhancedInstance clientCallListener; - - @Mock - private GRPCDynamicFields unaryCachedObjects; - - @Mock - private GRPCDynamicFields streamCachedObjects; - - private Object[] arguments; - private Class[] argumentTypes; - - @Before - public void setUp() { - when(unaryCachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); - when(unaryCachedObjects.getAuthority()).thenReturn("localhost:500051"); - when(unaryCachedObjects.getMethodType()).thenReturn(MethodDescriptor.MethodType.UNARY); - - when(streamCachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); - when(streamCachedObjects.getAuthority()).thenReturn("localhost:500051"); - when(streamCachedObjects.getMethodType()).thenReturn(MethodDescriptor.MethodType.SERVER_STREAMING); - - arguments = new Object[] {clientCallImpl, clientCallListener}; - argumentTypes = new Class[] {clientCallImpl.getClass(), clientCallListener.getClass()}; - - clientCallStartInterceptor = new ClientCallsMethodInterceptor(); - } - - @Test - public void testNormalUnaryCallStart() throws Throwable { - when(clientCallImpl.getSkyWalkingDynamicField()).thenReturn(unaryCachedObjects); - - clientCallStartInterceptor.beforeMethod(null, null, arguments, argumentTypes, null); - clientCallStartInterceptor.afterMethod(null, null, arguments, argumentTypes, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); - AbstractTracingSpan abstractTracingSpan = SegmentHelper.getSpans(traceSegment).get(0); - SpanAssert.assertComponent(abstractTracingSpan, ComponentsDefine.GRPC); - SpanAssert.assertLayer(abstractTracingSpan, SpanLayer.RPC_FRAMEWORK); - SpanAssert.assertOccurException(abstractTracingSpan, false); - } - - @Test - public void testNormalStreamCallStart() throws Throwable { - when(clientCallImpl.getSkyWalkingDynamicField()).thenReturn(streamCachedObjects); - - clientCallStartInterceptor.beforeMethod(null, null, arguments, argumentTypes, null); - clientCallStartInterceptor.afterMethod(null, null, arguments, argumentTypes, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); - AbstractTracingSpan abstractTracingSpan = SegmentHelper.getSpans(traceSegment).get(0); - SpanAssert.assertComponent(abstractTracingSpan, ComponentsDefine.GRPC); - SpanAssert.assertLayer(abstractTracingSpan, SpanLayer.RPC_FRAMEWORK); - SpanAssert.assertOccurException(abstractTracingSpan, false); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java deleted file mode 100644 index a4eb0c9d4203..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallHandlerInterceptorTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; -import io.grpc.ServerCall; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(MethodDescriptor.class) -public class ServerCallHandlerInterceptorTest { - @Mock - private EnhancedInstance enhancedInstance; - - private ServerCallHandlerInterceptor callHandlerInterceptor; - - @Mock - private ServerCall serverCall; - @Mock - private MethodDescriptor methodDescriptor; - - private Metadata metadata; - - private Object[] arguments; - private Class[] argumentTypes; - - @Before - public void setUp() { - when(methodDescriptor.getFullMethodName()).thenReturn("org.skywalking.test.GreetService/SayHello"); - when(serverCall.getMethodDescriptor()).thenReturn(methodDescriptor); - - callHandlerInterceptor = new ServerCallHandlerInterceptor(); - metadata = new Metadata(); - arguments = new Object[] {serverCall, metadata}; - argumentTypes = new Class[] {serverCall.getClass(), metadata.getClass()}; - } - - @Test - public void testSetCachedObjects() throws Throwable { - callHandlerInterceptor.afterMethod(null, null, arguments, argumentTypes, enhancedInstance); - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java deleted file mode 100644 index b8cdbfe03910..000000000000 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/test/java/org/skywalking/apm/plugin/grpc/v1/ServerCallOnMessageInterceptorTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.grpc.v1; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.plugin.grpc.v1.vo.GRPCDynamicFields; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ServerCallOnMessageInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - @Mock - private EnhancedInstance clientCall; - - @Mock - private GRPCDynamicFields cachedObjects; - - private ServerCallOnMessageInterceptor serverCallOnMessageInterceptor; - - @Before - public void setUp() { - when(cachedObjects.getRequestMethodName()).thenReturn("org.skywalking.test.grpc.GreetService.sayHello"); - when(clientCall.getSkyWalkingDynamicField()).thenReturn(cachedObjects); - - serverCallOnMessageInterceptor = new ServerCallOnMessageInterceptor(); - } - - @Test - public void testCallOnNext() throws Throwable { - serverCallOnMessageInterceptor.beforeMethod(clientCall, null, null, null, null); - serverCallOnMessageInterceptor.afterMethod(clientCall, null, null, null, null); - - verify(cachedObjects, times(1)).incrementOnNextCount(); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1)); - AbstractTracingSpan span = SegmentHelper.getSpans(traceSegment).get(0); - assertThat(span.getOperationName(), is("org.skywalking.test.grpc.GreetService.sayHello/ResponseStreamObserver/OnNext")); - assertThat(span.isEntry(), is(false)); - assertThat(span.isExit(), is(false)); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java new file mode 100644 index 000000000000..3c8518d48084 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link JdbcXAConnectionConstructorInterceptor } store {@link ConnectionInfo} + * when the client new instance of {@link org.h2.jdbcx.JdbcXAConnection}. + * + * @author zhangxin + */ +public class JdbcXAConnectionConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + objInst.setSkyWalkingDynamicField(((EnhancedInstance)allArguments[2]).getSkyWalkingDynamicField()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java new file mode 100644 index 000000000000..c297d20acc76 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link PooledJdbcConnectionConstructorInterceptor } store {@link ConnectionInfo} + * when the client new instance of {@link org.h2.jdbcx.JdbcXAConnection$PooledJdbcConnection}. + * + * @author zhangxin + */ +public class PooledJdbcConnectionConstructorInterceptor implements InstanceConstructorInterceptor { + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + objInst.setSkyWalkingDynamicField(((EnhancedInstance)allArguments[0]).getSkyWalkingDynamicField()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java new file mode 100644 index 000000000000..53945a5b53ba --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.plugin.jdbc.define.Constants; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@link AbstractConnectionInstrumentation} define how to enhance the following methods that the class which extend + * {@link java.sql.Connection}.
+ * + * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor + * 3. Enhance prepareCall by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor + * 4. Enhance createStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor + * 5. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * + * @author zhangxin + */ +public abstract class AbstractConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(1)); + } + + @Override public String getMethodsInterceptor() { + return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3)); + } + + @Override public String getMethodsInterceptor() { + return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_CALL_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return Constants.PREPARE_CALL_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.CREATE_STATEMENT_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.COMMIT_METHOD_NAME).or(named(Constants.ROLLBACK_METHOD_NAME)).or(named(Constants.CLOSE_METHOD_NAME)).or(named(Constants.RELEASE_SAVE_POINT_METHOD_NAME)); + } + + @Override public String getMethodsInterceptor() { + return Constants.SERVICE_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java new file mode 100644 index 000000000000..5ac5a2fa208f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2.define; + +import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link DriverInstrumentation} presents that skywalking intercepts {@link org.h2.Driver}. + * + * @author zhangxin + */ +public class DriverInstrumentation extends AbstractDriverInstrumentation { + private static final String CLASS_OF_INTERCEPT_H2_DRIVER = "org.h2.Driver"; + + @Override + protected ClassMatch enhanceClass() { + return byName(CLASS_OF_INTERCEPT_H2_DRIVER); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java new file mode 100644 index 000000000000..a31221dba2cb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link JdbcConnectionInstrumentation} presents that skywalking intercepts {@link org.h2.jdbc.JdbcConnection}. + * + * @author zhangxin + */ +public class JdbcConnectionInstrumentation extends AbstractConnectionInstrumentation { + public static final String ENHANCE_CLASS = "org.h2.jdbc.JdbcConnection"; + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java new file mode 100644 index 000000000000..61a5f8581788 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link JdbcXAConnectionInstrumentation} presents that skywalking intercepts {@link org.h2.jdbcx.JdbcXAConnection}. + * + * @author zhangxin + */ +public class JdbcXAConnectionInstrumentation extends AbstractConnectionInstrumentation { + + public static final String ENHANCE_CLASS = "org.h2.jdbcx.JdbcXAConnection"; + public static final String CONSTRUCTOR_INTERCEPT_CLASS = "JdbcXAConnectionConstructorInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPT_CLASS; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java new file mode 100644 index 000000000000..67e371a05a34 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.h2.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; + +/** + * {@link PooledJdbcConnectionInstrumentation} presents that skywalking intercepts {@link + * org.h2.jdbcx.JdbcXAConnection}. + * + * @author zhangxin + */ +public class PooledJdbcConnectionInstrumentation extends AbstractConnectionInstrumentation { + + public static final String CONSTRUCTOR_INTERCEPT_CLASS = "PooledJdbcConnectionConstructorInterceptor"; + public static final String ENHANCE_CLASS = "org.h2.jdbcx.JdbcXAConnection$PooledJdbcConnection"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPT_CLASS; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java deleted file mode 100644 index cc7fff43d8ee..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/JdbcXAConnectionConstructorInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * {@link JdbcXAConnectionConstructorInterceptor } store {@link org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo} - * when the client new instance of {@link org.h2.jdbcx.JdbcXAConnection}. - * - * @author zhangxin - */ -public class JdbcXAConnectionConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - objInst.setSkyWalkingDynamicField(((EnhancedInstance)allArguments[2]).getSkyWalkingDynamicField()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java deleted file mode 100644 index c72266acbee1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/PooledJdbcConnectionConstructorInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * {@link PooledJdbcConnectionConstructorInterceptor } store {@link org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo} - * when the client new instance of {@link org.h2.jdbcx.JdbcXAConnection$PooledJdbcConnection}. - * - * @author zhangxin - */ -public class PooledJdbcConnectionConstructorInterceptor implements InstanceConstructorInterceptor { - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - objInst.setSkyWalkingDynamicField(((EnhancedInstance)allArguments[0]).getSkyWalkingDynamicField()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java deleted file mode 100644 index fb539aabcc13..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/AbstractConnectionInstrumentation.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; - -/** - * {@link AbstractConnectionInstrumentation} define how to enhance the following methods that the class which extend - * {@link java.sql.Connection}.
- * - * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 3. Enhance prepareCall by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 4. Enhance createStatement by org.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 5. Enhance commit, rollback, close, releaseSavepoint by org.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor - * - * @author zhangxin - */ -public abstract class AbstractConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(1)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_CALL_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_CALL_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_STATEMENT_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return CREATE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(COMMIT_METHOD_NAME).or(named(ROLLBACK_METHOD_NAME)).or(named(CLOSE_METHOD_NAME)).or(named(RELEASE_SAVE_POINT_METHOD_NAME)); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java deleted file mode 100644 index 06fdfa2f8615..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/DriverInstrumentation.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; - -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link DriverInstrumentation} presents that skywalking intercepts {@link org.h2.Driver}. - * - * @author zhangxin - */ -public class DriverInstrumentation extends AbstractDriverInstrumentation { - private static final String CLASS_OF_INTERCEPT_H2_DRIVER = "org.h2.Driver"; - - @Override - protected ClassMatch enhanceClass() { - return byName(CLASS_OF_INTERCEPT_H2_DRIVER); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java deleted file mode 100644 index 17ad563bd06f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcConnectionInstrumentation.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JdbcConnectionInstrumentation} presents that skywalking intercepts {@link org.h2.jdbc.JdbcConnection}. - * - * @author zhangxin - */ -public class JdbcConnectionInstrumentation extends AbstractConnectionInstrumentation { - public static final String ENHANCE_CLASS = "org.h2.jdbc.JdbcConnection"; - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java deleted file mode 100644 index 5f729afba902..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/JdbcXAConnectionInstrumentation.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JdbcXAConnectionInstrumentation} presents that skywalking intercepts {@link org.h2.jdbcx.JdbcXAConnection}. - * - * @author zhangxin - */ -public class JdbcXAConnectionInstrumentation extends AbstractConnectionInstrumentation { - - public static final String ENHANCE_CLASS = "org.h2.jdbcx.JdbcXAConnection"; - public static final String CONSTRUCTOR_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.h2.JdbcXAConnectionConstructorInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override public String getConstructorInterceptor() { - return CONSTRUCTOR_INTERCEPT_CLASS; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java deleted file mode 100644 index 28ad9c8efdbb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/h2/define/PooledJdbcConnectionInstrumentation.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.h2.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link PooledJdbcConnectionInstrumentation} presents that skywalking intercepts {@link - * org.h2.jdbcx.JdbcXAConnection}. - * - * @author zhangxin - */ -public class PooledJdbcConnectionInstrumentation extends AbstractConnectionInstrumentation { - - public static final String CONSTRUCTOR_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.h2.PooledJdbcConnectionConstructorInterceptor"; - public static final String ENHANCE_CLASS = "org.h2.jdbcx.JdbcXAConnection$PooledJdbcConnection"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override public String getConstructorInterceptor() { - return CONSTRUCTOR_INTERCEPT_CLASS; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/resources/skywalking-plugin.def index 7af7b99364b8..a16c4b3d230c 100644 --- a/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/h2-1.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -h2-1.x=org.skywalking.apm.plugin.jdbc.h2.define.DriverInstrumentation -h2-1.x=org.skywalking.apm.plugin.jdbc.h2.define.JdbcConnectionInstrumentation -h2-1.x=org.skywalking.apm.plugin.jdbc.h2.define.PooledJdbcConnectionInstrumentation -h2-1.x=org.skywalking.apm.plugin.jdbc.h2.define.JdbcXAConnectionInstrumentation +h2-1.x=DriverInstrumentation +h2-1.x=JdbcConnectionInstrumentation +h2-1.x=PooledJdbcConnectionInstrumentation +h2-1.x=JdbcXAConnectionInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java new file mode 100644 index 000000000000..771a02bd1771 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4; + +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + if (allArguments[0] == null || allArguments[1] == null) { + // illegal args, can't trace. ignore. + return; + } + final HttpHost httpHost = (HttpHost)allArguments[0]; + HttpRequest httpRequest = (HttpRequest)allArguments[1]; + final ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = null; + String remotePeer = httpHost.getHostName() + ":" + httpHost.getPort(); + try { + URL url = new URL(httpRequest.getRequestLine().getUri()); + span = ContextManager.createExitSpan(url.getPath(), contextCarrier, remotePeer); + } catch (MalformedURLException e) { + throw e; + } + + span.setComponent(ComponentsDefine.HTTPCLIENT); + Tags.URL.set(span, httpRequest.getRequestLine().getUri()); + Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod()); + SpanLayer.asHttp(span); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + httpRequest.setHeader(next.getHeadKey(), next.getHeadValue()); + } + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + if (allArguments[0] == null || allArguments[1] == null) { + return ret; + } + + HttpResponse response = (HttpResponse)ret; + int statusCode = response.getStatusLine().getStatusCode(); + AbstractSpan span = ContextManager.activeSpan(); + if (statusCode >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); + } + + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + activeSpan.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java new file mode 100644 index 000000000000..3447af519e65 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.protocol.HttpContext; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts + * {@link org.apache.http.impl.client.AbstractHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class AbstractHttpClientInstrumentation extends HttpClientInstrumentation { + + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.AbstractHttpClient"; + + @Override + public ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + /** + * version 4.2, intercept method: execute, intercept
+ * public final HttpResponse execute(HttpHost target, HttpRequest request, + * HttpContext context)
+ */ + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java new file mode 100644 index 000000000000..aa23c2134a82 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class DefaultRequestDirectorInstrumentation extends HttpClientInstrumentation { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.DefaultRequestDirector"; + + /** + * DefaultRequestDirector is default implement.
+ * usually use in version 4.0-4.2
+ * since 4.3, this class is Deprecated. + */ + @Override + public ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java new file mode 100644 index 000000000000..fefae06589a9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.plugin.httpClient.v4.HttpClientExecuteInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +/** + * {@link HttpClientInstrumentation} present that skywalking intercepts {@link HttpClientInstrumentation#enhanceClass()} + * by using {@link HttpClientExecuteInterceptor} + * + * @author zhangxin + */ +public abstract class HttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String INTERCEPT_CLASS = "HttpClientExecuteInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + protected String getInstanceMethodsInterceptor() { + return INTERCEPT_CLASS; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java new file mode 100644 index 000000000000..c034030ba46a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts {@link + * org.apache.http.impl.client.InternalHttpClient#doExecute(org.apache.http.HttpHost, org.apache.http.HttpRequest, + * org.apache.http.protocol.HttpContext)} by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class InternalHttpClientInstrumentation extends HttpClientInstrumentation { + + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.InternalHttpClient"; + + @Override + public ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java new file mode 100644 index 000000000000..ff6b52912e0e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.protocol.HttpContext; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking + * intercepts {@link org.apache.http.impl.client.MinimalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class MinimalHttpClientInstrumentation extends HttpClientInstrumentation { + + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.MinimalHttpClient"; + + @Override + public ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java deleted file mode 100644 index 802d42a19316..000000000000 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.httpClient.v4; - -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - if (allArguments[0] == null || allArguments[1] == null) { - // illegal args, can't trace. ignore. - return; - } - final HttpHost httpHost = (HttpHost)allArguments[0]; - HttpRequest httpRequest = (HttpRequest)allArguments[1]; - final ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan span = null; - String remotePeer = httpHost.getHostName() + ":" + httpHost.getPort(); - try { - URL url = new URL(httpRequest.getRequestLine().getUri()); - span = ContextManager.createExitSpan(url.getPath(), contextCarrier, remotePeer); - } catch (MalformedURLException e) { - throw e; - } - - span.setComponent(ComponentsDefine.HTTPCLIENT); - Tags.URL.set(span, httpRequest.getRequestLine().getUri()); - Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod()); - SpanLayer.asHttp(span); - - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - httpRequest.setHeader(next.getHeadKey(), next.getHeadValue()); - } - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - if (allArguments[0] == null || allArguments[1] == null) { - return ret; - } - - HttpResponse response = (HttpResponse)ret; - int statusCode = response.getStatusLine().getStatusCode(); - AbstractSpan span = ContextManager.activeSpan(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); - } - - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.errorOccurred(); - activeSpan.log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java deleted file mode 100644 index 4d6293cac01e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.httpClient.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.protocol.HttpContext; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts - * {@link org.apache.http.impl.client.AbstractHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} - * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. - * - * @author zhangxin - */ -public class AbstractHttpClientInstrumentation extends HttpClientInstrumentation { - - private static final String ENHANCE_CLASS = "org.apache.http.impl.client.AbstractHttpClient"; - - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - /** - * version 4.2, intercept method: execute, intercept
- * public final HttpResponse execute(HttpHost target, HttpRequest request, - * HttpContext context)
- */ - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java deleted file mode 100644 index 3f5607c1e8d9..000000000000 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.httpClient.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -public class DefaultRequestDirectorInstrumentation extends HttpClientInstrumentation { - - /** - * Enhance class. - */ - private static final String ENHANCE_CLASS = "org.apache.http.impl.client.DefaultRequestDirector"; - - /** - * DefaultRequestDirector is default implement.
- * usually use in version 4.0-4.2
- * since 4.3, this class is Deprecated. - */ - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java deleted file mode 100644 index ae721aa840a2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/HttpClientInstrumentation.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.httpClient.v4.define; - -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.plugin.httpClient.v4.HttpClientExecuteInterceptor; - -/** - * {@link HttpClientInstrumentation} present that skywalking intercepts {@link HttpClientInstrumentation#enhanceClass()} - * by using {@link HttpClientExecuteInterceptor} - * - * @author zhangxin - */ -public abstract class HttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.httpClient.v4.HttpClientExecuteInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - protected String getInstanceMethodsInterceptor() { - return INTERCEPT_CLASS; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java deleted file mode 100644 index 8005fa8b0b94..000000000000 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.httpClient.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts {@link - * org.apache.http.impl.client.InternalHttpClient#doExecute(org.apache.http.HttpHost, org.apache.http.HttpRequest, - * org.apache.http.protocol.HttpContext)} by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. - * - * @author zhangxin - */ -public class InternalHttpClientInstrumentation extends HttpClientInstrumentation { - - private static final String ENHANCE_CLASS = "org.apache.http.impl.client.InternalHttpClient"; - - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java deleted file mode 100644 index b5e235499e33..000000000000 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.httpClient.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.protocol.HttpContext; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link AbstractHttpClientInstrumentation} presents that skywalking - * intercepts {@link org.apache.http.impl.client.MinimalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} - * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. - * - * @author zhangxin - */ -public class MinimalHttpClientInstrumentation extends HttpClientInstrumentation { - - private static final String ENHANCE_CLASS = "org.apache.http.impl.client.MinimalHttpClient"; - - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def index bea7bc146794..89e32defb09d 100644 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -httpclient-4.x=org.skywalking.apm.plugin.httpClient.v4.define.AbstractHttpClientInstrumentation -httpclient-4.x=org.skywalking.apm.plugin.httpClient.v4.define.InternalHttpClientInstrumentation -httpclient-4.x=org.skywalking.apm.plugin.httpClient.v4.define.MinimalHttpClientInstrumentation -httpclient-4.x=org.skywalking.apm.plugin.httpClient.v4.define.DefaultRequestDirectorInstrumentation \ No newline at end of file +httpclient-4.x=AbstractHttpClientInstrumentation +httpclient-4.x=InternalHttpClientInstrumentation +httpclient-4.x=MinimalHttpClientInstrumentation +httpclient-4.x=DefaultRequestDirectorInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java similarity index 80% rename from apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java index 60cf84e42ff3..d2fc403ab377 100644 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.httpClient.v4; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.httpClient.v4; import java.util.List; import org.apache.http.HttpHost; @@ -25,6 +43,7 @@ import org.apache.http.ProtocolVersion; import org.apache.http.RequestLine; import org.apache.http.StatusLine; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; @@ -36,18 +55,17 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static junit.framework.TestCase.assertNotNull; import static org.hamcrest.CoreMatchers.is; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java new file mode 100644 index 000000000000..1359f77576ca --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link ConnectionServiceMethodInterceptor} create an exit span when the following methods execute: + * 1. close + * 2. rollback + * 3. releaseSavepoint + * 4. commit + * + * @author zhangxin + */ +public class ConnectionServiceMethodInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ConnectionInfo connectInfo = (ConnectionInfo)objInst.getSkyWalkingDynamicField(); + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, ""); + span.setComponent(connectInfo.getComponent()); + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java new file mode 100644 index 000000000000..e64a8a3ffd31 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.lang.reflect.Method; +import java.sql.Connection; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * {@link JDBCDriverInterceptor} set ConnectionInfo to {@link Connection} object when {@link + * java.sql.Driver} to create connection, instead of the {@link Connection} instance. + * + * @author zhangxin + */ +public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + if (ret != null) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(URLParser.parser((String)allArguments[0])); + } + + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java new file mode 100644 index 000000000000..33e709a4e59e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.lang.reflect.Method; +import java.sql.CallableStatement; +import java.sql.Connection; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWCallableStatement; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link JDBCPrepareCallInterceptor} return {@link SWCallableStatement} instance that wrapper the real CallStatement + * instance when the client call prepareCall method. + * + * @author zhangxin + */ +public class JDBCPrepareCallInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (objInst.getSkyWalkingDynamicField() == null) { + return ret; + } + return new SWCallableStatement((Connection)objInst, (CallableStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java new file mode 100644 index 000000000000..c9ed6f318ef3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.lang.reflect.Method; +import java.sql.Connection; +import java.sql.PreparedStatement; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link JDBCPrepareStatementInterceptor} return {@link SWPreparedStatement} instance that wrapper the real + * PreparedStatement instance when the client call prepareStatement method. + * + * @author zhangxin + */ +public class JDBCPrepareStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (objInst.getSkyWalkingDynamicField() == null) { + return ret; + } + return new SWPreparedStatement((Connection)objInst, (PreparedStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java new file mode 100644 index 000000000000..173ec9e97970 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.lang.reflect.Method; +import java.sql.Connection; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWStatement; + +/** + * {@link JDBCStatementInterceptor} return {@link SWStatement} instance that wrapper the real Statement instance when + * the client call createStatement method. + * + * @author zhangxin + */ +public class JDBCStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (objInst.getSkyWalkingDynamicField() == null) { + return ret; + } + return new SWStatement((Connection)objInst, (java.sql.Statement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField()); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java new file mode 100644 index 000000000000..d609f52c4cf0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; + +public abstract class AbstractURLParser implements ConnectionURLParser { + + protected String url; + + public AbstractURLParser(String url) { + this.url = url; + } + + /** + * Fetch the index range that database host and port from connection url. + * + * @return index range that database hosts. + */ + protected abstract URLLocation fetchDatabaseHostsIndexRange(); + + /** + * Fetch the index range that database name from connection url. + * + * @return index range that database name. + */ + protected abstract URLLocation fetchDatabaseNameIndexRange(); + + /** + * Fetch database host(s) from connection url. + * + * @return database host(s). + */ + protected String fetchDatabaseHostsFromURL() { + URLLocation hostsLocation = fetchDatabaseHostsIndexRange(); + return url.substring(hostsLocation.startIndex(), hostsLocation.endIndex()); + } + + /** + * Fetch database name from connection url. + * + * @return database name. + */ + protected String fetchDatabaseNameFromURL() { + URLLocation hostsLocation = fetchDatabaseNameIndexRange(); + return url.substring(hostsLocation.startIndex(), hostsLocation.endIndex()); + } + + /** + * Fetch database name from connection url. + * + * @return database name. + */ + protected String fetchDatabaseNameFromURL(int[] indexRange) { + return url.substring(indexRange[0], indexRange[1]); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java new file mode 100644 index 000000000000..0e137d59927c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; + +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public interface ConnectionURLParser { + /** + * {@link ConnectionURLParser} parses database name and the database host(s) from connection url. + * + * @return connection info. + */ + ConnectionInfo parse(); +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java similarity index 83% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java index f5dd3abeec03..ea978567d693 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java @@ -16,10 +16,28 @@ * */ -package org.skywalking.apm.plugin.jdbc.connectionurl.parser; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; /** * {@link H2URLParser} presents that skywalking how to parse the connection url of H2 database. diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java similarity index 76% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java index cd3eef52f678..9802f70a8bef 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java @@ -16,10 +16,28 @@ * */ -package org.skywalking.apm.plugin.jdbc.connectionurl.parser; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; /** * {@link MysqlURLParser} parse connection url of mysql. diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java similarity index 83% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java index 265354b7fed7..489ccfa7c950 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java @@ -16,13 +16,31 @@ * */ -package org.skywalking.apm.plugin.jdbc.connectionurl.parser; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; import java.util.ArrayList; import java.util.List; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.util.StringUtil; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.util.StringUtil; /** * {@link OracleURLParser} presents that how to parse oracle connection url. diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java similarity index 76% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java index da7a861ea527..a1f33a0572b9 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java @@ -16,10 +16,28 @@ * */ -package org.skywalking.apm.plugin.jdbc.connectionurl.parser; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; /** * {@link PostgreSQLURLParser} parse connection url of mysql. diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java new file mode 100644 index 000000000000..c7590d399775 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; + +public class URLLocation { + private final int startIndex; + private final int endIndex; + + public URLLocation(int startIndex, int endIndex) { + this.startIndex = startIndex; + this.endIndex = endIndex; + } + + public int startIndex() { + return startIndex; + } + + public int endIndex() { + return endIndex; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java new file mode 100644 index 000000000000..fa5834f4e756 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; + +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database. But there are + * some url cannot be parsed, such as Oracle connection url with multiple host. + * + * @author zhangxin + */ +public class URLParser { + + private static final String MYSQL_JDBC_URL_PREFIX = "jdbc:mysql"; + private static final String ORACLE_JDBC_URL_PREFIX = "jdbc:oracle"; + private static final String H2_JDBC_URL_PREFIX = "jdbc:h2"; + private static final String POSTGRESQL_JDBC_URL_PREFIX = "jdbc:postgresql"; + + public static ConnectionInfo parser(String url) { + ConnectionURLParser parser = null; + if (url.startsWith(MYSQL_JDBC_URL_PREFIX)) { + parser = new MysqlURLParser(url); + } else if (url.startsWith(ORACLE_JDBC_URL_PREFIX)) { + parser = new OracleURLParser(url); + } else if (url.startsWith(H2_JDBC_URL_PREFIX)) { + parser = new H2URLParser(url); + } else if (url.startsWith(POSTGRESQL_JDBC_URL_PREFIX)) { + parser = new PostgreSQLURLParser(url); + } + return parser.parse(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java new file mode 100644 index 000000000000..88884eb91c7f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * JDBC plugin using {@link JDBCDriverInterceptor} to intercept the connect method of all driver class. + * + * @author zhangxin + */ +public abstract class AbstractDriverInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String DRIVER_INTERCEPT_CLASS = "JDBCDriverInterceptor"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("connect"); + } + + @Override + public String getMethodsInterceptor() { + return DRIVER_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java new file mode 100644 index 000000000000..4f78615b2a9b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.define; + +public class Constants { + public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "JDBCStatementInterceptor"; + + public static final String PREPARE_STATEMENT_INTERCEPT_CLASS = "JDBCPrepareStatementInterceptor"; + + public static final String PREPARE_CALL_INTERCEPT_CLASS = "JDBCPrepareCallInterceptor"; + + public static final String SERVICE_METHOD_INTERCEPT_CLASS = "ConnectionServiceMethodInterceptor"; + + public static final String PREPARE_STATEMENT_METHOD_NAME = "prepareStatement"; + + public static final String PREPARE_CALL_METHOD_NAME = "prepareCall"; + + public static final String CREATE_STATEMENT_METHOD_NAME = "createStatement"; + + public static final String COMMIT_METHOD_NAME = "commit"; + + public static final String ROLLBACK_METHOD_NAME = "rollback"; + + public static final String CLOSE_METHOD_NAME = "close"; + + public static final String RELEASE_SAVE_POINT_METHOD_NAME = "releaseSavepoint"; + +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java new file mode 100644 index 000000000000..d05647b0139e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.define; + +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and + * sql for trace mysql. + * + * @author zhangxin + */ +public class StatementEnhanceInfos { + private ConnectionInfo connectionInfo; + private String statementName; + private String sql; + + public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) { + this.connectionInfo = connectionInfo; + this.sql = sql; + this.statementName = statementName; + } + + public ConnectionInfo getConnectionInfo() { + return connectionInfo; + } + + public String getSql() { + return sql; + } + + public String getStatementName() { + return statementName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java new file mode 100644 index 000000000000..c6112e60b85a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; + +import java.sql.SQLException; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.ContextManager; + +/** + * {@link CallableStatementTracing} create an exit span when the client call the method in the class that extend {@link + * java.sql.CallableStatement}. + * + * @author zhangxin + */ +public class CallableStatementTracing { + + public static R execute(java.sql.CallableStatement realStatement, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + SpanLayer.asDB(span); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + span.setComponent(connectInfo.getComponent()); + return exec.exe(realStatement, sql); + } catch (SQLException e) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(e); + throw e; + } finally { + ContextManager.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.CallableStatement realConnection, String sql) + throws SQLException; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java new file mode 100644 index 000000000000..7b4c74d063b1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; + +import org.apache.skywalking.apm.network.trace.component.OfficialComponent; + +/** + * {@link ConnectionInfo} stored the jdbc connection info, the connection info contains db type, host, port, database + * name. The {@link #hosts} be null if {@link #host} is not null. + * + * @author zhangxin + */ +public class ConnectionInfo { + /** + * DB type, such as mysql, oracle, h2. + */ + private final String dbType; + /** + * Operation database name. + */ + private final String databaseName; + + private String databasePeer; + + /** + * Component + */ + private final OfficialComponent component; + + public ConnectionInfo(OfficialComponent component, String dbType, String host, int port, String databaseName) { + this.dbType = dbType; + this.databasePeer = host + ":" + port; + this.databaseName = databaseName; + this.component = component; + } + + public ConnectionInfo(OfficialComponent component, String dbType, String hosts, String databaseName) { + this.dbType = dbType; + this.databasePeer = hosts; + this.databaseName = databaseName; + this.component = component; + } + + public String getDBType() { + return dbType; + } + + public String getDatabaseName() { + return databaseName; + } + + public String getDatabasePeer() { + return databasePeer; + } + + public OfficialComponent getComponent() { + return component; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java new file mode 100644 index 000000000000..4da635ec268a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; + +import java.sql.SQLException; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.ContextManager; + +/** + * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link + * java.sql.PreparedStatement}. + * + * @author zhangxin + */ +public class PreparedStatementTracing { + + public static R execute(java.sql.PreparedStatement realStatement, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + return exec.exe(realStatement, sql); + } catch (SQLException e) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(e); + throw e; + } finally { + ContextManager.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.PreparedStatement realConnection, String sql) + throws SQLException; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java index 63b442aa9580..0f3419b7c43b 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWCallableStatement.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc.trace; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; import java.io.InputStream; import java.io.Reader; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java similarity index 95% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java index fdbdc7e1e74e..113ff6934780 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWPreparedStatement.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc.trace; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; import java.io.InputStream; import java.io.Reader; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWStatement.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWStatement.java similarity index 92% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWStatement.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWStatement.java index eb8c087a2305..937bc1a9e1f6 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/SWStatement.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/SWStatement.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc.trace; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; import java.sql.Connection; import java.sql.ResultSet; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/StatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/StatementTracing.java new file mode 100644 index 000000000000..7a81d029165c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/trace/StatementTracing.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.trace; + +import java.sql.SQLException; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; + +/** + * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link + * java.sql.Statement}. + * + * @author zhangxin + */ +public class StatementTracing { + public static R execute(java.sql.Statement realStatement, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + span.setComponent(connectInfo.getComponent()); + SpanLayer.asDB(span); + return exec.exe(realStatement, sql); + } catch (SQLException e) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(e); + throw e; + } finally { + ContextManager.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.Statement realStatement, String sql) + throws SQLException; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java deleted file mode 100644 index 268710705131..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link ConnectionServiceMethodInterceptor} create an exit span when the following methods execute: - * 1. close - * 2. rollback - * 3. releaseSavepoint - * 4. commit - * - * @author zhangxin - */ -public class ConnectionServiceMethodInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ConnectionInfo connectInfo = (ConnectionInfo)objInst.getSkyWalkingDynamicField(); - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, ""); - span.setComponent(connectInfo.getComponent()); - SpanLayer.asDB(span); - } - - @Override - public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java deleted file mode 100644 index b5c3357464f5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.lang.reflect.Method; -import java.sql.Connection; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; - -/** - * {@link JDBCDriverInterceptor} set ConnectionInfo to {@link Connection} object when {@link - * java.sql.Driver} to create connection, instead of the {@link Connection} instance. - * - * @author zhangxin - */ -public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - if (ret != null) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(URLParser.parser((String)allArguments[0])); - } - - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java deleted file mode 100644 index 7e22cddab107..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareCallInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.lang.reflect.Method; -import java.sql.CallableStatement; -import java.sql.Connection; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.plugin.jdbc.trace.SWCallableStatement; - -/** - * {@link JDBCPrepareCallInterceptor} return {@link SWCallableStatement} instance that wrapper the real CallStatement - * instance when the client call prepareCall method. - * - * @author zhangxin - */ -public class JDBCPrepareCallInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (objInst.getSkyWalkingDynamicField() == null) { - return ret; - } - return new SWCallableStatement((Connection)objInst, (CallableStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java deleted file mode 100644 index 39e1cb972cd8..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.PreparedStatement; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; - -/** - * {@link JDBCPrepareStatementInterceptor} return {@link SWPreparedStatement} instance that wrapper the real - * PreparedStatement instance when the client call prepareStatement method. - * - * @author zhangxin - */ -public class JDBCPrepareStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (objInst.getSkyWalkingDynamicField() == null) { - return ret; - } - return new SWPreparedStatement((Connection)objInst, (PreparedStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java deleted file mode 100644 index 837ef1951526..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/JDBCStatementInterceptor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.lang.reflect.Method; -import java.sql.Connection; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.plugin.jdbc.trace.SWStatement; - -/** - * {@link JDBCStatementInterceptor} return {@link SWStatement} instance that wrapper the real Statement instance when - * the client call createStatement method. - * - * @author zhangxin - */ -public class JDBCStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (objInst.getSkyWalkingDynamicField() == null) { - return ret; - } - return new SWStatement((Connection)objInst, (java.sql.Statement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField()); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java deleted file mode 100644 index e5acac32bc49..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.connectionurl.parser; - -public abstract class AbstractURLParser implements ConnectionURLParser { - - protected String url; - - public AbstractURLParser(String url) { - this.url = url; - } - - /** - * Fetch the index range that database host and port from connection url. - * - * @return index range that database hosts. - */ - protected abstract URLLocation fetchDatabaseHostsIndexRange(); - - /** - * Fetch the index range that database name from connection url. - * - * @return index range that database name. - */ - protected abstract URLLocation fetchDatabaseNameIndexRange(); - - /** - * Fetch database host(s) from connection url. - * - * @return database host(s). - */ - protected String fetchDatabaseHostsFromURL() { - URLLocation hostsLocation = fetchDatabaseHostsIndexRange(); - return url.substring(hostsLocation.startIndex(), hostsLocation.endIndex()); - } - - /** - * Fetch database name from connection url. - * - * @return database name. - */ - protected String fetchDatabaseNameFromURL() { - URLLocation hostsLocation = fetchDatabaseNameIndexRange(); - return url.substring(hostsLocation.startIndex(), hostsLocation.endIndex()); - } - - /** - * Fetch database name from connection url. - * - * @return database name. - */ - protected String fetchDatabaseNameFromURL(int[] indexRange) { - return url.substring(indexRange[0], indexRange[1]); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java deleted file mode 100644 index 4a8af8cb8d10..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.connectionurl.parser; - -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -public interface ConnectionURLParser { - /** - * {@link ConnectionURLParser} parses database name and the database host(s) from connection url. - * - * @return connection info. - */ - ConnectionInfo parse(); -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java deleted file mode 100644 index 2685495c12ef..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.connectionurl.parser; - -public class URLLocation { - private final int startIndex; - private final int endIndex; - - public URLLocation(int startIndex, int endIndex) { - this.startIndex = startIndex; - this.endIndex = endIndex; - } - - public int startIndex() { - return startIndex; - } - - public int endIndex() { - return endIndex; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java deleted file mode 100644 index 87ecd426dba9..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.connectionurl.parser; - -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database. But there are - * some url cannot be parsed, such as Oracle connection url with multiple host. - * - * @author zhangxin - */ -public class URLParser { - - private static final String MYSQL_JDBC_URL_PREFIX = "jdbc:mysql"; - private static final String ORACLE_JDBC_URL_PREFIX = "jdbc:oracle"; - private static final String H2_JDBC_URL_PREFIX = "jdbc:h2"; - private static final String POSTGRESQL_JDBC_URL_PREFIX = "jdbc:postgresql"; - - public static ConnectionInfo parser(String url) { - ConnectionURLParser parser = null; - if (url.startsWith(MYSQL_JDBC_URL_PREFIX)) { - parser = new MysqlURLParser(url); - } else if (url.startsWith(ORACLE_JDBC_URL_PREFIX)) { - parser = new OracleURLParser(url); - } else if (url.startsWith(H2_JDBC_URL_PREFIX)) { - parser = new H2URLParser(url); - } else if (url.startsWith(POSTGRESQL_JDBC_URL_PREFIX)) { - parser = new PostgreSQLURLParser(url); - } - return parser.parse(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java deleted file mode 100644 index 1392ed4b4ccb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/AbstractDriverInstrumentation.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -/** - * JDBC plugin using {@link JDBCDriverInterceptor} to intercept the connect method of all driver class. - * - * @author zhangxin - */ -public abstract class AbstractDriverInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String DRIVER_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("connect"); - } - - @Override - public String getMethodsInterceptor() { - return DRIVER_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/Constants.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/Constants.java deleted file mode 100644 index f901401c190a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/Constants.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.define; - -public class Constants { - public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.JDBCStatementInterceptor"; - - public static final String PREPARE_STATEMENT_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.JDBCPrepareStatementInterceptor"; - - public static final String PREPARE_CALL_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.JDBCPrepareCallInterceptor"; - - public static final String SERVICE_METHOD_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jdbc.ConnectionServiceMethodInterceptor"; - - public static final String PREPARE_STATEMENT_METHOD_NAME = "prepareStatement"; - - public static final String PREPARE_CALL_METHOD_NAME = "prepareCall"; - - public static final String CREATE_STATEMENT_METHOD_NAME = "createStatement"; - - public static final String COMMIT_METHOD_NAME = "commit"; - - public static final String ROLLBACK_METHOD_NAME = "rollback"; - - public static final String CLOSE_METHOD_NAME = "close"; - - public static final String RELEASE_SAVE_POINT_METHOD_NAME = "releaseSavepoint"; - -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java deleted file mode 100644 index 6e47f64feac0..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.define; - -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link StatementEnhanceInfos} contain the {@link org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo} and - * sql for trace mysql. - * - * @author zhangxin - */ -public class StatementEnhanceInfos { - private ConnectionInfo connectionInfo; - private String statementName; - private String sql; - - public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) { - this.connectionInfo = connectionInfo; - this.sql = sql; - this.statementName = statementName; - } - - public ConnectionInfo getConnectionInfo() { - return connectionInfo; - } - - public String getSql() { - return sql; - } - - public String getStatementName() { - return statementName; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java deleted file mode 100644 index c066e27034b3..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.trace; - -import java.sql.SQLException; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; - -/** - * {@link CallableStatementTracing} create an exit span when the client call the method in the class that extend {@link - * java.sql.CallableStatement}. - * - * @author zhangxin - */ -public class CallableStatementTracing { - - public static R execute(java.sql.CallableStatement realStatement, - ConnectionInfo connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - SpanLayer.asDB(span); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, sql); - span.setComponent(connectInfo.getComponent()); - return exec.exe(realStatement, sql); - } catch (SQLException e) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(e); - throw e; - } finally { - ContextManager.stopSpan(); - } - } - - public interface Executable { - R exe(java.sql.CallableStatement realConnection, String sql) - throws SQLException; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java deleted file mode 100644 index a046a715e78c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.trace; - -import org.skywalking.apm.network.trace.component.OfficialComponent; - -/** - * {@link ConnectionInfo} stored the jdbc connection info, the connection info contains db type, host, port, database - * name. The {@link #hosts} be null if {@link #host} is not null. - * - * @author zhangxin - */ -public class ConnectionInfo { - /** - * DB type, such as mysql, oracle, h2. - */ - private final String dbType; - /** - * Operation database name. - */ - private final String databaseName; - - private String databasePeer; - - /** - * Component - */ - private final OfficialComponent component; - - public ConnectionInfo(OfficialComponent component, String dbType, String host, int port, String databaseName) { - this.dbType = dbType; - this.databasePeer = host + ":" + port; - this.databaseName = databaseName; - this.component = component; - } - - public ConnectionInfo(OfficialComponent component, String dbType, String hosts, String databaseName) { - this.dbType = dbType; - this.databasePeer = hosts; - this.databaseName = databaseName; - this.component = component; - } - - public String getDBType() { - return dbType; - } - - public String getDatabaseName() { - return databaseName; - } - - public String getDatabasePeer() { - return databasePeer; - } - - public OfficialComponent getComponent() { - return component; - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java deleted file mode 100644 index f7a627b4a035..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.trace; - -import java.sql.SQLException; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; - -/** - * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link - * java.sql.PreparedStatement}. - * - * @author zhangxin - */ -public class PreparedStatementTracing { - - public static R execute(java.sql.PreparedStatement realStatement, - ConnectionInfo connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, sql); - span.setComponent(connectInfo.getComponent()); - - SpanLayer.asDB(span); - return exec.exe(realStatement, sql); - } catch (SQLException e) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(e); - throw e; - } finally { - ContextManager.stopSpan(); - } - } - - public interface Executable { - R exe(java.sql.PreparedStatement realConnection, String sql) - throws SQLException; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java deleted file mode 100644 index 401e708b45ad..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.trace; - -import java.sql.SQLException; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; - -/** - * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link - * java.sql.Statement}. - * - * @author zhangxin - */ -public class StatementTracing { - public static R execute(java.sql.Statement realStatement, - ConnectionInfo connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, sql); - span.setComponent(connectInfo.getComponent()); - SpanLayer.asDB(span); - return exec.exe(realStatement, sql); - } catch (SQLException e) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(e); - throw e; - } finally { - ContextManager.stopSpan(); - } - } - - public interface Executable { - R exe(java.sql.Statement realStatement, String sql) - throws SQLException; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/AbstractStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/AbstractStatementTest.java new file mode 100644 index 000000000000..4fbd91214275 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/AbstractStatementTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.sql.SQLException; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; + +import static junit.framework.TestCase.assertNotNull; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public abstract class AbstractStatementTest { + + protected void assertDBSpanLog(LogDataEntity logData) { + Assert.assertThat(logData.getLogs().size(), is(4)); + Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.is("error")); + Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.is(SQLException.class.getName())); + Assert.assertNull(logData.getLogs().get(2).getValue()); + assertNotNull(logData.getLogs().get(3).getValue()); + } + + protected void assertDBSpan(AbstractTracingSpan span, String exceptOperationName, String exceptDBStatement) { + assertDBSpan(span, exceptOperationName); + assertThat(span.isExit(), is(true)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(2).getValue(), is(exceptDBStatement)); + } + + protected void assertDBSpan(AbstractTracingSpan span, String exceptOperationName) { + assertThat(span.getOperationName(), is(exceptOperationName)); + assertThat(SpanHelper.getComponentId(span), is(5)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(0).getValue(), is("sql")); + assertThat(tags.get(1).getValue(), is("test")); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB)); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionTracing.java new file mode 100755 index 000000000000..8e077604f313 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/ConnectionTracing.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; + +import java.sql.SQLException; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class ConnectionTracing { + + public static R execute(java.sql.Connection realConnection, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method, connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + span.setComponent(connectInfo.getComponent()); + SpanLayer.asDB(span); + return exec.exe(realConnection, sql); + } catch (SQLException e) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(e); + throw e; + } finally { + ContextManager.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.Connection realConnection, String sql) + throws SQLException; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java index f6dfd535e330..4a8594466828 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; import com.mysql.cj.api.jdbc.JdbcConnection; import java.io.InputStream; @@ -42,6 +60,13 @@ import java.util.HashMap; import java.util.List; import java.util.Properties; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; @@ -52,15 +77,8 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnection.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWConnection.java similarity index 90% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnection.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWConnection.java index 60eb3404ed7d..4a5f40f2e261 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnection.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWConnection.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; import java.sql.Array; import java.sql.Blob; @@ -36,11 +54,11 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; -import org.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.plugin.jdbc.trace.SWCallableStatement; -import org.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; -import org.skywalking.apm.plugin.jdbc.trace.SWStatement; +import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWCallableStatement; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWStatement; public class SWConnection implements Connection { private ConnectionInfo connectInfo; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWConnectionTest.java similarity index 90% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWConnectionTest.java index f102bd645de2..8e40820f4ae3 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWConnectionTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; import com.mysql.cj.api.jdbc.JdbcConnection; import java.sql.PreparedStatement; @@ -26,6 +44,7 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.Executor; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,14 +52,13 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWStatementTest.java similarity index 89% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWStatementTest.java index 2f117083072b..421fa183ed3a 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SWStatementTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; import com.mysql.cj.api.jdbc.JdbcConnection; import java.net.MalformedURLException; @@ -26,6 +44,7 @@ import java.sql.Statement; import java.util.List; import java.util.Properties; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Rule; @@ -34,14 +53,13 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java similarity index 95% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java index 6e89a6c0dfbf..1b9e7aecc91d 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jdbc; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc; import com.mysql.cj.api.jdbc.JdbcConnection; import java.io.InputStream; @@ -41,6 +59,15 @@ import java.util.Calendar; import java.util.List; import java.util.Properties; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; @@ -51,15 +78,6 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java similarity index 87% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java index 9774f397fb6c..8e26ce44a1c4 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java @@ -16,10 +16,28 @@ * */ -package org.skywalking.apm.plugin.jdbc.connectionurl.parser; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser; import org.junit.Test; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/AbstractStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/AbstractStatementTest.java deleted file mode 100644 index 0fcc3aa5fa70..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/AbstractStatementTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.sql.SQLException; -import java.util.List; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.test.helper.SpanHelper; - -import static junit.framework.TestCase.assertNotNull; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public abstract class AbstractStatementTest { - - protected void assertDBSpanLog(LogDataEntity logData) { - Assert.assertThat(logData.getLogs().size(), is(4)); - Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.is("error")); - Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.is(SQLException.class.getName())); - Assert.assertNull(logData.getLogs().get(2).getValue()); - assertNotNull(logData.getLogs().get(3).getValue()); - } - - protected void assertDBSpan(AbstractTracingSpan span, String exceptOperationName, String exceptDBStatement) { - assertDBSpan(span, exceptOperationName); - assertThat(span.isExit(), is(true)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(2).getValue(), is(exceptDBStatement)); - } - - protected void assertDBSpan(AbstractTracingSpan span, String exceptOperationName) { - assertThat(span.getOperationName(), is(exceptOperationName)); - assertThat(SpanHelper.getComponentId(span), is(5)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("sql")); - assertThat(tags.get(1).getValue(), is("test")); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java deleted file mode 100755 index 6e5e781c44a7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc; - -import java.sql.SQLException; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -public class ConnectionTracing { - - public static R execute(java.sql.Connection realConnection, - ConnectionInfo connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method, connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, sql); - span.setComponent(connectInfo.getComponent()); - SpanLayer.asDB(span); - return exec.exe(realConnection, sql); - } catch (SQLException e) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(e); - throw e; - } finally { - ContextManager.stopSpan(); - } - } - - public interface Executable { - R exe(java.sql.Connection realConnection, String sql) - throws SQLException; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java new file mode 100644 index 000000000000..801ca01fd12b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import redis.clients.jedis.HostAndPort; + +public class JedisClusterConstructorWithHostAndPortArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + HostAndPort hostAndPort = (HostAndPort)allArguments[0]; + objInst.setSkyWalkingDynamicField(hostAndPort.getHost() + ":" + hostAndPort.getPort()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java new file mode 100644 index 000000000000..0db2c9e1bc7b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import java.util.Set; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import redis.clients.jedis.HostAndPort; + +public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + StringBuilder redisConnInfo = new StringBuilder(); + Set hostAndPorts = (Set)allArguments[0]; + for (HostAndPort hostAndPort : hostAndPorts) { + redisConnInfo.append(hostAndPort.toString()).append(";"); + } + + objInst.setSkyWalkingDynamicField(redisConnInfo.toString()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java new file mode 100644 index 000000000000..27d00d253638 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import redis.clients.jedis.JedisShardInfo; + +public class JedisConstructorWithShardInfoArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String redisConnInfo; + JedisShardInfo shardInfo = (JedisShardInfo)allArguments[0]; + redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort(); + objInst.setSkyWalkingDynamicField(redisConnInfo); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java new file mode 100644 index 000000000000..e711537d058c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class JedisConstructorWithStringArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String host = (String)allArguments[0]; + String port = "6379"; + if (allArguments.length > 1) { + port = String.valueOf(allArguments[1]); + } + + objInst.setSkyWalkingDynamicField(host + ":" + port); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java new file mode 100644 index 000000000000..f87aa36aa907 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import java.net.URI; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class JedisConstructorWithUriArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + URI uri = (URI)allArguments[0]; + objInst.setSkyWalkingDynamicField(uri.getHost() + ":" + uri.getPort()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java new file mode 100644 index 000000000000..201eed2ba56f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class JedisMethodInterceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); + AbstractSpan span = ContextManager.createExitSpan("Jedis/" + method.getName(), peer); + span.setComponent(ComponentsDefine.REDIS); + Tags.DB_TYPE.set(span, "Redis"); + SpanLayer.asDB(span); + + if (allArguments.length > 0 && allArguments[0] instanceof String) { + Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); + } + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java similarity index 87% rename from apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java rename to apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java index 54dd458901ab..13c77c8b4229 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/RedisMethodMatch.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.jedis.v2; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java new file mode 100644 index 000000000000..5d6bf0fcfd2c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2.define; + +import java.util.Set; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithHostAndPortArgInterceptor; +import org.apache.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithListHostAndPortArgInterceptor; +import org.apache.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor; +import org.apache.skywalking.apm.plugin.jedis.v2.RedisMethodMatch; + +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link JedisClusterInstrumentation} presents that skywalking intercepts all constructors and methods of {@link + * redis.clients.jedis.JedisCluster}. {@link JedisClusterConstructorWithHostAndPortArgInterceptor} + * intercepts all constructor with argument {@link redis.clients.jedis.HostAndPort} and the other constructor intercept + * by class {@link JedisClusterConstructorWithListHostAndPortArgInterceptor}. {@link JedisMethodInterceptor} intercept + * all methods of {@link redis.clients.jedis.JedisCluster} + * + * @author zhangxin + */ +public class JedisClusterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ARGUMENT_TYPE_NAME = "redis.clients.jedis.HostAndPort"; + private static final String ENHANCE_CLASS = "redis.clients.jedis.JedisCluster"; + private static final String CONSTRUCTOR_WITH_LIST_HOSTANDPORT_ARG_INTERCEPT_CLASS = "JedisClusterConstructorWithListHostAndPortArgInterceptor"; + private static final String METHOD_INTERCEPT_CLASS = "JedisMethodInterceptor"; + private static final String CONSTRUCTOR_WITH_HOSTANDPORT_ARG_INTERCEPT_CLASS = "JedisClusterConstructorWithHostAndPortArgInterceptor"; + + @Override + public ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(0, Set.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_LIST_HOSTANDPORT_ARG_INTERCEPT_CLASS; + } + }, + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, ARGUMENT_TYPE_NAME); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_HOSTANDPORT_ARG_INTERCEPT_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return RedisMethodMatch.INSTANCE.getJedisClusterMethodMatcher(); + } + + @Override + public String getMethodsInterceptor() { + return METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java new file mode 100644 index 000000000000..fe6561bd7202 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2.define; + +import java.net.URI; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor; +import org.apache.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor; +import org.apache.skywalking.apm.plugin.jedis.v2.RedisMethodMatch; + +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link JedisInstrumentation} presents that skywalking intercept all constructors and methods of {@link + * redis.clients.jedis.Jedis}. {@link JedisConstructorWithShardInfoArgInterceptor} intercepts all constructor with + * argument {@link redis.clients.jedis.HostAndPort} ,{@link JedisConstructorWithUriArgInterceptor} intercepts the + * constructors with uri argument and the other constructor intercept by class {@link + * JedisConstructorWithShardInfoArgInterceptor}. {@link JedisMethodInterceptor} intercept all methods of {@link + * redis.clients.jedis.Jedis}. + * + * @author zhangxin + */ +public class JedisInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String HOST_AND_PORT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort"; + private static final String ENHANCE_CLASS = "redis.clients.jedis.Jedis"; + private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "JedisConstructorWithStringArgInterceptor"; + private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "JedisConstructorWithShardInfoArgInterceptor"; + private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "JedisConstructorWithUriArgInterceptor"; + private static final String JEDIS_METHOD_INTERCET_CLASS = "JedisMethodInterceptor"; + + @Override + public ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(0, String.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS; + } + }, + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, HOST_AND_PORT_ARG_TYPE_NAME); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS; + } + }, + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(0, URI.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return RedisMethodMatch.INSTANCE.getJedisMethodMatcher(); + } + + @Override + public String getMethodsInterceptor() { + return JEDIS_METHOD_INTERCET_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java deleted file mode 100644 index a35145438c5c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.HostAndPort; - -public class JedisClusterConstructorWithHostAndPortArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - HostAndPort hostAndPort = (HostAndPort)allArguments[0]; - objInst.setSkyWalkingDynamicField(hostAndPort.getHost() + ":" + hostAndPort.getPort()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java deleted file mode 100644 index 4599dc422b77..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import java.util.Set; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.HostAndPort; - -public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - StringBuilder redisConnInfo = new StringBuilder(); - Set hostAndPorts = (Set)allArguments[0]; - for (HostAndPort hostAndPort : hostAndPorts) { - redisConnInfo.append(hostAndPort.toString()).append(";"); - } - - objInst.setSkyWalkingDynamicField(redisConnInfo.toString()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java deleted file mode 100644 index a64fd01662cc..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.JedisShardInfo; - -public class JedisConstructorWithShardInfoArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String redisConnInfo; - JedisShardInfo shardInfo = (JedisShardInfo)allArguments[0]; - redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort(); - objInst.setSkyWalkingDynamicField(redisConnInfo); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java deleted file mode 100644 index 5aba8ddb76e9..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class JedisConstructorWithStringArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String host = (String)allArguments[0]; - String port = "6379"; - if (allArguments.length > 1) { - port = String.valueOf(allArguments[1]); - } - - objInst.setSkyWalkingDynamicField(host + ":" + port); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java deleted file mode 100644 index 4eefe98c7c09..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import java.net.URI; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class JedisConstructorWithUriArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - URI uri = (URI)allArguments[0]; - objInst.setSkyWalkingDynamicField(uri.getHost() + ":" + uri.getPort()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java deleted file mode 100644 index ea48e2076860..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class JedisMethodInterceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); - AbstractSpan span = ContextManager.createExitSpan("Jedis/" + method.getName(), peer); - span.setComponent(ComponentsDefine.REDIS); - Tags.DB_TYPE.set(span, "Redis"); - SpanLayer.asDB(span); - - if (allArguments.length > 0 && allArguments[0] instanceof String) { - Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); - } - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java deleted file mode 100644 index a53605fae171..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisClusterInstrumentation.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2.define; - -import java.util.Set; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithHostAndPortArgInterceptor; -import org.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithListHostAndPortArgInterceptor; -import org.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor; -import org.skywalking.apm.plugin.jedis.v2.RedisMethodMatch; - -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JedisClusterInstrumentation} presents that skywalking intercepts all constructors and methods of {@link - * redis.clients.jedis.JedisCluster}. {@link JedisClusterConstructorWithHostAndPortArgInterceptor} - * intercepts all constructor with argument {@link redis.clients.jedis.HostAndPort} and the other constructor intercept - * by class {@link JedisClusterConstructorWithListHostAndPortArgInterceptor}. {@link JedisMethodInterceptor} intercept - * all methods of {@link redis.clients.jedis.JedisCluster} - * - * @author zhangxin - */ -public class JedisClusterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ARGUMENT_TYPE_NAME = "redis.clients.jedis.HostAndPort"; - private static final String ENHANCE_CLASS = "redis.clients.jedis.JedisCluster"; - private static final String CONSTRUCTOR_WITH_LIST_HOSTANDPORT_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithListHostAndPortArgInterceptor"; - private static final String METHOD_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor"; - private static final String CONSTRUCTOR_WITH_HOSTANDPORT_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithHostAndPortArgInterceptor"; - - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, Set.class); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_LIST_HOSTANDPORT_ARG_INTERCEPT_CLASS; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, ARGUMENT_TYPE_NAME); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_HOSTANDPORT_ARG_INTERCEPT_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return RedisMethodMatch.INSTANCE.getJedisClusterMethodMatcher(); - } - - @Override - public String getMethodsInterceptor() { - return METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java deleted file mode 100644 index 6d1e18492f00..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/define/JedisInstrumentation.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2.define; - -import java.net.URI; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor; -import org.skywalking.apm.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor; -import org.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor; -import org.skywalking.apm.plugin.jedis.v2.RedisMethodMatch; - -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JedisInstrumentation} presents that skywalking intercept all constructors and methods of {@link - * redis.clients.jedis.Jedis}. {@link JedisConstructorWithShardInfoArgInterceptor} intercepts all constructor with - * argument {@link redis.clients.jedis.HostAndPort} ,{@link JedisConstructorWithUriArgInterceptor} intercepts the - * constructors with uri argument and the other constructor intercept by class {@link - * JedisConstructorWithShardInfoArgInterceptor}. {@link JedisMethodInterceptor} intercept all methods of {@link - * redis.clients.jedis.Jedis}. - * - * @author zhangxin - */ -public class JedisInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String HOST_AND_PORT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort"; - private static final String ENHANCE_CLASS = "redis.clients.jedis.Jedis"; - private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisConstructorWithStringArgInterceptor"; - private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor"; - private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor"; - private static final String JEDIS_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor"; - - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, String.class); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, HOST_AND_PORT_ARG_TYPE_NAME); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, URI.class); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return RedisMethodMatch.INSTANCE.getJedisMethodMatcher(); - } - - @Override - public String getMethodsInterceptor() { - return JEDIS_METHOD_INTERCET_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def index d2b37ef8c74b..6e343906f094 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -jedis-2.x=org.skywalking.apm.plugin.jedis.v2.define.JedisClusterInstrumentation -jedis-2.x=org.skywalking.apm.plugin.jedis.v2.define.JedisInstrumentation \ No newline at end of file +jedis-2.x=JedisClusterInstrumentation +jedis-2.x=JedisInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java new file mode 100644 index 000000000000..36e8df924d2d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import redis.clients.jedis.HostAndPort; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class JedisClusterConstructorWithHostAndPortArgInterceptorTest { + + private JedisClusterConstructorWithHostAndPortArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new JedisClusterConstructorWithHostAndPortArgInterceptor(); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void onConstruct() throws Exception { + interceptor.onConstruct(enhancedInstance, new Object[] {new HostAndPort("127.0.0.1", 6379)}); + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java new file mode 100644 index 000000000000..f1d7ce63e1ef --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import java.util.HashSet; +import java.util.Set; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import redis.clients.jedis.HostAndPort; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class JedisClusterConstructorWithListHostAndPortArgInterceptorTest { + + private JedisClusterConstructorWithListHostAndPortArgInterceptor interceptor; + + private Set hostAndPortSet; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + hostAndPortSet = new HashSet(); + interceptor = new JedisClusterConstructorWithListHostAndPortArgInterceptor(); + hostAndPortSet.add(new HostAndPort("127.0.0.1", 6379)); + hostAndPortSet.add(new HostAndPort("127.0.0.1", 16379)); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void onConstruct() throws Exception { + interceptor.onConstruct(enhancedInstance, new Object[] {hostAndPortSet}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379;127.0.0.1:16379;"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java new file mode 100644 index 000000000000..4440836f980c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import redis.clients.jedis.JedisShardInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class JedisConstructorWithShardInfoArgInterceptorTest { + private JedisConstructorWithShardInfoArgInterceptor interceptor; + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new JedisConstructorWithShardInfoArgInterceptor(); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void onConstruct() throws Exception { + + interceptor.onConstruct(enhancedInstance, new Object[] {new JedisShardInfo("127.0.0.1", 6379)}); + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java new file mode 100644 index 000000000000..699d859c9468 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class JedisConstructorWithStringArgInterceptorTest { + + private JedisConstructorWithStringArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new JedisConstructorWithStringArgInterceptor(); + } + + @Test + public void onConstruct() throws Exception { + interceptor.onConstruct(enhancedInstance, new Object[] {"127.0.0.1"}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); + } + + @Test + public void onConstructWithPort() { + interceptor.onConstruct(enhancedInstance, new Object[] {"127.0.0.1", 16379}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:16379"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java new file mode 100644 index 000000000000..4c360391c799 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; + +import java.net.URI; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(URI.class) +public class JedisConstructorWithUriArgInterceptorTest { + + private JedisConstructorWithUriArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + private URI uri = URI.create("http://127.0.0.1:6379"); + + @Before + public void setUp() throws Exception { + interceptor = new JedisConstructorWithUriArgInterceptor(); + } + + @Test + public void onConstruct() throws Exception { + interceptor.onConstruct(enhancedInstance, new Object[] {uri}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java similarity index 75% rename from apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java index 087804471c67..09280a13d653 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java @@ -16,10 +16,38 @@ * */ -package org.skywalking.apm.plugin.jedis.v2; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jedis.v2; import java.lang.reflect.Method; import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; @@ -29,18 +57,8 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import redis.clients.jedis.Jedis; import static junit.framework.TestCase.assertNotNull; @@ -131,7 +149,7 @@ private void assertRedisSpan(AbstractTracingSpan span) { List tags = SpanHelper.getTags(span); assertThat(tags.get(0).getValue(), is("Redis")); assertThat(tags.get(1).getValue(), is("set OperationKey")); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB)); } private Method getMockSetMethod() { diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java deleted file mode 100644 index ea5eb982ffed..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import redis.clients.jedis.HostAndPort; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class JedisClusterConstructorWithHostAndPortArgInterceptorTest { - - private JedisClusterConstructorWithHostAndPortArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new JedisClusterConstructorWithHostAndPortArgInterceptor(); - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void onConstruct() throws Exception { - interceptor.onConstruct(enhancedInstance, new Object[] {new HostAndPort("127.0.0.1", 6379)}); - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java deleted file mode 100644 index c8d7eee61007..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import java.util.HashSet; -import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import redis.clients.jedis.HostAndPort; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class JedisClusterConstructorWithListHostAndPortArgInterceptorTest { - - private JedisClusterConstructorWithListHostAndPortArgInterceptor interceptor; - - private Set hostAndPortSet; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - hostAndPortSet = new HashSet(); - interceptor = new JedisClusterConstructorWithListHostAndPortArgInterceptor(); - hostAndPortSet.add(new HostAndPort("127.0.0.1", 6379)); - hostAndPortSet.add(new HostAndPort("127.0.0.1", 16379)); - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void onConstruct() throws Exception { - interceptor.onConstruct(enhancedInstance, new Object[] {hostAndPortSet}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379;127.0.0.1:16379;"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java deleted file mode 100644 index 81fd9afadab2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptorTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import redis.clients.jedis.JedisShardInfo; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class JedisConstructorWithShardInfoArgInterceptorTest { - private JedisConstructorWithShardInfoArgInterceptor interceptor; - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new JedisConstructorWithShardInfoArgInterceptor(); - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void onConstruct() throws Exception { - - interceptor.onConstruct(enhancedInstance, new Object[] {new JedisShardInfo("127.0.0.1", 6379)}); - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java deleted file mode 100644 index 3d066dea50ec..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithStringArgInterceptorTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class JedisConstructorWithStringArgInterceptorTest { - - private JedisConstructorWithStringArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new JedisConstructorWithStringArgInterceptor(); - } - - @Test - public void onConstruct() throws Exception { - interceptor.onConstruct(enhancedInstance, new Object[] {"127.0.0.1"}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); - } - - @Test - public void onConstructWithPort() { - interceptor.onConstruct(enhancedInstance, new Object[] {"127.0.0.1", 16379}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:16379"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java deleted file mode 100644 index e434b3639760..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisConstructorWithUriArgInterceptorTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jedis.v2; - -import java.net.URI; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(URI.class) -public class JedisConstructorWithUriArgInterceptorTest { - - private JedisConstructorWithUriArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - private URI uri = URI.create("http://127.0.0.1:6379"); - - @Before - public void setUp() throws Exception { - interceptor = new JedisConstructorWithUriArgInterceptor(); - } - - @Test - public void onConstruct() throws Exception { - interceptor.onConstruct(enhancedInstance, new Object[] {uri}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:6379"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java new file mode 100644 index 000000000000..a0506747f25e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.eclipse.jetty.client.HttpRequest; +import org.eclipse.jetty.http.HttpFields; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class AsyncHttpRequestSendInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpRequest request = (HttpRequest)objInst; + ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, request.getHost() + ":" + request.getPort()); + span.setComponent(ComponentsDefine.JETTY_CLIENT); + Tags.HTTP.METHOD.set(span, request.getMethod().asString()); + Tags.URL.set(span, request.getURI().toString()); + SpanLayer.asHttp(span); + + CarrierItem next = contextCarrier.items(); + HttpFields field = request.getHeaders(); + while (next.hasNext()) { + next = next.next(); + field.add(next.getHeadKey(), next.getHeadValue()); + } + + EnhancedInstance callBackResult = (EnhancedInstance)allArguments[0]; + callBackResult.setSkyWalkingDynamicField(ContextManager.capture()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java new file mode 100644 index 000000000000..8a2d560930f3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.eclipse.jetty.client.api.Result; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class CompleteListenerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ContextSnapshot contextSnapshot = (ContextSnapshot)objInst.getSkyWalkingDynamicField(); + if (contextSnapshot != null) { + Result callBackResult = (Result)allArguments[0]; + + AbstractSpan abstractSpan = ContextManager.createLocalSpan("CallBack/" + callBackResult.getRequest().getURI().getPath()); + ContextManager.continued(contextSnapshot); + + if (callBackResult.isFailed()) { + abstractSpan.errorOccurred().log(callBackResult.getFailure()); + Tags.STATUS_CODE.set(abstractSpan, Integer.toString(callBackResult.getResponse().getStatus())); + } + abstractSpan.setComponent(ComponentsDefine.JETTY_CLIENT); + abstractSpan.setLayer(SpanLayer.HTTP); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextSnapshot contextSnapshot = (ContextSnapshot)objInst.getSkyWalkingDynamicField(); + if (contextSnapshot != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java new file mode 100644 index 000000000000..3670864205e6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.eclipse.jetty.client.HttpRequest; +import org.eclipse.jetty.http.HttpFields; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SyncHttpRequestSendInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpRequest request = (HttpRequest)objInst; + ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, request.getHost() + ":" + request.getPort()); + span.setComponent(ComponentsDefine.JETTY_CLIENT); + Tags.HTTP.METHOD.set(span, "GET"); + Tags.URL.set(span, request.getURI().toString()); + SpanLayer.asHttp(span); + + CarrierItem next = contextCarrier.items(); + HttpFields field = request.getHeaders(); + while (next.hasNext()) { + next = next.next(); + field.add(next.getHeadKey(), next.getHeadValue()); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java new file mode 100644 index 000000000000..26b39c8287e7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; + +/** + * {@link CompleteListenerInstrumentation} enhance the onComplete method in all class of hierarchy + * org.eclipse.jetty.client.api.Response$CompleteListener by org.apache.skywalking.apm.plugin.jetty.client.CompleteListenerInterceptor + * + * @author zhangxin + */ +public class CompleteListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.eclipse.jetty.client.api.Response$CompleteListener"; + private static final String ENHANCE_METHOD = "onComplete"; + public static final String SEND_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jetty.client.CompleteListenerInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return SEND_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byHierarchyMatch(new String[] {ENHANCE_CLASS}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java new file mode 100644 index 000000000000..d1ed562e6f42 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; + +/** + * {@link HttpRequestInstrumentation} enhance the send method without argument in + * org.eclipse.jetty.client.HttpRequest by org.apache.skywalking.apm.plugin.jetty.client.SyncHttpRequestSendInterceptor + * and enhance the send with org.eclipse.jetty.client.api.Response$CompleteListener parameter + * by org.apache.skywalking.apm.plugin.jetty.client.AsyncHttpRequestSendInterceptor + * + * @author zhangxin + */ +public class HttpRequestInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.eclipse.jetty.client.HttpRequest"; + private static final String ENHANCE_CLASS_NAME = "send"; + public static final String ASYNC_SEND_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jetty.client.AsyncHttpRequestSendInterceptor"; + public static final String SYNC_SEND_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jetty.client.SyncHttpRequestSendInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + //sync call interceptor point + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_CLASS_NAME).and(takesArguments(0)); + } + + @Override public String getMethodsInterceptor() { + return SYNC_SEND_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + //async call interceptor point + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_CLASS_NAME).and(takesArgumentWithType(0, "org.eclipse.jetty.client.api.Response$CompleteListener")); + } + + @Override public String getMethodsInterceptor() { + return ASYNC_SEND_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java deleted file mode 100644 index 6eda9a77367b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client; - -import java.lang.reflect.Method; -import org.eclipse.jetty.client.HttpRequest; -import org.eclipse.jetty.http.HttpFields; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class AsyncHttpRequestSendInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - HttpRequest request = (HttpRequest)objInst; - ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan span = ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, request.getHost() + ":" + request.getPort()); - span.setComponent(ComponentsDefine.JETTY_CLIENT); - Tags.HTTP.METHOD.set(span, request.getMethod().asString()); - Tags.URL.set(span, request.getURI().toString()); - SpanLayer.asHttp(span); - - CarrierItem next = contextCarrier.items(); - HttpFields field = request.getHeaders(); - while (next.hasNext()) { - next = next.next(); - field.add(next.getHeadKey(), next.getHeadValue()); - } - - EnhancedInstance callBackResult = (EnhancedInstance)allArguments[0]; - callBackResult.setSkyWalkingDynamicField(ContextManager.capture()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java deleted file mode 100644 index 4b165936baca..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client; - -import java.lang.reflect.Method; -import org.eclipse.jetty.client.api.Result; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class CompleteListenerInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ContextSnapshot contextSnapshot = (ContextSnapshot)objInst.getSkyWalkingDynamicField(); - if (contextSnapshot != null) { - Result callBackResult = (Result)allArguments[0]; - - AbstractSpan abstractSpan = ContextManager.createLocalSpan("CallBack/" + callBackResult.getRequest().getURI().getPath()); - ContextManager.continued(contextSnapshot); - - if (callBackResult.isFailed()) { - abstractSpan.errorOccurred().log(callBackResult.getFailure()); - Tags.STATUS_CODE.set(abstractSpan, Integer.toString(callBackResult.getResponse().getStatus())); - } - abstractSpan.setComponent(ComponentsDefine.JETTY_CLIENT); - abstractSpan.setLayer(SpanLayer.HTTP); - } - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextSnapshot contextSnapshot = (ContextSnapshot)objInst.getSkyWalkingDynamicField(); - if (contextSnapshot != null) { - ContextManager.stopSpan(); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java deleted file mode 100644 index 0e91c9c93c24..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client; - -import java.lang.reflect.Method; -import org.eclipse.jetty.client.HttpRequest; -import org.eclipse.jetty.http.HttpFields; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class SyncHttpRequestSendInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - HttpRequest request = (HttpRequest)objInst; - ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan span = ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, request.getHost() + ":" + request.getPort()); - span.setComponent(ComponentsDefine.JETTY_CLIENT); - Tags.HTTP.METHOD.set(span, "GET"); - Tags.URL.set(span, request.getURI().toString()); - SpanLayer.asHttp(span); - - CarrierItem next = contextCarrier.items(); - HttpFields field = request.getHeaders(); - while (next.hasNext()) { - next = next.next(); - field.add(next.getHeadKey(), next.getHeadValue()); - } - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java deleted file mode 100644 index ae398443d625..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; - -/** - * {@link CompleteListenerInstrumentation} enhance the onComplete method in all class of hierarchy - * org.eclipse.jetty.client.api.Response$CompleteListener by org.skywalking.apm.plugin.jetty.client.CompleteListenerInterceptor - * - * @author zhangxin - */ -public class CompleteListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.eclipse.jetty.client.api.Response$CompleteListener"; - private static final String ENHANCE_METHOD = "onComplete"; - public static final String SEND_INTERCEPTOR = "org.skywalking.apm.plugin.jetty.client.CompleteListenerInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return SEND_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byHierarchyMatch(new String[] {ENHANCE_CLASS}); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java deleted file mode 100644 index c726202a4ff6..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link HttpRequestInstrumentation} enhance the send method without argument in - * org.eclipse.jetty.client.HttpRequest by org.skywalking.apm.plugin.jetty.client.SyncHttpRequestSendInterceptor - * and enhance the send with org.eclipse.jetty.client.api.Response$CompleteListener parameter - * by org.skywalking.apm.plugin.jetty.client.AsyncHttpRequestSendInterceptor - * - * @author zhangxin - */ -public class HttpRequestInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.eclipse.jetty.client.HttpRequest"; - private static final String ENHANCE_CLASS_NAME = "send"; - public static final String ASYNC_SEND_INTERCEPTOR = "org.skywalking.apm.plugin.jetty.client.AsyncHttpRequestSendInterceptor"; - public static final String SYNC_SEND_INTERCEPTOR = "org.skywalking.apm.plugin.jetty.client.SyncHttpRequestSendInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - //sync call interceptor point - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_CLASS_NAME).and(takesArguments(0)); - } - - @Override public String getMethodsInterceptor() { - return SYNC_SEND_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - //async call interceptor point - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_CLASS_NAME).and(takesArgumentWithType(0, "org.eclipse.jetty.client.api.Response$CompleteListener")); - } - - @Override public String getMethodsInterceptor() { - return ASYNC_SEND_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def index 72bfb22aeff0..293a141abb03 100644 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -jetty-client-9.x=org.skywalking.apm.plugin.jetty.v9.client.define.CompleteListenerInstrumentation -jetty-client-9.x=org.skywalking.apm.plugin.jetty.v9.client.define.HttpRequestInstrumentation +jetty-client-9.x=CompleteListenerInstrumentation +jetty-client-9.x=HttpRequestInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java new file mode 100644 index 000000000000..05a7f723df2c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client; + +import java.net.URI; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.HttpRequest; +import org.eclipse.jetty.http.HttpMethod; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class AsyncHttpRequestSendInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + @Mock + private HttpClient httpClient; + @Mock + private EnhancedInstance callBackEnhanceInstance; + + private Object[] allArguments; + private Class[] argumentTypes; + private MockHttpRequest enhancedInstance; + private AsyncHttpRequestSendInterceptor interceptor; + private URI uri = URI.create("http://localhost:8080/test"); + + @Before + public void setUp() throws Exception { + enhancedInstance = new MockHttpRequest(httpClient, uri); + allArguments = new Object[] {"OperationKey", "OperationValue"}; + argumentTypes = new Class[] {String.class, String.class}; + + interceptor = new AsyncHttpRequestSendInterceptor(); + allArguments = new Object[] {callBackEnhanceInstance}; + } + + @Test + public void testMethodsAround() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + + Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); + AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); + + List tags = SpanHelper.getTags(finishedSpan); + assertThat(tags.size(), is(2)); + assertThat(tags.get(0).getValue(), is("POST")); + assertThat(tags.get(1).getValue(), is(uri.toString())); + + Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan)); + } + + @Test + public void testMethodsAroundError() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + + Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); + AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); + + List tags = SpanHelper.getTags(finishedSpan); + assertThat(tags.size(), is(2)); + assertThat(tags.get(0).getValue(), is("POST")); + assertThat(tags.get(1).getValue(), is(uri.toString())); + + Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan)); + SpanAssert.assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class); + + } + + private class MockHttpRequest extends HttpRequest implements EnhancedInstance { + public MockHttpRequest(HttpClient httpClient, URI uri) { + super(httpClient, uri); + } + + @Override public Object getSkyWalkingDynamicField() { + return null; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + + @Override public HttpMethod getMethod() { + return HttpMethod.POST; + } + + @Override public URI getURI() { + return uri; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java similarity index 75% rename from apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java index 6709bfc3e36e..bd06a60144ee 100644 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java @@ -16,9 +16,36 @@ * */ -package org.skywalking.apm.plugin.jetty.v9.client; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client; import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import org.eclipse.jetty.client.HttpRequest; import org.eclipse.jetty.client.HttpResponse; import org.eclipse.jetty.client.api.Result; @@ -30,15 +57,6 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.ids.DistributedTraceId; -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java new file mode 100644 index 000000000000..af2483cc1f4a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.client; + +import java.net.URI; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.HttpRequest; +import org.eclipse.jetty.http.HttpMethod; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class SyncHttpRequestSendInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + @Mock + private HttpClient httpClient; + @Mock + private EnhancedInstance callBackEnhanceInstance; + + private Object[] allArguments; + private Class[] argumentTypes; + private MockHttpRequest enhancedInstance; + private AsyncHttpRequestSendInterceptor interceptor; + private URI uri = URI.create("http://localhost:8080/test"); + + @Before + public void setUp() throws Exception { + enhancedInstance = new MockHttpRequest(httpClient, uri); + allArguments = new Object[] {"OperationKey", "OperationValue"}; + argumentTypes = new Class[] {String.class, String.class}; + + interceptor = new AsyncHttpRequestSendInterceptor(); + allArguments = new Object[] {callBackEnhanceInstance}; + } + + @Test + public void testMethodsAround() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + + Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); + AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); + + List tags = SpanHelper.getTags(finishedSpan); + assertThat(tags.size(), is(2)); + assertThat(tags.get(0).getValue(), is("GET")); + assertThat(tags.get(1).getValue(), is(uri.toString())); + + Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan)); + } + + @Test + public void testMethodsAroundError() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + + Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); + AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); + + List tags = SpanHelper.getTags(finishedSpan); + assertThat(tags.size(), is(2)); + assertThat(tags.get(0).getValue(), is("GET")); + assertThat(tags.get(1).getValue(), is(uri.toString())); + + Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan)); + SpanAssert.assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class); + + } + + private class MockHttpRequest extends HttpRequest implements EnhancedInstance { + public MockHttpRequest(HttpClient httpClient, URI uri) { + super(httpClient, uri); + } + + @Override public Object getSkyWalkingDynamicField() { + return null; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + + @Override public HttpMethod getMethod() { + return HttpMethod.GET; + } + + @Override public URI getURI() { + return uri; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java deleted file mode 100644 index 8aa990656d37..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client; - -import java.net.URI; -import java.util.List; -import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.client.HttpRequest; -import org.eclipse.jetty.http.HttpMethod; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class AsyncHttpRequestSendInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - @Mock - private HttpClient httpClient; - @Mock - private EnhancedInstance callBackEnhanceInstance; - - private Object[] allArguments; - private Class[] argumentTypes; - private MockHttpRequest enhancedInstance; - private AsyncHttpRequestSendInterceptor interceptor; - private URI uri = URI.create("http://localhost:8080/test"); - - @Before - public void setUp() throws Exception { - enhancedInstance = new MockHttpRequest(httpClient, uri); - allArguments = new Object[] {"OperationKey", "OperationValue"}; - argumentTypes = new Class[] {String.class, String.class}; - - interceptor = new AsyncHttpRequestSendInterceptor(); - allArguments = new Object[] {callBackEnhanceInstance}; - } - - @Test - public void testMethodsAround() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - - Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); - AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); - - List tags = SpanHelper.getTags(finishedSpan); - assertThat(tags.size(), is(2)); - assertThat(tags.get(0).getValue(), is("POST")); - assertThat(tags.get(1).getValue(), is(uri.toString())); - - Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan)); - } - - @Test - public void testMethodsAroundError() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - - Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); - AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); - - List tags = SpanHelper.getTags(finishedSpan); - assertThat(tags.size(), is(2)); - assertThat(tags.get(0).getValue(), is("POST")); - assertThat(tags.get(1).getValue(), is(uri.toString())); - - Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan)); - assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class); - - } - - private class MockHttpRequest extends HttpRequest implements EnhancedInstance { - public MockHttpRequest(HttpClient httpClient, URI uri) { - super(httpClient, uri); - } - - @Override public Object getSkyWalkingDynamicField() { - return null; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - - } - - @Override public HttpMethod getMethod() { - return HttpMethod.POST; - } - - @Override public URI getURI() { - return uri; - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java deleted file mode 100644 index 873a0ba2f45d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.client; - -import java.net.URI; -import java.util.List; -import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.client.HttpRequest; -import org.eclipse.jetty.http.HttpMethod; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class SyncHttpRequestSendInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - @Mock - private HttpClient httpClient; - @Mock - private EnhancedInstance callBackEnhanceInstance; - - private Object[] allArguments; - private Class[] argumentTypes; - private MockHttpRequest enhancedInstance; - private AsyncHttpRequestSendInterceptor interceptor; - private URI uri = URI.create("http://localhost:8080/test"); - - @Before - public void setUp() throws Exception { - enhancedInstance = new MockHttpRequest(httpClient, uri); - allArguments = new Object[] {"OperationKey", "OperationValue"}; - argumentTypes = new Class[] {String.class, String.class}; - - interceptor = new AsyncHttpRequestSendInterceptor(); - allArguments = new Object[] {callBackEnhanceInstance}; - } - - @Test - public void testMethodsAround() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - - Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); - AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); - - List tags = SpanHelper.getTags(finishedSpan); - assertThat(tags.size(), is(2)); - assertThat(tags.get(0).getValue(), is("GET")); - assertThat(tags.get(1).getValue(), is(uri.toString())); - - Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan)); - } - - @Test - public void testMethodsAroundError() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - - Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size()); - AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0); - - List tags = SpanHelper.getTags(finishedSpan); - assertThat(tags.size(), is(2)); - assertThat(tags.get(0).getValue(), is("GET")); - assertThat(tags.get(1).getValue(), is(uri.toString())); - - Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan)); - assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class); - - } - - private class MockHttpRequest extends HttpRequest implements EnhancedInstance { - public MockHttpRequest(HttpClient httpClient, URI uri) { - super(httpClient, uri); - } - - @Override public Object getSkyWalkingDynamicField() { - return null; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - - } - - @Override public HttpMethod getMethod() { - return HttpMethod.GET; - } - - @Override public URI getURI() { - return uri; - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java new file mode 100644 index 000000000000..6ea4caa1c574 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.server; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.eclipse.jetty.server.HttpChannel; + +public class HandleInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpChannel httpChannel = (HttpChannel)allArguments[0]; + HttpServletRequest servletRequest = httpChannel.getRequest(); + + ContextCarrier contextCarrier = new ContextCarrier(); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(servletRequest.getHeader(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier); + Tags.URL.set(span, servletRequest.getRequestURL().toString()); + Tags.HTTP.METHOD.set(span, servletRequest.getMethod()); + span.setComponent(ComponentsDefine.JETTY_SERVER); + SpanLayer.asHttp(span); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + HttpChannel httpChannel = (HttpChannel)allArguments[0]; + HttpServletResponse servletResponse = httpChannel.getResponse(); + AbstractSpan span = ContextManager.activeSpan(); + if (servletResponse.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(servletResponse.getStatus())); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java new file mode 100644 index 000000000000..ab230969349b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.server.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; + +/** + * {@link JettyInstrumentation} enhance the handle method in org.eclipse.jetty.server.handler.HandlerList + * by HandleInterceptor + * + * @author zhangxin + */ +public class JettyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.eclipse.jetty.server.Server"; + private static final String ENHANCE_METHOD = "handle"; + private static final String INTERCEPTOR_CLASS = "HandleInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD).and(takesArgumentWithType(0, "org.eclipse.jetty.server.HttpChannel")); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java deleted file mode 100644 index 0180a75f7e61..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.server; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.server.HttpChannel; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class HandleInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - HttpChannel httpChannel = (HttpChannel)allArguments[0]; - HttpServletRequest servletRequest = httpChannel.getRequest(); - - ContextCarrier contextCarrier = new ContextCarrier(); - - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(servletRequest.getHeader(next.getHeadKey())); - } - - AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier); - Tags.URL.set(span, servletRequest.getRequestURL().toString()); - Tags.HTTP.METHOD.set(span, servletRequest.getMethod()); - span.setComponent(ComponentsDefine.JETTY_SERVER); - SpanLayer.asHttp(span); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - HttpChannel httpChannel = (HttpChannel)allArguments[0]; - HttpServletResponse servletResponse = httpChannel.getResponse(); - AbstractSpan span = ContextManager.activeSpan(); - if (servletResponse.getStatus() >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(servletResponse.getStatus())); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java deleted file mode 100644 index b67da4ddce71..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.server.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JettyInstrumentation} enhance the handle method in org.eclipse.jetty.server.handler.HandlerList - * by org.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor - * - * @author zhangxin - */ -public class JettyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.eclipse.jetty.server.Server"; - private static final String ENHANCE_METHOD = "handle"; - private static final String INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD).and(takesArgumentWithType(0, "org.eclipse.jetty.server.HttpChannel")); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def index 053c257c2ebf..f2c39cb130f2 100644 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -jetty-server-9.x=org.skywalking.apm.plugin.jetty.v9.server.define.JettyInstrumentation +jetty-server-9.x=JettyInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java new file mode 100644 index 000000000000..1167843c281d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jetty.v9.server; + +import java.util.List; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.eclipse.jetty.server.HttpChannel; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Response; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class HandleInterceptorTest { + + private HandleInterceptor jettyInvokeInterceptor; + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private Request request; + + @Mock + private Response response; + @Mock + private MethodInterceptResult methodInterceptResult; + + @Mock + private EnhancedInstance enhancedInstance; + + @Mock + private HttpChannel httpChannel; + + private Object[] arguments; + private Class[] argumentType; + + @Before + public void setUp() throws Exception { + jettyInvokeInterceptor = new HandleInterceptor(); + when(request.getRequestURI()).thenReturn("/test/testRequestURL"); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatus()).thenReturn(200); + when(httpChannel.getResponse()).thenReturn(response); + when(httpChannel.getRequest()).thenReturn(request); + arguments = new Object[] {httpChannel}; + argumentType = new Class[] {httpChannel.getClass()}; + + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithSerializedContextData() throws Throwable { + when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + + jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + jettyInvokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); + } + + private void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.JETTY_SERVER); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java deleted file mode 100644 index 3019d3959ddb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jetty.v9.server; - -import java.util.List; -import org.eclipse.jetty.server.HttpChannel; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Response; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class HandleInterceptorTest { - - private HandleInterceptor jettyInvokeInterceptor; - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private Request request; - - @Mock - private Response response; - @Mock - private MethodInterceptResult methodInterceptResult; - - @Mock - private EnhancedInstance enhancedInstance; - - @Mock - private HttpChannel httpChannel; - - private Object[] arguments; - private Class[] argumentType; - - @Before - public void setUp() throws Exception { - jettyInvokeInterceptor = new HandleInterceptor(); - when(request.getRequestURI()).thenReturn("/test/testRequestURL"); - when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); - when(response.getStatus()).thenReturn(200); - when(httpChannel.getResponse()).thenReturn(response); - when(httpChannel.getRequest()).thenReturn(request); - arguments = new Object[] {httpChannel}; - argumentType = new Class[] {httpChannel.getClass()}; - - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithSerializedContextData() throws Throwable { - when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); - - jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - assertTraceSegmentRef(traceSegment.getRefs().get(0)); - } - - @Test - public void testWithOccurException() throws Throwable { - jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - jettyInvokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); - jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); - assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); - } - - private void assertHttpSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("/test/testRequestURL")); - assertComponent(span, ComponentsDefine.JETTY_SERVER); - assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java new file mode 100644 index 000000000000..62bd61ea3351 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v2; + +import com.mongodb.AggregationOutput; +import com.mongodb.CommandResult; +import com.mongodb.DB; +import com.mongodb.ServerAddress; +import com.mongodb.WriteResult; +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link MongoDBCollectionMethodInterceptor} intercepts constructor of {@link com.mongodb.DBCollection}or {@link + * com.mongodb.DBCollectionImpl} recording the ServerAddress and creating the exit span. + * + * @author liyuntao + */ + +public class MongoDBCollectionMethodInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { + + private static final String DB_TYPE = "MongoDB"; + + private static final String MONGO_DB_OP_PREFIX = "MongoDB/"; + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + String remotePeer = (String)objInst.getSkyWalkingDynamicField(); + String opertaion = method.getName(); + AbstractSpan span = ContextManager.createExitSpan(MONGO_DB_OP_PREFIX + opertaion, new ContextCarrier(), remotePeer); + span.setComponent(ComponentsDefine.MONGODB); + Tags.DB_TYPE.set(span, DB_TYPE); + SpanLayer.asDB(span); + + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + AbstractSpan activeSpan = ContextManager.activeSpan(); + CommandResult cresult = null; + if (ret instanceof WriteResult) { + WriteResult wresult = (WriteResult)ret; + cresult = wresult.getCachedLastError(); + } else if (ret instanceof AggregationOutput) { + AggregationOutput aresult = (AggregationOutput)ret; + cresult = aresult.getCommandResult(); + } + if (null != cresult && !cresult.ok()) { + activeSpan.log(cresult.getException()); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + activeSpan.log(t); + } + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + List servers = null; + DB db = (DB)allArguments[0]; + servers = db.getMongo().getAllAddress(); + StringBuilder peers = new StringBuilder(); + for (ServerAddress address : servers) { + peers.append(address.getHost() + ":" + address.getPort() + ";"); + } + + objInst.setSkyWalkingDynamicField(peers.subSequence(0, peers.length() - 1).toString()); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java new file mode 100644 index 000000000000..bfad16056fe9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v2.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; + +/** + * @auther liyuntao + */ +public abstract class InterceptPoint implements InstanceMethodsInterceptPoint { + private static final String MONGDB_METHOD_INTERCET_CLASS = "MongoDBCollectionMethodInterceptor"; + + @Override + public String getMethodsInterceptor() { + return MONGDB_METHOD_INTERCET_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java new file mode 100644 index 000000000000..5d9ba3c9a9fb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v2.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@link MongoDBCollectionImplInstrumentation} define that the MongoDB Java Driver 2.13.x-2.14.x plugin intercepts the + * following methods in the {@link com.mongodb.DBCollectionImpl}class: + * 1. find
+ * 2. insert
+ * 3. insertImpl
+ * 4. update
+ * 5. updateImpl
+ * 6. remove
+ * 7. createIndex
+ * + * @author liyuntao + */ +public class MongoDBCollectionImplInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.mongodb.DBCollectionImpl"; + + private static final String MONGDB_METHOD_INTERCET_CLASS = "MongoDBCollectionMethodInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return MONGDB_METHOD_INTERCET_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("find").and(takesArguments(9)); + } + + }, + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("insert").and(takesArguments(4)); + } + + }, + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("insertImpl"); + } + + }, + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("update"); + } + }, + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("updateImpl"); + } + + }, + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("remove").and(takesArguments(4)); + } + + }, + new InterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("createIndex"); + } + + }, + + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected String[] witnessClasses() { + /** + * @see {@link com.mongodb.tools.ConnectionPoolStat} + */ + return new String[] { + "com.mongodb.tools.ConnectionPoolStat" + }; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java similarity index 78% rename from apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java index f8d5b350f00d..be04464d7518 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java @@ -16,20 +16,38 @@ * */ -package org.skywalking.apm.plugin.mongodb.v2.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v2.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** * {@link MongoDBCollectionInstrumentation} define that the MongoDB Java Driver 2.13.x-2.14.x plugin intercepts the @@ -51,7 +69,7 @@ public class MongoDBCollectionInstrumentation extends ClassInstanceMethodsEnhanc private static final String ENHANCE_CLASS = "com.mongodb.DBCollection"; - private static final String MONGDB_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.mongodb.v2.MongoDBCollectionMethodInterceptor"; + private static final String MONGDB_METHOD_INTERCET_CLASS = "MongoDBCollectionMethodInterceptor"; @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java deleted file mode 100644 index a66646f42d96..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.mongodb.v2; - -import com.mongodb.AggregationOutput; -import com.mongodb.CommandResult; -import com.mongodb.DB; -import com.mongodb.ServerAddress; -import com.mongodb.WriteResult; -import java.lang.reflect.Method; -import java.util.List; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link MongoDBCollectionMethodInterceptor} intercepts constructor of {@link com.mongodb.DBCollection}or {@link - * com.mongodb.DBCollectionImpl} recording the ServerAddress and creating the exit span. - * - * @author liyuntao - */ - -public class MongoDBCollectionMethodInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { - - private static final String DB_TYPE = "MongoDB"; - - private static final String MONGO_DB_OP_PREFIX = "MongoDB/"; - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - String remotePeer = (String)objInst.getSkyWalkingDynamicField(); - String opertaion = method.getName(); - AbstractSpan span = ContextManager.createExitSpan(MONGO_DB_OP_PREFIX + opertaion, new ContextCarrier(), remotePeer); - span.setComponent(ComponentsDefine.MONGODB); - Tags.DB_TYPE.set(span, DB_TYPE); - SpanLayer.asDB(span); - - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - AbstractSpan activeSpan = ContextManager.activeSpan(); - CommandResult cresult = null; - if (ret instanceof WriteResult) { - WriteResult wresult = (WriteResult)ret; - cresult = wresult.getCachedLastError(); - } else if (ret instanceof AggregationOutput) { - AggregationOutput aresult = (AggregationOutput)ret; - cresult = aresult.getCommandResult(); - } - if (null != cresult && !cresult.ok()) { - activeSpan.log(cresult.getException()); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.errorOccurred(); - activeSpan.log(t); - } - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - List servers = null; - DB db = (DB)allArguments[0]; - servers = db.getMongo().getAllAddress(); - StringBuilder peers = new StringBuilder(); - for (ServerAddress address : servers) { - peers.append(address.getHost() + ":" + address.getPort() + ";"); - } - - objInst.setSkyWalkingDynamicField(peers.subSequence(0, peers.length() - 1).toString()); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java deleted file mode 100644 index 96880d348df1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.mongodb.v2.define; - -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; - -/** - * @auther liyuntao - */ -public abstract class InterceptPoint implements InstanceMethodsInterceptPoint { - private static final String MONGDB_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.mongodb.v2.MongoDBCollectionMethodInterceptor"; - - @Override - public String getMethodsInterceptor() { - return MONGDB_METHOD_INTERCET_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java deleted file mode 100644 index e81bd4e9f7de..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.mongodb.v2.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link MongoDBCollectionImplInstrumentation} define that the MongoDB Java Driver 2.13.x-2.14.x plugin intercepts the - * following methods in the {@link com.mongodb.DBCollectionImpl}class: - * 1. find
- * 2. insert
- * 3. insertImpl
- * 4. update
- * 5. updateImpl
- * 6. remove
- * 7. createIndex
- * - * @author liyuntao - */ -public class MongoDBCollectionImplInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.mongodb.DBCollectionImpl"; - - private static final String MONGDB_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.mongodb.v2.MongoDBCollectionMethodInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return MONGDB_METHOD_INTERCET_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("find").and(takesArguments(9)); - } - - }, - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("insert").and(takesArguments(4)); - } - - }, - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("insertImpl"); - } - - }, - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("update"); - } - }, - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("updateImpl"); - } - - }, - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("remove").and(takesArguments(4)); - } - - }, - new InterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("createIndex"); - } - - }, - - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected String[] witnessClasses() { - /** - * @see {@link com.mongodb.tools.ConnectionPoolStat} - */ - return new String[] { - "com.mongodb.tools.ConnectionPoolStat" - }; - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/resources/skywalking-plugin.def index fb8a07eabfe1..78ac4d5ee9b3 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -mongodb-2.x=org.skywalking.apm.plugin.mongodb.v2.define.MongoDBCollectionInstrumentation -mongodb-2.x=org.skywalking.apm.plugin.mongodb.v2.define.MongoDBCollectionImplInstrumentation +mongodb-2.x=MongoDBCollectionInstrumentation +mongodb-2.x=MongoDBCollectionImplInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java new file mode 100644 index 000000000000..c54b44dd5542 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v2; + +import com.mongodb.DBCollection; +import com.mongodb.DBObject; +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.hamcrest.CoreMatchers; +import org.hamcrest.MatcherAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MongoDBCollectionMethodInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private MongoDBCollectionMethodInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + private Object[] arguments = new Object[3]; + private Class[] argumentTypes; + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Before + public void setUp() throws Exception { + + interceptor = new MongoDBCollectionMethodInterceptor(); + + Config.Plugin.MongoDB.TRACE_PARAM = true; + + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); + + } + + @Test + public void testIntercept() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), null, null, null); + interceptor.afterMethod(enhancedInstance, getExecuteMethod(), null, null, null); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertMongoSpan(spans.get(0)); + } + + @Test + public void testInterceptWithException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), null, null, null); + interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), null, null, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, getExecuteMethod(), null, null, null); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertMongoSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertMongoSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("MongoDB/insert")); + assertThat(SpanHelper.getComponentId(span), is(9)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(0).getValue(), is("MongoDB")); + assertThat(span.isExit(), is(true)); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB)); + } + + private Method getExecuteMethod() { + try { + return DBCollection.class.getMethod("insert", DBObject[].class); + } catch (NoSuchMethodException e) { + return null; + } + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java deleted file mode 100644 index 2416ef9d513e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.mongodb.v2; - -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import java.lang.reflect.Method; -import java.util.List; -import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class MongoDBCollectionMethodInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private MongoDBCollectionMethodInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - private Object[] arguments = new Object[3]; - private Class[] argumentTypes; - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Before - public void setUp() throws Exception { - - interceptor = new MongoDBCollectionMethodInterceptor(); - - Config.Plugin.MongoDB.TRACE_PARAM = true; - - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); - - } - - @Test - public void testIntercept() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), null, null, null); - interceptor.afterMethod(enhancedInstance, getExecuteMethod(), null, null, null); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertMongoSpan(spans.get(0)); - } - - @Test - public void testInterceptWithException() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), null, null, null); - interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), null, null, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, getExecuteMethod(), null, null, null); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertMongoSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertMongoSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("MongoDB/insert")); - assertThat(SpanHelper.getComponentId(span), is(9)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("MongoDB")); - assertThat(span.isExit(), is(true)); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); - } - - private Method getExecuteMethod() { - try { - return DBCollection.class.getMethod("insert", DBObject[].class); - } catch (NoSuchMethodException e) { - return null; - } - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java similarity index 84% rename from apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java rename to apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java index 00a8ef47349c..dc5efc6b16ab 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.mongodb.v3; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v3; import com.mongodb.ReadPreference; import com.mongodb.ServerAddress; @@ -47,18 +65,18 @@ import com.mongodb.operation.WriteOperation; import java.lang.reflect.Method; import java.util.List; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.bson.BsonDocument; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; /** * {@link MongoDBMethodInterceptor} intercept method of {@link com.mongodb.Mongo#execute(ReadOperation, ReadPreference)} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java new file mode 100644 index 000000000000..ba708e683e0c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; + +public class MongoDBInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.mongodb.Mongo"; + + private static final String MONGDB_METHOD_INTERCET_CLASS = "MongoDBMethodInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, "com.mongodb.connection.Cluster"); + } + + @Override + public String getConstructorInterceptor() { + return MONGDB_METHOD_INTERCET_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override + public String getMethodsInterceptor() { + return MONGDB_METHOD_INTERCET_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java deleted file mode 100644 index ea536329f49f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/define/MongoDBInstrumentation.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.mongodb.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -public class MongoDBInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.mongodb.Mongo"; - - private static final String MONGDB_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.mongodb.v3.MongoDBMethodInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, "com.mongodb.connection.Cluster"); - } - - @Override - public String getConstructorInterceptor() { - return MONGDB_METHOD_INTERCET_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override - public String getMethodsInterceptor() { - return MONGDB_METHOD_INTERCET_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/resources/skywalking-plugin.def index cdb37e55841b..7631814411c8 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -mongodb-3.x=org.skywalking.apm.plugin.mongodb.v3.define.MongoDBInstrumentation \ No newline at end of file +mongodb-3.x=MongoDBInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java new file mode 100644 index 000000000000..7194c85ea572 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.mongodb.v3; + +import com.mongodb.Mongo; +import com.mongodb.MongoNamespace; +import com.mongodb.operation.FindOperation; +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.bson.BsonDocument; +import org.bson.BsonString; +import org.bson.codecs.Decoder; +import org.hamcrest.CoreMatchers; +import org.hamcrest.MatcherAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MongoDBMethodInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private MongoDBMethodInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + private Object[] arguments; + private Class[] argumentTypes; + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Before + public void setUp() throws Exception { + + interceptor = new MongoDBMethodInterceptor(); + + Config.Plugin.MongoDB.TRACE_PARAM = true; + + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); + + BsonDocument document = new BsonDocument(); + document.append("name", new BsonString("by")); + MongoNamespace mongoNamespace = new MongoNamespace("test.user"); + Decoder decoder = PowerMockito.mock(Decoder.class); + FindOperation findOperation = new FindOperation(mongoNamespace, decoder); + findOperation.filter(document); + + arguments = new Object[] {findOperation}; + argumentTypes = new Class[] {findOperation.getClass()}; + } + + @Test + public void testIntercept() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); + interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertRedisSpan(spans.get(0)); + } + + @Test + public void testInterceptWithException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); + interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertRedisSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertRedisSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("MongoDB/getUsedDatabases")); + assertThat(SpanHelper.getComponentId(span), is(9)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(1).getValue(), is("FindOperation { \"name\" : \"by\" }")); + assertThat(tags.get(0).getValue(), is("MongoDB")); + assertThat(span.isExit(), is(true)); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB)); + } + + private Method getExecuteMethod() { + try { + return Mongo.class.getMethod("getUsedDatabases"); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java deleted file mode 100644 index b74cd39b5570..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.mongodb.v3; - -import com.mongodb.Mongo; -import com.mongodb.MongoNamespace; -import com.mongodb.operation.FindOperation; -import java.lang.reflect.Method; -import java.util.List; -import org.bson.BsonDocument; -import org.bson.BsonString; -import org.bson.codecs.Decoder; -import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class MongoDBMethodInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private MongoDBMethodInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - private Object[] arguments; - private Class[] argumentTypes; - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Before - public void setUp() throws Exception { - - interceptor = new MongoDBMethodInterceptor(); - - Config.Plugin.MongoDB.TRACE_PARAM = true; - - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); - - BsonDocument document = new BsonDocument(); - document.append("name", new BsonString("by")); - MongoNamespace mongoNamespace = new MongoNamespace("test.user"); - Decoder decoder = PowerMockito.mock(Decoder.class); - FindOperation findOperation = new FindOperation(mongoNamespace, decoder); - findOperation.filter(document); - - arguments = new Object[] {findOperation}; - argumentTypes = new Class[] {findOperation.getClass()}; - } - - @Test - public void testIntercept() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); - interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertRedisSpan(spans.get(0)); - } - - @Test - public void testInterceptWithException() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); - interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertRedisSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertRedisSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("MongoDB/getUsedDatabases")); - assertThat(SpanHelper.getComponentId(span), is(9)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(1).getValue(), is("FindOperation { \"name\" : \"by\" }")); - assertThat(tags.get(0).getValue(), is("MongoDB")); - assertThat(span.isExit(), is(true)); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); - } - - private Method getExecuteMethod() { - try { - return Mongo.class.getMethod("getUsedDatabases"); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - return null; - } - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java new file mode 100644 index 000000000000..9480a3dcf628 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.motan; + +import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.Response; +import com.weibo.api.motan.rpc.URL; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link MotanProviderInterceptor} create span by fetch request url from + * {@link EnhancedInstance#getSkyWalkingDynamicField()} and transport serialized context + * data to provider side through {@link Request#setAttachment(String, String)}. + * + * @author zhangxin + */ +public class MotanConsumerInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + objInst.setSkyWalkingDynamicField(allArguments[1]); + } + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + URL url = (URL)objInst.getSkyWalkingDynamicField(); + Request request = (Request)allArguments[0]; + if (url != null) { + ContextCarrier contextCarrier = new ContextCarrier(); + String remotePeer = url.getHost() + ":" + url.getPort(); + AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer); + span.setComponent(ComponentsDefine.MOTAN); + Tags.URL.set(span, url.getIdentity()); + SpanLayer.asRPCFramework(span); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + request.setAttachment(next.getHeadKey(), next.getHeadValue()); + } + } + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Response response = (Response)ret; + if (response != null && response.getException() != null) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(response.getException()); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(t); + } + + /** + * Generate operation name. + * + * @return operation name. + */ + private static String generateOperationName(URL serviceURI, Request request) { + return new StringBuilder(serviceURI.getPath()).append(".").append(request.getMethodName()).append("(") + .append(request.getParamtersDesc()).append(")").toString(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptor.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptor.java new file mode 100644 index 000000000000..8bb7f9476ec1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptor.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.motan; + +import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.Response; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * Current trace segment will ref the trace segment if the serialized trace context that fetch from {@link + * Request#getAttachments()} is not null. + *

+ * {@link MotanConsumerInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for + * record the request url from consumer side. + * + * @author zhangxin + */ +public class MotanProviderInterceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + Request request = (Request)allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getAttachments().get(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(generateViewPoint(request), contextCarrier); + SpanLayer.asRPCFramework(span); + span.setComponent(ComponentsDefine.MOTAN); + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Response response = (Response)ret; + if (response != null && response.getException() != null) { + AbstractSpan span = ContextManager.activeSpan(); + span.log(response.getException()); + span.errorOccurred(); + } + + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + activeSpan.log(t); + } + + private static String generateViewPoint(Request request) { + StringBuilder viewPoint = new StringBuilder(request.getInterfaceName()); + viewPoint.append("." + request.getMethodName()); + viewPoint.append("(" + request.getParamtersDesc() + ")"); + return viewPoint.toString(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java new file mode 100644 index 000000000000..640b35ca345e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.motan.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.plugin.motan.MotanProviderInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link MotanConsumerInstrumentation} presents that skywalking intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(com.weibo.api.motan.rpc.Request)} + * by using {@link MotanProviderInterceptor}. + * + * @author zhangxin + */ +public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.weibo.api.motan.transport.ProviderMessageRouter"; + + private static final String INVOKE_INTERCEPT_CLASS = "MotanProviderInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("call"); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java new file mode 100644 index 000000000000..ecb6f82830f4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.motan.define; + +import com.weibo.api.motan.rpc.Request; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.motan.MotanConsumerInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link MotanProviderInstrumentation} presents that skywalking will use + * {@link MotanConsumerInterceptor} to intercept + * all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and + * {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. + * + * @author zhangxin + */ +public class MotanProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "com.weibo.api.motan.rpc.AbstractReferer"; + /** + * Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}. + */ + private static final String CONSTRUCTOR_INTERCEPT_CLASS = "MotanConsumerInterceptor"; + /** + * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. + */ + private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "MotanConsumerInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPT_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("call"); + } + + @Override + public String getMethodsInterceptor() { + return PROVIDER_INVOKE_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java deleted file mode 100644 index 53ed2c74dc73..000000000000 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.motan; - -import com.weibo.api.motan.rpc.Request; -import com.weibo.api.motan.rpc.Response; -import com.weibo.api.motan.rpc.URL; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link MotanProviderInterceptor} create span by fetch request url from - * {@link EnhancedInstance#getSkyWalkingDynamicField()} and transport serialized context - * data to provider side through {@link Request#setAttachment(String, String)}. - * - * @author zhangxin - */ -public class MotanConsumerInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - objInst.setSkyWalkingDynamicField(allArguments[1]); - } - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - URL url = (URL)objInst.getSkyWalkingDynamicField(); - Request request = (Request)allArguments[0]; - if (url != null) { - ContextCarrier contextCarrier = new ContextCarrier(); - String remotePeer = url.getHost() + ":" + url.getPort(); - AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer); - span.setComponent(ComponentsDefine.MOTAN); - Tags.URL.set(span, url.getIdentity()); - SpanLayer.asRPCFramework(span); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - request.setAttachment(next.getHeadKey(), next.getHeadValue()); - } - } - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Response response = (Response)ret; - if (response != null && response.getException() != null) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(response.getException()); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(t); - } - - /** - * Generate operation name. - * - * @return operation name. - */ - private static String generateOperationName(URL serviceURI, Request request) { - return new StringBuilder(serviceURI.getPath()).append(".").append(request.getMethodName()).append("(") - .append(request.getParamtersDesc()).append(")").toString(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptor.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptor.java deleted file mode 100644 index 064dad8a1fcc..000000000000 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptor.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.motan; - -import com.weibo.api.motan.rpc.Request; -import com.weibo.api.motan.rpc.Response; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * Current trace segment will ref the trace segment if the serialized trace context that fetch from {@link - * Request#getAttachments()} is not null. - *

- * {@link MotanConsumerInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for - * record the request url from consumer side. - * - * @author zhangxin - */ -public class MotanProviderInterceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - Request request = (Request)allArguments[0]; - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getAttachments().get(next.getHeadKey())); - } - - AbstractSpan span = ContextManager.createEntrySpan(generateViewPoint(request), contextCarrier); - SpanLayer.asRPCFramework(span); - span.setComponent(ComponentsDefine.MOTAN); - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Response response = (Response)ret; - if (response != null && response.getException() != null) { - AbstractSpan span = ContextManager.activeSpan(); - span.log(response.getException()); - span.errorOccurred(); - } - - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.errorOccurred(); - activeSpan.log(t); - } - - private static String generateViewPoint(Request request) { - StringBuilder viewPoint = new StringBuilder(request.getInterfaceName()); - viewPoint.append("." + request.getMethodName()); - viewPoint.append("(" + request.getParamtersDesc() + ")"); - return viewPoint.toString(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java deleted file mode 100644 index fb11c37be57d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.motan.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.motan.MotanProviderInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link MotanConsumerInstrumentation} presents that skywalking intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(com.weibo.api.motan.rpc.Request)} - * by using {@link MotanProviderInterceptor}. - * - * @author zhangxin - */ -public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.weibo.api.motan.transport.ProviderMessageRouter"; - - private static final String INVOKE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.motan.MotanProviderInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("call"); - } - - @Override - public String getMethodsInterceptor() { - return INVOKE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java deleted file mode 100644 index a1addf71ff30..000000000000 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/define/MotanProviderInstrumentation.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.motan.define; - -import com.weibo.api.motan.rpc.Request; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.motan.MotanConsumerInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link MotanProviderInstrumentation} presents that skywalking will use - * {@link MotanConsumerInterceptor} to intercept - * all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and - * {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. - * - * @author zhangxin - */ -public class MotanProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - /** - * Enhance class. - */ - private static final String ENHANCE_CLASS = "com.weibo.api.motan.rpc.AbstractReferer"; - /** - * Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}. - */ - private static final String CONSTRUCTOR_INTERCEPT_CLASS = "org.skywalking.apm.plugin.motan.MotanConsumerInterceptor"; - /** - * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. - */ - private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.motan.MotanConsumerInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_INTERCEPT_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("call"); - } - - @Override - public String getMethodsInterceptor() { - return PROVIDER_INVOKE_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def index b653df3bdbb0..512d40fb3a67 100644 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -motan-0.x=org.skywalking.apm.plugin.motan.define.MotanConsumerInstrumentation -motan-0.x=org.skywalking.apm.plugin.motan.define.MotanProviderInstrumentation \ No newline at end of file +motan-0.x=MotanConsumerInstrumentation +motan-0.x=MotanProviderInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java new file mode 100644 index 000000000000..99b52a4c1a5c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.motan; + +import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.Response; +import com.weibo.api.motan.rpc.URL; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.hamcrest.MatcherAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MotanConsumerInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private MotanConsumerInterceptor invokeInterceptor; + @Mock + private Response response; + @Mock + private Request request; + + private URL url; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() { + invokeInterceptor = new MotanConsumerInterceptor(); + url = URL.valueOf("motan://127.0.0.1:34000/org.apache.skywalking.apm.test.TestService"); + + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(url); + when(request.getMethodName()).thenReturn("test"); + when(request.getInterfaceName()).thenReturn("org.apache.skywalking.apm.test.TestService"); + when(request.getParamtersDesc()).thenReturn("java.lang.String, java.lang.Object"); + } + + @Test + public void testInvokeInterceptor() throws Throwable { + invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null); + invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertMotanConsumerSpan(spans.get(0)); + verify(request, times(1)).setAttachment(anyString(), anyString()); + } + + @Test + public void testResponseWithException() throws Throwable { + when(response.getException()).thenReturn(new RuntimeException()); + + invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null); + invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertTraceSegmentWhenOccurException(spans.get(0)); + } + + private void assertTraceSegmentWhenOccurException(AbstractTracingSpan tracingSpan) { + assertMotanConsumerSpan(tracingSpan); + verify(request, times(1)).setAttachment(anyString(), anyString()); + List logDataEntities = SpanHelper.getLogs(tracingSpan); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + @Test + public void testInvokeInterceptorWithException() throws Throwable { + + invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null); + invokeInterceptor.handleMethodException(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, new RuntimeException()); + invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertTraceSegmentWhenOccurException(spans.get(0)); + } + + private void assertMotanConsumerSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("org.apache.skywalking.apm.test.TestService.test(java.lang.String, java.lang.Object)")); + assertComponent(span, ComponentsDefine.MOTAN); + SpanAssert.assertLayer(span, SpanLayer.RPC_FRAMEWORK); + SpanAssert.assertTag(span, 0, "motan://127.0.0.1:34000/default_rpc/org.apache.skywalking.apm.test.TestService/1.0/service"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java new file mode 100644 index 000000000000..6e7dfdda11ba --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/apache/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.motan; + +import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.Response; +import com.weibo.api.motan.rpc.URL; +import java.util.HashMap; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.hamcrest.MatcherAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MotanProviderInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private MotanProviderInterceptor invokeInterceptor; + @Mock + private Response response; + @Mock + private Request request; + + private URL url; + + @Mock + private EnhancedInstance enhancedInstance; + + private Object[] arguments; + private Class[] argumentType; + + @Before + public void setUp() { + invokeInterceptor = new MotanProviderInterceptor(); + url = URL.valueOf("motan://127.0.0.1:34000/org.apache.skywalking.apm.test.TestService"); + + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(url); + arguments = new Object[] {request}; + argumentType = new Class[] {request.getClass()}; + when(request.getMethodName()).thenReturn("test"); + when(request.getInterfaceName()).thenReturn("org.apache.skywalking.apm.test.TestService"); + when(request.getParamtersDesc()).thenReturn("java.lang.String, java.lang.Object"); + } + + @Test + public void testInvokerWithoutRefSegment() throws Throwable { + invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); + invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertMotanProviderSpan(spans.get(0)); + assertTrue(traceSegment.getRefs() == null); + + } + + @Test + public void testInvokerWithRefSegment() throws Throwable { + HashMap attachments = new HashMap(); + attachments.put(SW3CarrierItem.HEADER_NAME, "1.123.456|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + when(request.getAttachments()).thenReturn(attachments); + + invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); + invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); + + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertMotanProviderSpan(spans.get(0)); + assertRefSegment(traceSegment.getRefs().get(0)); + } + + @Test + public void testResponseWithException() throws Throwable { + when(response.getException()).thenReturn(new RuntimeException()); + + invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); + invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); + + assertTraceSegmentWhenOccurException(); + } + + @Test + public void testOccurException() throws Throwable { + + invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); + invokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); + + assertTraceSegmentWhenOccurException(); + } + + private void assertTraceSegmentWhenOccurException() { + MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertMotanProviderSpan(spans.get(0)); + SpanAssert.assertLogSize(spans.get(0), 1); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertRefSegment(TraceSegmentRef primaryRef) { + assertThat(SegmentRefHelper.getTraceSegmentId(primaryRef).toString(), is("1.123.456")); + assertThat(SegmentRefHelper.getSpanId(primaryRef), is(3)); + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(primaryRef), is(1)); + assertThat(SegmentRefHelper.getPeerHost(primaryRef), is("192.168.1.8:18002")); + } + + private void assertMotanProviderSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("org.apache.skywalking.apm.test.TestService.test(java.lang.String, java.lang.Object)")); + assertComponent(span, ComponentsDefine.MOTAN); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.RPC_FRAMEWORK); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java deleted file mode 100644 index 8bcae77b5fd7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.motan; - -import com.weibo.api.motan.rpc.Request; -import com.weibo.api.motan.rpc.Response; -import com.weibo.api.motan.rpc.URL; -import java.util.List; -import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class MotanConsumerInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private MotanConsumerInterceptor invokeInterceptor; - @Mock - private Response response; - @Mock - private Request request; - - private URL url; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() { - invokeInterceptor = new MotanConsumerInterceptor(); - url = URL.valueOf("motan://127.0.0.1:34000/org.skywalking.apm.test.TestService"); - - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(url); - when(request.getMethodName()).thenReturn("test"); - when(request.getInterfaceName()).thenReturn("org.skywalking.apm.test.TestService"); - when(request.getParamtersDesc()).thenReturn("java.lang.String, java.lang.Object"); - } - - @Test - public void testInvokeInterceptor() throws Throwable { - invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null); - invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertMotanConsumerSpan(spans.get(0)); - verify(request, times(1)).setAttachment(anyString(), anyString()); - } - - @Test - public void testResponseWithException() throws Throwable { - when(response.getException()).thenReturn(new RuntimeException()); - - invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null); - invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertTraceSegmentWhenOccurException(spans.get(0)); - } - - private void assertTraceSegmentWhenOccurException(AbstractTracingSpan tracingSpan) { - assertMotanConsumerSpan(tracingSpan); - verify(request, times(1)).setAttachment(anyString(), anyString()); - List logDataEntities = SpanHelper.getLogs(tracingSpan); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - @Test - public void testInvokeInterceptorWithException() throws Throwable { - - invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null); - invokeInterceptor.handleMethodException(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, new RuntimeException()); - invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertTraceSegmentWhenOccurException(spans.get(0)); - } - - private void assertMotanConsumerSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("org.skywalking.apm.test.TestService.test(java.lang.String, java.lang.Object)")); - assertComponent(span, ComponentsDefine.MOTAN); - assertLayer(span, SpanLayer.RPC_FRAMEWORK); - assertTag(span, 0, "motan://127.0.0.1:34000/default_rpc/org.skywalking.apm.test.TestService/1.0/service"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java deleted file mode 100644 index 25848fd6783f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.motan; - -import com.weibo.api.motan.rpc.Request; -import com.weibo.api.motan.rpc.Response; -import com.weibo.api.motan.rpc.URL; -import java.util.HashMap; -import java.util.List; -import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLogSize; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class MotanProviderInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private MotanProviderInterceptor invokeInterceptor; - @Mock - private Response response; - @Mock - private Request request; - - private URL url; - - @Mock - private EnhancedInstance enhancedInstance; - - private Object[] arguments; - private Class[] argumentType; - - @Before - public void setUp() { - invokeInterceptor = new MotanProviderInterceptor(); - url = URL.valueOf("motan://127.0.0.1:34000/org.skywalking.apm.test.TestService"); - - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(url); - arguments = new Object[] {request}; - argumentType = new Class[] {request.getClass()}; - when(request.getMethodName()).thenReturn("test"); - when(request.getInterfaceName()).thenReturn("org.skywalking.apm.test.TestService"); - when(request.getParamtersDesc()).thenReturn("java.lang.String, java.lang.Object"); - } - - @Test - public void testInvokerWithoutRefSegment() throws Throwable { - invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); - invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertMotanProviderSpan(spans.get(0)); - assertTrue(traceSegment.getRefs() == null); - - } - - @Test - public void testInvokerWithRefSegment() throws Throwable { - HashMap attachments = new HashMap(); - attachments.put(SW3CarrierItem.HEADER_NAME, "1.123.456|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); - when(request.getAttachments()).thenReturn(attachments); - - invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); - invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); - - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertMotanProviderSpan(spans.get(0)); - assertRefSegment(traceSegment.getRefs().get(0)); - } - - @Test - public void testResponseWithException() throws Throwable { - when(response.getException()).thenReturn(new RuntimeException()); - - invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); - invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); - - assertTraceSegmentWhenOccurException(); - } - - @Test - public void testOccurException() throws Throwable { - - invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null); - invokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); - invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response); - - assertTraceSegmentWhenOccurException(); - } - - private void assertTraceSegmentWhenOccurException() { - MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertMotanProviderSpan(spans.get(0)); - assertLogSize(spans.get(0), 1); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertRefSegment(TraceSegmentRef primaryRef) { - assertThat(SegmentRefHelper.getTraceSegmentId(primaryRef).toString(), is("1.123.456")); - assertThat(SegmentRefHelper.getSpanId(primaryRef), is(3)); - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(primaryRef), is(1)); - assertThat(SegmentRefHelper.getPeerHost(primaryRef), is("192.168.1.8:18002")); - } - - private void assertMotanProviderSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("org.skywalking.apm.test.TestService.test(java.lang.String, java.lang.Object)")); - assertComponent(span, ComponentsDefine.MOTAN); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.RPC_FRAMEWORK); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java new file mode 100644 index 000000000000..945398ae3f3d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#createStatement()} method in + * the {@link com.mysql.jdbc.ConnectionImpl} class. + * + * @author zhangxin + */ +public class CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java new file mode 100644 index 000000000000..e94b42885f74 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#prepareStatement()} method in + * the {@link com.mysql.jdbc.ConnectionImpl} class. + * + * @author zhangxin + */ +public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java new file mode 100644 index 000000000000..cbc18306b0a1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#createStatement()} method in + * the {@link com.mysql.jdbc.ConnectionImpl} class. + * + * @author zhangxin + */ +public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "CallableStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java new file mode 100644 index 000000000000..3e2490c9aac4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link StatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor methods. + * + * @author zhangxin + */ +public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + /** + * To protected the code occur NullPointException. because mysql execute system sql when constructor method in + * {@link com.mysql.jdbc.ConnectionImpl} class executed. but the interceptor set the connection Info after + * the constructor method executed. + * + * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) + */ + if (connectInfo != null) { + + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + } + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java new file mode 100644 index 000000000000..e3eeb9872886 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; + +/** + * {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link + * com.mysql.jdbc.CallableStatement} by {@link org.apache.skywalking.apm.plugin.jdbc.mysql.CallableStatementInterceptor}: + * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * + * @author zhangxin + */ +public class CallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.mysql.jdbc.CallableStatement"; + private static final String SERVICE_METHOD_INTERCEPTOR = "StatementExecuteMethodsInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMatch(ENHANCE_CLASS, "com.mysql.jdbc.cj.CallableStatement"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java new file mode 100644 index 000000000000..dba99815d9aa --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.define.Constants; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@link ConnectionInstrumentation} intercepts the following methods that the class which extend {@link + * com.mysql.jdbc.ConnectionImpl}.
+ * + * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor + * 2. Enhance prepareCall by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor + * 3. Enhance createStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor + * 4. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * + * @author zhangxin + */ +public abstract class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return "CreatePreparedStatementInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_CALL_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return "CreateCallableStatementInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); + } + + @Override public String getMethodsInterceptor() { + return "CreateStatementInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.COMMIT_METHOD_NAME).or(named(Constants.ROLLBACK_METHOD_NAME)).or(named(Constants.CLOSE_METHOD_NAME)).or(named(Constants.RELEASE_SAVE_POINT_METHOD_NAME)); + } + + @Override public String getMethodsInterceptor() { + return Constants.SERVICE_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + + } + + @Override protected abstract ClassMatch enhanceClass(); +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java new file mode 100644 index 000000000000..e334fc3a9361 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; + +/** + * {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. + * + * @author zhangxin + */ +public class DriverInstrumentation extends AbstractDriverInstrumentation { + @Override + protected ClassMatch enhanceClass() { + return byMultiClassMatch("com.mysql.jdbc.Driver", "com.mysql.cj.jdbc.Driver"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java new file mode 100644 index 000000000000..a4fcb1d1879c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import java.util.Arrays; +import java.util.List; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * Match class with a given set of classes. + * + * @author zhangxin + */ +public class MultiClassNameMatch implements IndirectMatch { + + private List matchClassNames; + + private MultiClassNameMatch(String[] classNames) { + if (classNames == null || classNames.length == 0) { + throw new IllegalArgumentException("match class names is null"); + } + this.matchClassNames = Arrays.asList(classNames); + } + + @Override + public ElementMatcher.Junction buildJunction() { + ElementMatcher.Junction junction = null; + for (String name : matchClassNames) { + if (junction == null) { + junction = named(name); + } else { + junction = junction.or(named(name)); + } + } + return junction; + } + + @Override + public boolean isMatch(TypeDescription typeDescription) { + return matchClassNames.contains(typeDescription.getTypeName()); + } + + public static ClassMatch byMultiClassMatch(String... classNames) { + return new MultiClassNameMatch(classNames); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java new file mode 100644 index 000000000000..0c9e2ae7bd1f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link Mysql50ConnectionInstrumentation} interceptor the {@link com.mysql.jdbc.Connection} class in the 5.0.x verison + * of mysql driver jar. + * + * @author zhangxin + */ +public class Mysql50ConnectionInstrumentation extends ConnectionInstrumentation { + @Override + protected ClassMatch enhanceClass() { + return byName("com.mysql.jdbc.Connection"); + } + + @Override protected String[] witnessClasses() { + return new String[] {"com.mysql.jdbc.CursorRowProvider"}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java new file mode 100644 index 000000000000..3751ae7fdea4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; + +/** + * {@link Mysql5xConnectionInstrumentation } interceptor {@link com.mysql.cj.jdbc.ConnectionImpl} and + * com.mysql.jdbc.ConnectionImpl in mysql jdbc driver 5.1 and 5.1+ + * + * @author zhangxin + */ +public class Mysql5xConnectionInstrumentation extends ConnectionInstrumentation { + public static final String ENHANCE_CLASS = "com.mysql.jdbc.ConnectionImpl"; + + public static final String CJ_JDBC_ENHANCE_CLASS = "com.mysql.cj.jdbc.ConnectionImpl"; + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMatch(ENHANCE_CLASS, CJ_JDBC_ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java new file mode 100644 index 000000000000..0ee1c063cdc4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; + +/** + * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the + * {@link com.mysql.jdbc.JDBC42PreparedStatement}, {@link com.mysql.jdbc.PreparedStatement} and {@link + * com.mysql.cj.jdbc.PreparedStatement} class: + * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * 4. executeLargeUpdate
+ * 5. addBatch
+ * + * @author zhangxin + */ +public class PreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; + private static final String SERVICE_METHOD_INTERCEPTOR = "StatementExecuteMethodsInterceptor"; + public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + public static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; + + @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")) + .or(named("addBatch")); + } + + @Override public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, MYSQL6_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java new file mode 100644 index 000000000000..4fe9b0ad51db --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; + +/** + * {@link StatementInstrumentation} intercepts the following methods in the {@link + * com.mysql.jdbc.StatementImpl} and {@link com.mysql.cj.jdbc.StatementImpl}class. + * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * 4. executeLargeUpdate
+ * 5. addBatch
+ * 6. executeBatchInternal
+ * 7. executeUpdateInternal
+ * 8. executeQuery
+ * 9. executeBatch
+ * + * @author zhangxin + */ +public class StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String STATEMENT_CLASS_NAME = "com.mysql.jdbc.StatementImpl"; + private static final String SERVICE_METHOD_INTERCEPTOR = "StatementExecuteMethodsInterceptor"; + public static final String MYSQL6_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.StatementImpl"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")) + .or(named("addBatch")) + .or(named("executeBatchInternal")) + .or(named("executeUpdateInternal")) + .or(named("executeQuery")) + .or(named("executeBatch")); + } + + @Override public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMatch(STATEMENT_CLASS_NAME, MYSQL6_STATEMENT_CLASS_NAME); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java deleted file mode 100644 index 3e96278e82b7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#createStatement()} method in - * the {@link com.mysql.jdbc.ConnectionImpl} class. - * - * @author zhangxin - */ -public class CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (ret instanceof EnhancedInstance) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java deleted file mode 100644 index 953e5a1b9bf9..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#prepareStatement()} method in - * the {@link com.mysql.jdbc.ConnectionImpl} class. - * - * @author zhangxin - */ -public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (ret instanceof EnhancedInstance) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java deleted file mode 100644 index 023429fdeff2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#createStatement()} method in - * the {@link com.mysql.jdbc.ConnectionImpl} class. - * - * @author zhangxin - */ -public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (ret instanceof EnhancedInstance) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "CallableStatement")); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java deleted file mode 100644 index 816e02dc53f5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link StatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor methods. - * - * @author zhangxin - */ -public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); - /** - * To protected the code occur NullPointException. because mysql execute system sql when constructor method in - * {@link com.mysql.jdbc.ConnectionImpl} class executed. but the interceptor set the connection Info after - * the constructor method executed. - * - * @see org.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) - */ - if (connectInfo != null) { - - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, cacheObject.getSql()); - span.setComponent(connectInfo.getComponent()); - - SpanLayer.asDB(span); - } - } - - @Override - public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - Object ret) throws Throwable { - StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - if (cacheObject.getConnectionInfo() != null) { - ContextManager.stopSpan(); - } - return ret; - } - - @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - if (cacheObject.getConnectionInfo() != null) { - ContextManager.activeSpan().errorOccurred().log(t); - } - } - - private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { - return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java deleted file mode 100644 index 5a726a0e21a7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; - -/** - * {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link - * com.mysql.jdbc.CallableStatement} by {@link org.skywalking.apm.plugin.jdbc.mysql.CallableStatementInterceptor}: - * 1. execute
- * 2. executeQuery
- * 3. executeUpdate
- * - * @author zhangxin - */ -public class CallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "com.mysql.jdbc.CallableStatement"; - private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute") - .or(named("executeQuery")) - .or(named("executeUpdate")); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byMultiClassMatch(ENHANCE_CLASS, "com.mysql.jdbc.cj.CallableStatement"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java deleted file mode 100644 index 06d470e92b4a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; - -/** - * {@link ConnectionInstrumentation} intercepts the following methods that the class which extend {@link - * com.mysql.jdbc.ConnectionImpl}.
- * - * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareCall by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 3. Enhance createStatement by org.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 4. Enhance commit, rollback, close, releaseSavepoint by org.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor - * - * @author zhangxin - */ -public abstract class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.jdbc.mysql.CreatePreparedStatementInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_CALL_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.jdbc.mysql.CreateCallableStatementInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); - } - - @Override public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.jdbc.mysql.CreateStatementInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(COMMIT_METHOD_NAME).or(named(ROLLBACK_METHOD_NAME)).or(named(CLOSE_METHOD_NAME)).or(named(RELEASE_SAVE_POINT_METHOD_NAME)); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - - } - - @Override protected abstract ClassMatch enhanceClass(); -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java deleted file mode 100644 index 8d59c0b00d18..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; - -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; - -/** - * {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. - * - * @author zhangxin - */ -public class DriverInstrumentation extends AbstractDriverInstrumentation { - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch("com.mysql.jdbc.Driver", "com.mysql.cj.jdbc.Driver"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java deleted file mode 100644 index bad6f37db53b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import java.util.Arrays; -import java.util.List; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.plugin.match.IndirectMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -/** - * Match class with a given set of classes. - * - * @author zhangxin - */ -public class MultiClassNameMatch implements IndirectMatch { - - private List matchClassNames; - - private MultiClassNameMatch(String[] classNames) { - if (classNames == null || classNames.length == 0) { - throw new IllegalArgumentException("match class names is null"); - } - this.matchClassNames = Arrays.asList(classNames); - } - - @Override - public ElementMatcher.Junction buildJunction() { - ElementMatcher.Junction junction = null; - for (String name : matchClassNames) { - if (junction == null) { - junction = named(name); - } else { - junction = junction.or(named(name)); - } - } - return junction; - } - - @Override - public boolean isMatch(TypeDescription typeDescription) { - return matchClassNames.contains(typeDescription.getTypeName()); - } - - public static ClassMatch byMultiClassMatch(String... classNames) { - return new MultiClassNameMatch(classNames); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java deleted file mode 100644 index db835390a522..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql50ConnectionInstrumentation.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link Mysql50ConnectionInstrumentation} interceptor the {@link com.mysql.jdbc.Connection} class in the 5.0.x verison - * of mysql driver jar. - * - * @author zhangxin - */ -public class Mysql50ConnectionInstrumentation extends ConnectionInstrumentation { - @Override - protected ClassMatch enhanceClass() { - return byName("com.mysql.jdbc.Connection"); - } - - @Override protected String[] witnessClasses() { - return new String[] {"com.mysql.jdbc.CursorRowProvider"}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java deleted file mode 100644 index 06d672674480..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; - -/** - * {@link Mysql5xConnectionInstrumentation } interceptor {@link com.mysql.cj.jdbc.ConnectionImpl} and - * com.mysql.jdbc.ConnectionImpl in mysql jdbc driver 5.1 and 5.1+ - * - * @author zhangxin - */ -public class Mysql5xConnectionInstrumentation extends ConnectionInstrumentation { - public static final String ENHANCE_CLASS = "com.mysql.jdbc.ConnectionImpl"; - - public static final String CJ_JDBC_ENHANCE_CLASS = "com.mysql.cj.jdbc.ConnectionImpl"; - - @Override protected ClassMatch enhanceClass() { - return byMultiClassMatch(ENHANCE_CLASS, CJ_JDBC_ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java deleted file mode 100644 index 121e946c1435..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; - -/** - * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the - * {@link com.mysql.jdbc.JDBC42PreparedStatement}, {@link com.mysql.jdbc.PreparedStatement} and {@link - * com.mysql.cj.jdbc.PreparedStatement} class: - * 1. execute
- * 2. executeQuery
- * 3. executeUpdate
- * 4. executeLargeUpdate
- * 5. addBatch
- * - * @author zhangxin - */ -public class PreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; - private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; - public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; - public static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; - - @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute") - .or(named("executeQuery")) - .or(named("executeUpdate")) - .or(named("executeLargeUpdate")) - .or(named("addBatch")); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, MYSQL6_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java deleted file mode 100644 index 692099d190bf..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; - -/** - * {@link StatementInstrumentation} intercepts the following methods in the {@link - * com.mysql.jdbc.StatementImpl} and {@link com.mysql.cj.jdbc.StatementImpl}class. - * 1. execute
- * 2. executeQuery
- * 3. executeUpdate
- * 4. executeLargeUpdate
- * 5. addBatch
- * 6. executeBatchInternal
- * 7. executeUpdateInternal
- * 8. executeQuery
- * 9. executeBatch
- * - * @author zhangxin - */ -public class StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String STATEMENT_CLASS_NAME = "com.mysql.jdbc.StatementImpl"; - private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; - public static final String MYSQL6_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.StatementImpl"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute") - .or(named("executeQuery")) - .or(named("executeUpdate")) - .or(named("executeLargeUpdate")) - .or(named("addBatch")) - .or(named("executeBatchInternal")) - .or(named("executeUpdateInternal")) - .or(named("executeQuery")) - .or(named("executeBatch")); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byMultiClassMatch(STATEMENT_CLASS_NAME, MYSQL6_STATEMENT_CLASS_NAME); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def index 2902f6972ad7..cb330f316f7e 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,6 +1,6 @@ -mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.DriverInstrumentation -mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.Mysql5xConnectionInstrumentation -mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.Mysql50ConnectionInstrumentation -mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.CallableInstrumentation -mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.PreparedStatementInstrumentation -mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.StatementInstrumentation +mysql-5.x=DriverInstrumentation +mysql-5.x=Mysql5xConnectionInstrumentation +mysql-5.x=Mysql50ConnectionInstrumentation +mysql-5.x=CallableInstrumentation +mysql-5.x=PreparedStatementInstrumentation +mysql-5.x=StatementInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java new file mode 100644 index 000000000000..506f42b3b81a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CreateCallableStatementInterceptorTest { + + private CreateCallableStatementInterceptor interceptor; + + @Mock + private EnhancedInstance ret; + + @Mock + private EnhancedInstance objectInstance; + + @Mock + private ConnectionInfo connectionInfo; + + @Before + public void setUp() { + interceptor = new CreateCallableStatementInterceptor(); + + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); + verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); + verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java new file mode 100644 index 000000000000..6e1b9dc59a48 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CreatePreparedStatementInterceptorTest { + private CreatePreparedStatementInterceptor interceptor; + + @Mock + private EnhancedInstance ret; + + @Mock + private EnhancedInstance objectInstance; + + @Mock + private ConnectionInfo connectionInfo; + + @Before + public void setUp() { + interceptor = new CreatePreparedStatementInterceptor(); + + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); + verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); + verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java new file mode 100644 index 000000000000..55fd57db2e2e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CreateStatementInterceptorTest { + + private CreateStatementInterceptor interceptor; + + @Mock + private EnhancedInstance ret; + + @Mock + private EnhancedInstance objectInstance; + + @Mock + private ConnectionInfo connectionInfo; + + @Before + public void setUp() { + interceptor = new CreateStatementInterceptor(); + + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); + verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); + verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java new file mode 100644 index 000000000000..70a4a7960c5f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class StatementExecuteMethodsInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private StatementExecuteMethodsInterceptor serviceMethodInterceptor; + + @Mock + private ConnectionInfo connectionInfo; + @Mock + private EnhancedInstance objectInstance; + @Mock + private Method method; + private StatementEnhanceInfos enhanceRequireCacheObject; + + @Before + public void setUp() { + serviceMethodInterceptor = new StatementExecuteMethodsInterceptor(); + + enhanceRequireCacheObject = new StatementEnhanceInfos(connectionInfo, "SELECT * FROM test", "CallableStatement"); + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(enhanceRequireCacheObject); + when(method.getName()).thenReturn("executeQuery"); + when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.H2); + when(connectionInfo.getDBType()).thenReturn("H2"); + when(connectionInfo.getDatabaseName()).thenReturn("test"); + when(connectionInfo.getDatabasePeer()).thenReturn("localhost:3307"); + } + + @Test + public void testCreateDatabaseSpan() throws Throwable { + serviceMethodInterceptor.beforeMethod(objectInstance, method, null, null, null); + serviceMethodInterceptor.afterMethod(objectInstance, method, null, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment segment = segmentStorage.getTraceSegments().get(0); + assertThat(SegmentHelper.getSpans(segment).size(), is(1)); + AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0); + SpanAssert.assertLayer(span, SpanLayer.DB); + assertThat(span.getOperationName(), is("H2/JDBI/CallableStatement/")); + SpanAssert.assertTag(span, 0, "sql"); + SpanAssert.assertTag(span, 1, "test"); + SpanAssert.assertTag(span, 2, "SELECT * FROM test"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java deleted file mode 100644 index 937f32294dea..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class CreateCallableStatementInterceptorTest { - - private CreateCallableStatementInterceptor interceptor; - - @Mock - private EnhancedInstance ret; - - @Mock - private EnhancedInstance objectInstance; - - @Mock - private ConnectionInfo connectionInfo; - - @Before - public void setUp() { - interceptor = new CreateCallableStatementInterceptor(); - - when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); - } - - @Test - public void testResultIsEnhanceInstance() throws Throwable { - interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); - verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } - - @Test - public void testResultIsNotEnhanceInstance() throws Throwable { - interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); - verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java deleted file mode 100644 index 66af0b1d7d1e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class CreatePreparedStatementInterceptorTest { - private CreatePreparedStatementInterceptor interceptor; - - @Mock - private EnhancedInstance ret; - - @Mock - private EnhancedInstance objectInstance; - - @Mock - private ConnectionInfo connectionInfo; - - @Before - public void setUp() { - interceptor = new CreatePreparedStatementInterceptor(); - - when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); - } - - @Test - public void testResultIsEnhanceInstance() throws Throwable { - interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); - verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } - - @Test - public void testResultIsNotEnhanceInstance() throws Throwable { - interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); - verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java deleted file mode 100644 index 1835dba4f00f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class CreateStatementInterceptorTest { - - private CreateStatementInterceptor interceptor; - - @Mock - private EnhancedInstance ret; - - @Mock - private EnhancedInstance objectInstance; - - @Mock - private ConnectionInfo connectionInfo; - - @Before - public void setUp() { - interceptor = new CreateStatementInterceptor(); - - when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); - } - - @Test - public void testResultIsEnhanceInstance() throws Throwable { - interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); - verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } - - @Test - public void testResultIsNotEnhanceInstance() throws Throwable { - interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); - verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java deleted file mode 100644 index 471956c10ad2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.mysql; - -import java.lang.reflect.Method; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.SpanAssert; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class StatementExecuteMethodsInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private StatementExecuteMethodsInterceptor serviceMethodInterceptor; - - @Mock - private ConnectionInfo connectionInfo; - @Mock - private EnhancedInstance objectInstance; - @Mock - private Method method; - private StatementEnhanceInfos enhanceRequireCacheObject; - - @Before - public void setUp() { - serviceMethodInterceptor = new StatementExecuteMethodsInterceptor(); - - enhanceRequireCacheObject = new StatementEnhanceInfos(connectionInfo, "SELECT * FROM test", "CallableStatement"); - when(objectInstance.getSkyWalkingDynamicField()).thenReturn(enhanceRequireCacheObject); - when(method.getName()).thenReturn("executeQuery"); - when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.H2); - when(connectionInfo.getDBType()).thenReturn("H2"); - when(connectionInfo.getDatabaseName()).thenReturn("test"); - when(connectionInfo.getDatabasePeer()).thenReturn("localhost:3307"); - } - - @Test - public void testCreateDatabaseSpan() throws Throwable { - serviceMethodInterceptor.beforeMethod(objectInstance, method, null, null, null); - serviceMethodInterceptor.afterMethod(objectInstance, method, null, null, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment segment = segmentStorage.getTraceSegments().get(0); - assertThat(SegmentHelper.getSpans(segment).size(), is(1)); - AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0); - SpanAssert.assertLayer(span, SpanLayer.DB); - assertThat(span.getOperationName(), is("H2/JDBI/CallableStatement/")); - SpanAssert.assertTag(span, 0, "sql"); - SpanAssert.assertTag(span, 1, "test"); - SpanAssert.assertTag(span, 2, "SELECT * FROM test"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java new file mode 100644 index 000000000000..fb1c3212bc16 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class SenderConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(final EnhancedInstance objInst, final Object[] allArguments) { + objInst.setSkyWalkingDynamicField(allArguments[0]); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java new file mode 100644 index 000000000000..cb8c1b573a42 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync; + +import java.lang.reflect.Method; +import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.nutz.http.Request; +import org.nutz.http.Request.METHOD; +import org.nutz.http.Response; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SenderSendInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, + final Class[] argumentsTypes, + final MethodInterceptResult result) throws Throwable { + Request req = (Request)objInst.getSkyWalkingDynamicField(); + final URI requestURL = req.getUrl().toURI(); + final METHOD httpMethod = req.getMethod(); + final ContextCarrier contextCarrier = new ContextCarrier(); + String remotePeer = requestURL.getHost() + ":" + requestURL.getPort(); + AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer); + + span.setComponent(ComponentsDefine.NUTZ_HTTP); + Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath()); + Tags.HTTP.METHOD.set(span, httpMethod.toString()); + SpanLayer.asHttp(span); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + req.getHeader().set(next.getHeadKey(), next.getHeadValue()); + } + } + + @Override + public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, + final Class[] argumentsTypes, + Object ret) throws Throwable { + Response response = (Response)ret; + int statusCode = response.getStatus(); + AbstractSpan span = ContextManager.activeSpan(); + if (statusCode >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); + } + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments, + final Class[] argumentsTypes, final Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java new file mode 100644 index 000000000000..195949f1456e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import net.bytebuddy.matcher.ElementMatchers; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +public abstract class AbstractNutzHttpInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String DO_SEND_METHOD_NAME = "send"; + private static final String DO_SEND_INTERCEPTOR = "SenderSendInterceptor"; + private static final String DO_CONSTRUCTOR_INTERCEPTOR = "SenderConstructorInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return ElementMatchers.takesArguments(1); + } + + @Override + public String getConstructorInterceptor() { + return DO_CONSTRUCTOR_INTERCEPTOR; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(DO_SEND_METHOD_NAME); + } + + @Override + public String getMethodsInterceptor() { + return DO_SEND_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + protected abstract ClassMatch enhanceClass(); +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java new file mode 100644 index 000000000000..aea077a22a5b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +public class NutzHttpFilePostSenderInstrumentation extends AbstractNutzHttpInstrumentation { + + protected ClassMatch enhanceClass() { + return NameMatch.byName("org.nutz.http.sender.FilePostSender"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java new file mode 100644 index 000000000000..521af57bf2b3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +public class NutzHttpGetSenderInstrumentation extends AbstractNutzHttpInstrumentation { + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName("org.nutz.http.sender.GetSender"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java new file mode 100644 index 000000000000..20b01440a833 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +public class NutzHttpPostSenderInstrumentation extends AbstractNutzHttpInstrumentation { + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName("org.nutz.http.sender.PostSender"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java deleted file mode 100644 index 153d45e88128..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class SenderConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(final EnhancedInstance objInst, final Object[] allArguments) { - objInst.setSkyWalkingDynamicField(allArguments[0]); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java deleted file mode 100644 index faeb9d5028f3..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync; - -import java.lang.reflect.Method; -import java.net.URI; -import org.nutz.http.Request; -import org.nutz.http.Request.METHOD; -import org.nutz.http.Response; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class SenderSendInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, - final Class[] argumentsTypes, - final MethodInterceptResult result) throws Throwable { - Request req = (Request)objInst.getSkyWalkingDynamicField(); - final URI requestURL = req.getUrl().toURI(); - final METHOD httpMethod = req.getMethod(); - final ContextCarrier contextCarrier = new ContextCarrier(); - String remotePeer = requestURL.getHost() + ":" + requestURL.getPort(); - AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer); - - span.setComponent(ComponentsDefine.NUTZ_HTTP); - Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath()); - Tags.HTTP.METHOD.set(span, httpMethod.toString()); - SpanLayer.asHttp(span); - - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - req.getHeader().set(next.getHeadKey(), next.getHeadValue()); - } - } - - @Override - public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, - final Class[] argumentsTypes, - Object ret) throws Throwable { - Response response = (Response)ret; - int statusCode = response.getStatus(); - AbstractSpan span = ContextManager.activeSpan(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); - } - ContextManager.stopSpan(); - return ret; - } - - @Override - public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments, - final Class[] argumentsTypes, final Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java deleted file mode 100644 index 31860f99b5d5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import net.bytebuddy.matcher.ElementMatchers; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public abstract class AbstractNutzHttpInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String DO_SEND_METHOD_NAME = "send"; - private static final String DO_SEND_INTERCEPTOR = "org.skywalking.apm.plugin.nutz.http.sync.SenderSendInterceptor"; - private static final String DO_CONSTRUCTOR_INTERCEPTOR = "org.skywalking.apm.plugin.nutz.http.sync.SenderConstructorInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return ElementMatchers.takesArguments(1); - } - - @Override - public String getConstructorInterceptor() { - return DO_CONSTRUCTOR_INTERCEPTOR; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(DO_SEND_METHOD_NAME); - } - - @Override - public String getMethodsInterceptor() { - return DO_SEND_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - protected abstract ClassMatch enhanceClass(); -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java deleted file mode 100644 index ef2ed6d0c98a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.plugin.match.NameMatch; - -public class NutzHttpFilePostSenderInstrumentation extends AbstractNutzHttpInstrumentation { - - protected ClassMatch enhanceClass() { - return NameMatch.byName("org.nutz.http.sender.FilePostSender"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java deleted file mode 100644 index ed2605e1dc84..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.plugin.match.NameMatch; - -public class NutzHttpGetSenderInstrumentation extends AbstractNutzHttpInstrumentation { - - @Override - protected ClassMatch enhanceClass() { - return NameMatch.byName("org.nutz.http.sender.GetSender"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java deleted file mode 100644 index baf850e15d8d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.plugin.match.NameMatch; - -public class NutzHttpPostSenderInstrumentation extends AbstractNutzHttpInstrumentation { - - @Override - protected ClassMatch enhanceClass() { - return NameMatch.byName("org.nutz.http.sender.PostSender"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/resources/skywalking-plugin.def index 203a31f4d737..25e732f61078 100644 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,3 +1,3 @@ -nutz-http-1.x=org.skywalking.apm.plugin.nutz.http.sync.define.NutzHttpGetSenderInstrumentation -nutz-http-1.x=org.skywalking.apm.plugin.nutz.http.sync.define.NutzHttpPostSenderInstrumentation -nutz-http-1.x=org.skywalking.apm.plugin.nutz.http.sync.define.NutzHttpFilePostSenderInstrumentation +nutz-http-1.x=NutzHttpGetSenderInstrumentation +nutz-http-1.x=NutzHttpPostSenderInstrumentation +nutz-http-1.x=NutzHttpFilePostSenderInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java new file mode 100644 index 000000000000..ffc5eae91bd6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.http.sync; + +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.nutz.http.Request; +import org.nutz.http.Request.METHOD; +import org.nutz.http.Response; +import org.nutz.http.Sender; +import org.nutz.http.sender.FilePostSender; +import org.nutz.http.sender.GetSender; +import org.nutz.http.sender.PostSender; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(org.powermock.modules.junit4.PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class SenderInterceptorTest { + + @SegmentStoragePoint + public SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private EnhancedInstance enhancedInstance; + + @Mock + Response resp; + + SenderConstructorInterceptor constructorInterceptPoint; + + SenderSendInterceptor senderSendInterceptor; + + Method sendMethod; + Object[] allArguments; + Class[] argumentsTypes; + + @Before + public void setUp() throws Exception { + ServiceManager.INSTANCE.boot(); + constructorInterceptPoint = new SenderConstructorInterceptor(); + senderSendInterceptor = new SenderSendInterceptor(); + } + + public void setupSender(Class klass) throws NoSuchMethodException, SecurityException { + sendMethod = klass.getMethod("send"); + allArguments = new Object[0]; + argumentsTypes = new Class[0]; + } + + @Test + public void test_constructor() { + Request request = Request.create("https://nutz.cn/yvr/list", METHOD.GET); + constructorInterceptPoint.onConstruct(enhancedInstance, new Object[] {request}); + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(request); + } + + @Test + public void test_getsender_send() throws NoSuchMethodException, SecurityException, Throwable { + setupSender(GetSender.class); + _sender_sender_test(); + } + + @Test + public void test_postsender_send() throws NoSuchMethodException, SecurityException, Throwable { + setupSender(PostSender.class); + _sender_sender_test(); + } + + @Test + public void test_filepostsender_send() throws NoSuchMethodException, SecurityException, Throwable { + setupSender(FilePostSender.class); + _sender_sender_test(); + } + + protected void _sender_sender_test() throws Throwable { + Request request = Request.create("https://nutz.cn/yvr/list", METHOD.GET); + constructorInterceptPoint.onConstruct(enhancedInstance, new Object[] {request}); + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(request); + + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(request); + when(resp.getStatus()).thenReturn(200); + + senderSendInterceptor.beforeMethod(enhancedInstance, sendMethod, allArguments, argumentsTypes, null); + senderSendInterceptor.afterMethod(enhancedInstance, sendMethod, allArguments, argumentsTypes, resp); + + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + assertThat(spans.get(0).getOperationName(), is("/yvr/list")); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java deleted file mode 100644 index adbbb2a56842..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.http.sync; - -import java.lang.reflect.Method; -import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.nutz.http.Request; -import org.nutz.http.Request.METHOD; -import org.nutz.http.Response; -import org.nutz.http.Sender; -import org.nutz.http.sender.FilePostSender; -import org.nutz.http.sender.GetSender; -import org.nutz.http.sender.PostSender; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(org.powermock.modules.junit4.PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class SenderInterceptorTest { - - @SegmentStoragePoint - public SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private EnhancedInstance enhancedInstance; - - @Mock - Response resp; - - SenderConstructorInterceptor constructorInterceptPoint; - - SenderSendInterceptor senderSendInterceptor; - - Method sendMethod; - Object[] allArguments; - Class[] argumentsTypes; - - @Before - public void setUp() throws Exception { - ServiceManager.INSTANCE.boot(); - constructorInterceptPoint = new SenderConstructorInterceptor(); - senderSendInterceptor = new SenderSendInterceptor(); - } - - public void setupSender(Class klass) throws NoSuchMethodException, SecurityException { - sendMethod = klass.getMethod("send"); - allArguments = new Object[0]; - argumentsTypes = new Class[0]; - } - - @Test - public void test_constructor() { - Request request = Request.create("https://nutz.cn/yvr/list", METHOD.GET); - constructorInterceptPoint.onConstruct(enhancedInstance, new Object[] {request}); - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(request); - } - - @Test - public void test_getsender_send() throws NoSuchMethodException, SecurityException, Throwable { - setupSender(GetSender.class); - _sender_sender_test(); - } - - @Test - public void test_postsender_send() throws NoSuchMethodException, SecurityException, Throwable { - setupSender(PostSender.class); - _sender_sender_test(); - } - - @Test - public void test_filepostsender_send() throws NoSuchMethodException, SecurityException, Throwable { - setupSender(FilePostSender.class); - _sender_sender_test(); - } - - protected void _sender_sender_test() throws Throwable { - Request request = Request.create("https://nutz.cn/yvr/list", METHOD.GET); - constructorInterceptPoint.onConstruct(enhancedInstance, new Object[] {request}); - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(request); - - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(request); - when(resp.getStatus()).thenReturn(200); - - senderSendInterceptor.beforeMethod(enhancedInstance, sendMethod, allArguments, argumentsTypes, null); - senderSendInterceptor.afterMethod(enhancedInstance, sendMethod, allArguments, argumentsTypes, resp); - - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - assertThat(spans.get(0).getOperationName(), is("/yvr/list")); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java new file mode 100644 index 000000000000..b7628c52b52f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.mvc; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.nutz.mvc.annotation.At; + +/** + * @author wendal + */ +public class ActionConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String basePath = ""; + At basePathRequestMapping = objInst.getClass().getAnnotation(At.class); + if (basePathRequestMapping != null) { + basePath = basePathRequestMapping.value()[0]; + } + PathMappingCache pathMappingCache = new PathMappingCache(basePath); + objInst.setSkyWalkingDynamicField(pathMappingCache); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java new file mode 100644 index 000000000000..f588ac55ea2d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.mvc; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.nutz.mvc.Mvcs; +import org.nutz.mvc.annotation.At; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * The ActionMethodInterceptor only use the first mapping value. + * + * @author wendal + */ +public class ActionMethodInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + PathMappingCache pathMappingCache = (PathMappingCache)objInst.getSkyWalkingDynamicField(); + String requestURL = pathMappingCache.findPathMapping(method); + if (requestURL == null) { + At methodRequestMapping = method.getAnnotation(At.class); + if (methodRequestMapping.value().length > 0) { + requestURL = methodRequestMapping.value()[0]; + } else { + requestURL = ""; + } + pathMappingCache.addPathMapping(method, requestURL); + requestURL = pathMappingCache.findPathMapping(method); + } + + HttpServletRequest request = Mvcs.getReq(); + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHeader(next.getHeadKey())); + } + AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); + Tags.URL.set(span, request.getRequestURL().toString()); + Tags.HTTP.METHOD.set(span, request.getMethod()); + span.setComponent(ComponentsDefine.NUTZ_MVC_ANNOTATION); + SpanLayer.asHttp(span); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + HttpServletResponse response = Mvcs.getResp(); + + AbstractSpan span = ContextManager.activeSpan(); + if (response.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java new file mode 100644 index 000000000000..31f8a58065d0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.mvc; + +import java.lang.reflect.Method; +import java.util.concurrent.ConcurrentHashMap; + +/** + * The PathMappingCache represents a mapping cache. + * key: {@link Method} + * value: the url pattern + * + * @author wendal + */ +public class PathMappingCache { + private String classPath = ""; + + private ConcurrentHashMap methodPathMapping = new ConcurrentHashMap(); + + public PathMappingCache(String classPath) { + this.classPath = classPath; + } + + public String findPathMapping(Method method) { + return methodPathMapping.get(method); + } + + public void addPathMapping(Method method, String methodPath) { + methodPathMapping.put(method, classPath + methodPath); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java new file mode 100644 index 000000000000..e38e13996521 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.nutz.mvc.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class ActionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_ANNOTATION = "org.nutz.mvc.annotation.At"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return "ActionConstructorInterceptor"; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return isAnnotatedWith(named("org.nutz.mvc.annotation.At")); + } + + @Override + public String getMethodsInterceptor() { + return "ActionMethodInterceptor"; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return ClassAnnotationMatch.byClassAnnotationMatch(getEnhanceAnnotations()); + } + + protected String[] getEnhanceAnnotations() { + return new String[] {ENHANCE_ANNOTATION}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java deleted file mode 100644 index 311054c0c407..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.mvc; - -import org.nutz.mvc.annotation.At; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * @author wendal - */ -public class ActionConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String basePath = ""; - At basePathRequestMapping = objInst.getClass().getAnnotation(At.class); - if (basePathRequestMapping != null) { - basePath = basePathRequestMapping.value()[0]; - } - PathMappingCache pathMappingCache = new PathMappingCache(basePath); - objInst.setSkyWalkingDynamicField(pathMappingCache); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java deleted file mode 100644 index 223af3ca39e4..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.mvc; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.nutz.mvc.Mvcs; -import org.nutz.mvc.annotation.At; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * The ActionMethodInterceptor only use the first mapping value. - * - * @author wendal - */ -public class ActionMethodInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - PathMappingCache pathMappingCache = (PathMappingCache)objInst.getSkyWalkingDynamicField(); - String requestURL = pathMappingCache.findPathMapping(method); - if (requestURL == null) { - At methodRequestMapping = method.getAnnotation(At.class); - if (methodRequestMapping.value().length > 0) { - requestURL = methodRequestMapping.value()[0]; - } else { - requestURL = ""; - } - pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); - } - - HttpServletRequest request = Mvcs.getReq(); - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHeader(next.getHeadKey())); - } - AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); - Tags.URL.set(span, request.getRequestURL().toString()); - Tags.HTTP.METHOD.set(span, request.getMethod()); - span.setComponent(ComponentsDefine.NUTZ_MVC_ANNOTATION); - SpanLayer.asHttp(span); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - HttpServletResponse response = Mvcs.getResp(); - - AbstractSpan span = ContextManager.activeSpan(); - if (response.getStatus() >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java deleted file mode 100644 index 11e0be9defc5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.mvc; - -import java.lang.reflect.Method; -import java.util.concurrent.ConcurrentHashMap; - -/** - * The PathMappingCache represents a mapping cache. - * key: {@link Method} - * value: the url pattern - * - * @author wendal - */ -public class PathMappingCache { - private String classPath = ""; - - private ConcurrentHashMap methodPathMapping = new ConcurrentHashMap(); - - public PathMappingCache(String classPath) { - this.classPath = classPath; - } - - public String findPathMapping(Method method) { - return methodPathMapping.get(method); - } - - public void addPathMapping(Method method, String methodPath) { - methodPathMapping.put(method, classPath + methodPath); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java deleted file mode 100644 index c45896b98954..000000000000 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.nutz.mvc.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; - -public class ActionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String ENHANCE_ANNOTATION = "org.nutz.mvc.annotation.At"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return "org.skywalking.apm.plugin.nutz.mvc.ActionConstructorInterceptor"; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return isAnnotatedWith(named("org.nutz.mvc.annotation.At")); - } - - @Override - public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.nutz.mvc.ActionMethodInterceptor"; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(getEnhanceAnnotations()); - } - - protected String[] getEnhanceAnnotations() { - return new String[] {ENHANCE_ANNOTATION}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/resources/skywalking-plugin.def index c6566dcf3f13..d10d3982c2b4 100644 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -nutz-mvc-annotation-1.x=org.skywalking.apm.plugin.nutz.mvc.define.ActionInstrumentation \ No newline at end of file +nutz-mvc-annotation-1.x=ActionInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java new file mode 100644 index 000000000000..d7b908d45e95 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.okhttp.v3; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link RealCallInterceptor} intercept the synchronous http calls by the discovery of okhttp. + * + * @author peng-yongsheng + */ +public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { + + /** + * Intercept the {@link okhttp3.RealCall#RealCall(OkHttpClient, Request, boolean)}, then put the second argument of + * {@link okhttp3.Request} into {@link EnhancedInstance}. + * + * @param objInst a new added instance field + * @param allArguments constructor invocation context. + */ + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + objInst.setSkyWalkingDynamicField(allArguments[1]); + } + + /** + * Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host, + * port, kind, component, url from {@link okhttp3.Request}. + * Through the reflection of the way, set the http header of context data into {@link okhttp3.Request#headers}. + * + * @param method + * @param result change this result, if you want to truncate the method. + * @throws Throwable + */ + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + Request request = (Request)objInst.getSkyWalkingDynamicField(); + + ContextCarrier contextCarrier = new ContextCarrier(); + HttpUrl requestUrl = request.url(); + AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri().getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl.port()); + span.setComponent(ComponentsDefine.OKHTTP); + Tags.HTTP.METHOD.set(span, request.method()); + Tags.URL.set(span, requestUrl.uri().toString()); + SpanLayer.asHttp(span); + + Field headersField = Request.class.getDeclaredField("headers"); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL); + + headersField.setAccessible(true); + Headers.Builder headerBuilder = request.headers().newBuilder(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + headerBuilder.add(next.getHeadKey(), next.getHeadValue()); + } + headersField.set(request, headerBuilder.build()); + } + + /** + * Get the status code from {@link Response}, when status code greater than 400, it means there was some errors in + * the server. + * Finish the {@link AbstractSpan}. + * + * @param method + * @param ret the method's original return value. + * @return + * @throws Throwable + */ + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Response response = (Response)ret; + int statusCode = response.code(); + + AbstractSpan span = ContextManager.activeSpan(); + if (statusCode >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); + } + + ContextManager.stopSpan(); + + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan abstractSpan = ContextManager.activeSpan(); + abstractSpan.errorOccurred(); + abstractSpan.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java new file mode 100644 index 000000000000..82c33c56ff08 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.okhttp.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.okhttp.v3.RealCallInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@link RealCallInstrumentation} presents that skywalking intercepts {@link okhttp3.RealCall#RealCall(OkHttpClient, + * Request, boolean)}, {@link okhttp3.RealCall#execute()} by using {@link RealCallInterceptor}. + * + * @author peng-yongsheng + */ +public class RealCallInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "okhttp3.RealCall"; + + /** + * Intercept class. + */ + private static final String INTERCEPT_CLASS = "RealCallInterceptor"; + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return takesArguments(OkHttpClient.class, Request.class, boolean.class); + } + + @Override public String getConstructorInterceptor() { + return INTERCEPT_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java deleted file mode 100644 index d667a85be948..000000000000 --- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.okhttp.v3; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import okhttp3.Headers; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link RealCallInterceptor} intercept the synchronous http calls by the discovery of okhttp. - * - * @author peng-yongsheng - */ -public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { - - /** - * Intercept the {@link okhttp3.RealCall#RealCall(OkHttpClient, Request, boolean)}, then put the second argument of - * {@link okhttp3.Request} into {@link EnhancedInstance}. - * - * @param objInst a new added instance field - * @param allArguments constructor invocation context. - */ - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - objInst.setSkyWalkingDynamicField(allArguments[1]); - } - - /** - * Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host, - * port, kind, component, url from {@link okhttp3.Request}. - * Through the reflection of the way, set the http header of context data into {@link okhttp3.Request#headers}. - * - * @param method - * @param result change this result, if you want to truncate the method. - * @throws Throwable - */ - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - Request request = (Request)objInst.getSkyWalkingDynamicField(); - - ContextCarrier contextCarrier = new ContextCarrier(); - HttpUrl requestUrl = request.url(); - AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri().getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl.port()); - span.setComponent(ComponentsDefine.OKHTTP); - Tags.HTTP.METHOD.set(span, request.method()); - Tags.URL.set(span, requestUrl.uri().toString()); - SpanLayer.asHttp(span); - - Field headersField = Request.class.getDeclaredField("headers"); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL); - - headersField.setAccessible(true); - Headers.Builder headerBuilder = request.headers().newBuilder(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - headerBuilder.add(next.getHeadKey(), next.getHeadValue()); - } - headersField.set(request, headerBuilder.build()); - } - - /** - * Get the status code from {@link Response}, when status code greater than 400, it means there was some errors in - * the server. - * Finish the {@link AbstractSpan}. - * - * @param method - * @param ret the method's original return value. - * @return - * @throws Throwable - */ - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Response response = (Response)ret; - int statusCode = response.code(); - - AbstractSpan span = ContextManager.activeSpan(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); - } - - ContextManager.stopSpan(); - - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan abstractSpan = ContextManager.activeSpan(); - abstractSpan.errorOccurred(); - abstractSpan.log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java deleted file mode 100644 index fa01c7822e0e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.okhttp.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.okhttp.v3.RealCallInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link RealCallInstrumentation} presents that skywalking intercepts {@link okhttp3.RealCall#RealCall(OkHttpClient, - * Request, boolean)}, {@link okhttp3.RealCall#execute()} by using {@link RealCallInterceptor}. - * - * @author peng-yongsheng - */ -public class RealCallInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - /** - * Enhance class. - */ - private static final String ENHANCE_CLASS = "okhttp3.RealCall"; - - /** - * Intercept class. - */ - private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.okhttp.v3.RealCallInterceptor"; - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return takesArguments(OkHttpClient.class, Request.class, boolean.class); - } - - @Override public String getConstructorInterceptor() { - return INTERCEPT_CLASS; - } - } - }; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/resources/skywalking-plugin.def index 8ee8f54ce5c5..9252ee2ceb95 100644 --- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -okhttp-3.x=org.skywalking.apm.plugin.okhttp.v3.define.RealCallInstrumentation \ No newline at end of file +okhttp-3.x=RealCallInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java new file mode 100644 index 000000000000..f343c7967a2c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.okhttp.v3; + +import java.util.List; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +/** + * @author peng-yongsheng + */ +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@PrepareForTest({Response.class}) +public class RealCallInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private RealCallInterceptor realCallInterceptor; + + @Mock + private OkHttpClient client; + + private Request request; + + private Object[] allArguments; + private Class[] argumentTypes; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + + private Object object; + + @Override + public Object getSkyWalkingDynamicField() { + return object; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.object = value; + } + }; + + @Before + public void setUp() throws Exception { + request = new Request.Builder().url("http://skywalking.org").build(); + allArguments = new Object[] {client, request, false}; + argumentTypes = new Class[] {client.getClass(), request.getClass(), Boolean.class}; + realCallInterceptor = new RealCallInterceptor(); + } + + @Test + public void testOnConstruct() { + realCallInterceptor.onConstruct(enhancedInstance, allArguments); + assertThat(enhancedInstance.getSkyWalkingDynamicField(), is(allArguments[1])); + } + + @Test + public void testMethodsAround() throws Throwable { + realCallInterceptor.onConstruct(enhancedInstance, allArguments); + realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + Response response = mock(Response.class); + when(response.code()).thenReturn(200); + realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertSpan(spans.get(0)); + SpanAssert.assertOccurException(spans.get(0), false); + } + + @Test + public void testMethodsAroundError() throws Throwable { + realCallInterceptor.onConstruct(enhancedInstance, allArguments); + realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + Response response = mock(Response.class); + when(response.code()).thenReturn(404); + realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertSpan(spans.get(0)); + SpanAssert.assertOccurException(spans.get(0), true); + } + + private void assertSpan(AbstractTracingSpan span) { + assertComponent(span, ComponentsDefine.OKHTTP); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + SpanAssert.assertTag(span, 0, "GET"); + SpanAssert.assertTag(span, 1, "http://skywalking.org/"); + assertThat(span.isExit(), is(true)); + assertThat(span.getOperationName(), is("/")); + } + + @Test + public void testException() throws Throwable { + realCallInterceptor.onConstruct(enhancedInstance, allArguments); + realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); + + realCallInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException")); + + Response response = mock(Response.class); + when(response.code()).thenReturn(200); + realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertSpan(spans.get(0)); + SpanAssert.assertOccurException(spans.get(0), true); + SpanAssert.assertLogSize(spans.get(0), 1); + SpanAssert.assertException(SpanHelper.getLogs(spans.get(0)).get(0), NullPointerException.class, "testException"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java deleted file mode 100644 index ddf8090e9c36..000000000000 --- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.okhttp.v3; - -import java.util.List; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLogSize; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertOccurException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -/** - * @author peng-yongsheng - */ -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -@PrepareForTest({Response.class}) -public class RealCallInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private RealCallInterceptor realCallInterceptor; - - @Mock - private OkHttpClient client; - - private Request request; - - private Object[] allArguments; - private Class[] argumentTypes; - - private EnhancedInstance enhancedInstance = new EnhancedInstance() { - - private Object object; - - @Override - public Object getSkyWalkingDynamicField() { - return object; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - this.object = value; - } - }; - - @Before - public void setUp() throws Exception { - request = new Request.Builder().url("http://skywalking.org").build(); - allArguments = new Object[] {client, request, false}; - argumentTypes = new Class[] {client.getClass(), request.getClass(), Boolean.class}; - realCallInterceptor = new RealCallInterceptor(); - } - - @Test - public void testOnConstruct() { - realCallInterceptor.onConstruct(enhancedInstance, allArguments); - assertThat(enhancedInstance.getSkyWalkingDynamicField(), is(allArguments[1])); - } - - @Test - public void testMethodsAround() throws Throwable { - realCallInterceptor.onConstruct(enhancedInstance, allArguments); - realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - Response response = mock(Response.class); - when(response.code()).thenReturn(200); - realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertSpan(spans.get(0)); - assertOccurException(spans.get(0), false); - } - - @Test - public void testMethodsAroundError() throws Throwable { - realCallInterceptor.onConstruct(enhancedInstance, allArguments); - realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - Response response = mock(Response.class); - when(response.code()).thenReturn(404); - realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertSpan(spans.get(0)); - assertOccurException(spans.get(0), true); - } - - private void assertSpan(AbstractTracingSpan span) { - assertComponent(span, ComponentsDefine.OKHTTP); - assertLayer(span, SpanLayer.HTTP); - assertTag(span, 0, "GET"); - assertTag(span, 1, "http://skywalking.org/"); - assertThat(span.isExit(), is(true)); - assertThat(span.getOperationName(), is("/")); - } - - @Test - public void testException() throws Throwable { - realCallInterceptor.onConstruct(enhancedInstance, allArguments); - realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null); - - realCallInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException")); - - Response response = mock(Response.class); - when(response.code()).thenReturn(200); - realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertSpan(spans.get(0)); - assertOccurException(spans.get(0), true); - assertLogSize(spans.get(0), 1); - assertException(SpanHelper.getLogs(spans.get(0)).get(0), NullPointerException.class, "testException"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java index 7b50568406c2..06ccae6d640c 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java @@ -21,11 +21,11 @@ import java.lang.reflect.Method; import java.sql.Connection; import java.sql.PreparedStatement; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; /** * {@link JDBCPrepareStatementWithArrayInterceptor} return {@link SWPreparedStatement} instance that wrapper the real diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java new file mode 100644 index 000000000000..959d202e53f7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.jdbc.define.Constants; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link + * oracle.jdbc.driver.PhysicalConnection}.
+ * + * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor + * 2. Enhance prepareStatement that the seconds argument type is java.lang.String[] by + * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor + * 3. Enhance prepareStatement that the seconds argument type is int[] by + * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor + * 4. Enhance prepareCall by + * org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor + * 5. Enhance createStatement + * by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor + * 6. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * + * @author zhangxin + */ +public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS = "oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor"; + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.PhysicalConnection"; + public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; + public static final String INT_ARRAY_ARGUMENT_TYPE = "int[]"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3)); + } + + @Override public String getMethodsInterceptor() { + return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(ArgumentTypeNameMatch.takesArgumentWithType(1, STRING_ARRAY_ARGUMENT_TYPE)); + } + + @Override public String getMethodsInterceptor() { + return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(ArgumentTypeNameMatch.takesArgumentWithType(1, INT_ARRAY_ARGUMENT_TYPE)); + } + + @Override public String getMethodsInterceptor() { + return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.PREPARE_CALL_METHOD_NAME).and(takesArguments(3)); + } + + @Override public String getMethodsInterceptor() { + return Constants.PREPARE_CALL_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(Constants.COMMIT_METHOD_NAME).or(named(Constants.ROLLBACK_METHOD_NAME)).or(named(Constants.CLOSE_METHOD_NAME)).or(named(Constants.RELEASE_SAVE_POINT_METHOD_NAME)); + } + + @Override public String getMethodsInterceptor() { + return Constants.SERVICE_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java new file mode 100644 index 000000000000..2e4fc8f3e034 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.oracle.define; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; + +/** + * {@link DriverInstrumentation} presents that skywalking intercepts {@link oracle.jdbc.driver.OracleDriver}. + * + * @author zhangxin + */ +public class DriverInstrumentation extends AbstractDriverInstrumentation { + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName("oracle.jdbc.driver.OracleDriver"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java deleted file mode 100644 index ba6783126e91..000000000000 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.oracle.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; - -/** - * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link - * oracle.jdbc.driver.PhysicalConnection}.
- * - * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareStatement that the seconds argument type is java.lang.String[] by - * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor - * 3. Enhance prepareStatement that the seconds argument type is int[] by - * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor - * 4. Enhance prepareCall by - * org.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 5. Enhance createStatement - * by org.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 6. Enhance commit, rollback, close, releaseSavepoint by org.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor - * - * @author zhangxin - */ -public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS = "oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor"; - public static final String ENHANCE_CLASS = "oracle.jdbc.driver.PhysicalConnection"; - public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; - public static final String INT_ARRAY_ARGUMENT_TYPE = "int[]"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArgumentWithType(1, STRING_ARRAY_ARGUMENT_TYPE)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArgumentWithType(1, INT_ARRAY_ARGUMENT_TYPE)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_CALL_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_CALL_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_STATEMENT_METHOD_NAME).and(takesArguments(2)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(COMMIT_METHOD_NAME).or(named(ROLLBACK_METHOD_NAME)).or(named(CLOSE_METHOD_NAME)).or(named(RELEASE_SAVE_POINT_METHOD_NAME)); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java deleted file mode 100644 index 1e896d5dd4d4..000000000000 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/oracle/define/DriverInstrumentation.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.oracle.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; - -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link DriverInstrumentation} presents that skywalking intercepts {@link oracle.jdbc.driver.OracleDriver}. - * - * @author zhangxin - */ -public class DriverInstrumentation extends AbstractDriverInstrumentation { - - @Override - protected ClassMatch enhanceClass() { - return byName("oracle.jdbc.driver.OracleDriver"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def index 26a5ba53156a..e2a524a6ed6c 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -oracle-10.x=org.skywalking.apm.plugin.jdbc.oracle.define.DriverInstrumentation -oracle-10.x=org.skywalking.apm.plugin.jdbc.oracle.define.ConnectionInstrumentation +oracle-10.x=DriverInstrumentation +oracle-10.x=ConnectionInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java new file mode 100644 index 000000000000..9410ef0ebe3e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link org.postgresql.jdbc.PgConnection#prepareCall} method in + * {@link org.postgresql.jdbc.PgConnection}, {@link org.postgresql.jdbc.PgConnection} or {@link org.postgresql.jdbc3.Jdbc3Connection} class. + * + * @author zhangxin + */ +public class CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java new file mode 100644 index 000000000000..0f742b6cbed9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreatePreparedStatementInterceptor} intercepts the {@link org.postgresql.jdbc.PgConnection#prepareStatement} method in + * {@link org.postgresql.jdbc.PgConnection}, {@link org.postgresql.jdbc.PgConnection} or {@link org.postgresql.jdbc3.Jdbc3Connection} class. + * + * @author zhangxin + */ +public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java new file mode 100644 index 000000000000..4f24c23bc6d9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.postgresql.jdbc.PgConnection; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link PgConnection#createStatement} method in + * {@link org.postgresql.jdbc.PgConnection}, {@link org.postgresql.jdbc.PgConnection} or {@link org.postgresql.jdbc3.Jdbc3Connection} class. + * + * @author zhangxin + */ +public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "CallableStatement")); + } + + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java new file mode 100644 index 000000000000..eaf20dab26c5 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql; + +import java.lang.reflect.Method; +import java.sql.Connection; +import java.sql.PreparedStatement; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link JDBCPrepareStatementWithStringArrayInterceptor} return {@link SWPreparedStatement} instance that wrapper the + * real preparedStatement instance when the client call org.postgresql.jdbc.PgConnection#prepareStatement(String, + * String[]) method. method. + * + * @author zhangxin + */ +public class JDBCPrepareStatementWithStringArrayInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + /** + * To prevent the org.postgresql.jdbc.prepareStatement(String sql) method from repeating + * interceptor, Because PGConnection call org.postgresql.jdbc.prepareStatement(String sql) method when + * the second argument is empty. + * + * @see org.postgresql.jdbc.PgConnection#prepareStatement(String, String[]) + **/ + String[] columnNames = (String[])allArguments[1]; + if (columnNames != null && columnNames.length == 0) { + return ret; + } + return new SWPreparedStatement((Connection)objInst, (PreparedStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java new file mode 100644 index 000000000000..d98aed6581e3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link StatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor methods. + * + * @author zhangxin + */ +public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java new file mode 100644 index 000000000000..6dcd819260ab --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link AbstractJdbc2StatementInstrumentation} intercept the following methods that the class which extend {@link + * org.postgresql.jdbc2.AbstractJdbc2Statement} by {@link StatementExecuteMethodsInterceptor}.
+ * 1. the execute with non parameter + * 2. the execute with one parameter + * 3. the executeBatch + * 4. the executeQuery with non parameter + * 5. the executeQuery with one parameter + * 6. the executeUpdate with non parameter + * 7. the executeUpdate with one parameter + * 8. the addBatch with non parameter + * 9. the addBatch with one parameter + * + * @author zhangxin + */ +public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.postgresql.jdbc2.AbstractJdbc2Statement"; + private static final String INTERCEPTOR_CLASS = "StatementExecuteMethodsInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute").and(takesArguments(0)) + .or(named("execute").and(takesArguments(1))) + .or(named("executeBatch")) + .or(named("executeQuery").and(takesArguments(0))) + .or(named("executeQuery").and(takesArguments(1))) + .or(named("executeUpdate").and(takesArguments(0))) + .or(named("executeUpdate").and(takesArguments(1))) + .or(named("addBatch").and(takesArguments(1))) + .or(named("addBatch").and(takesArguments(0))); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java new file mode 100644 index 000000000000..f652775ef891 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link + * org.postgresql.jdbc.PgConnection}.
+ * + * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor + * 2. Enhance prepareStatement that the seconds argument type is java.lang.String[] by + * JDBCPrepareStatementWithStringArrayInterceptor + * 3. Enhance prepareCall by + * org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor + * 4. Enhance createStatement + * by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor + * 5. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * + * @author zhangxin + */ +public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS = "JDBCPrepareStatementWithStringArrayInterceptor"; + public static final String ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection"; + public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArgumentWithType(1, STRING_ARRAY_ARGUMENT_TYPE)); + } + + @Override public String getMethodsInterceptor() { + return PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(3)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME)).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME)).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME)); + } + + @Override public String getMethodsInterceptor() { + return org.apache.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java new file mode 100644 index 000000000000..f91f480e0d6e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define; + +/** + * Interceptor class name constant variable + * + * @author zhangxin + */ +public class Constants { + public static final String CREATE_STATEMENT_INTERCEPTOR_CLASS = "CreateStatementInterceptor"; + public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS = "CreatePreparedStatementInterceptor"; + public static final String CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS = "CreateCallableStatementInterceptor"; + +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java new file mode 100644 index 000000000000..744ac9fc02da --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define; + +import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link DriverInstrumentation} presents that skywalking intercepts {@link org.postgresql.Driver}. + * + * @author zhangxin + */ +public class DriverInstrumentation extends AbstractDriverInstrumentation { + + @Override + protected ClassMatch enhanceClass() { + return byName("org.postgresql.Driver"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java new file mode 100644 index 000000000000..e43ec5bcfcfa --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@link Jdbc3ConnectionInstrumentation} intercept the following methods that the class which extend {@link + * org.postgresql.jdbc3.Jdbc3Connection}.
+ * + * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor + * 2. Enhance prepareCall by + * org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor + * 3. Enhance createStatement + * by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor + * 4. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * + * @author zhangxin + */ +public class Jdbc3ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.postgresql.jdbc3.Jdbc3Connection"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(3)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME)).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME)) + .or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME)); + } + + @Override public String getMethodsInterceptor() { + return org.apache.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java new file mode 100644 index 000000000000..3131c5a38255 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link Jdbc4ConnectionInstrumentation} intercept the following methods that the class which extend {@link + * org.postgresql.jdbc4.Jdbc4Connection}.
+ * + * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor + * 2. Enhance prepareCall by + * org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor + * 3. Enhance createStatement + * by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor + * 4. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * + * @author zhangxin + */ +public class Jdbc4ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.postgresql.jdbc4.Jdbc4Connection"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME).and(takesArguments(4)); + } + + @Override public String getMethodsInterceptor() { + return Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME).and(takesArguments(3)); + } + + @Override public String getMethodsInterceptor() { + return org.apache.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME)).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME)).or(named(org.apache.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME)); + } + + @Override public String getMethodsInterceptor() { + return org.apache.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java deleted file mode 100644 index 64bd2523c4c6..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link CreateStatementInterceptor} intercepts the {@link org.postgresql.jdbc.PgConnection#prepareCall} method in - * {@link org.postgresql.jdbc.PgConnection}, {@link org.postgresql.jdbc.PgConnection} or {@link org.postgresql.jdbc3.Jdbc3Connection} class. - * - * @author zhangxin - */ -public class CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (ret instanceof EnhancedInstance) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java deleted file mode 100644 index c044eb0dc09d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link CreatePreparedStatementInterceptor} intercepts the {@link org.postgresql.jdbc.PgConnection#prepareStatement} method in - * {@link org.postgresql.jdbc.PgConnection}, {@link org.postgresql.jdbc.PgConnection} or {@link org.postgresql.jdbc3.Jdbc3Connection} class. - * - * @author zhangxin - */ -public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (ret instanceof EnhancedInstance) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java deleted file mode 100644 index b7bbeaee5283..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql; - -import java.lang.reflect.Method; -import org.postgresql.jdbc.PgConnection; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link CreateStatementInterceptor} intercepts the {@link PgConnection#createStatement} method in - * {@link org.postgresql.jdbc.PgConnection}, {@link org.postgresql.jdbc.PgConnection} or {@link org.postgresql.jdbc3.Jdbc3Connection} class. - * - * @author zhangxin - */ -public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - - if (ret instanceof EnhancedInstance) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "CallableStatement")); - } - - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java deleted file mode 100644 index 9aa5bfd97ed3..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql; - -import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.PreparedStatement; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; - -/** - * {@link JDBCPrepareStatementWithStringArrayInterceptor} return {@link SWPreparedStatement} instance that wrapper the - * real preparedStatement instance when the client call org.postgresql.jdbc.PgConnection#prepareStatement(String, - * String[]) method. method. - * - * @author zhangxin - */ -public class JDBCPrepareStatementWithStringArrayInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - /** - * To prevent the org.postgresql.jdbc.prepareStatement(String sql) method from repeating - * interceptor, Because PGConnection call org.postgresql.jdbc.prepareStatement(String sql) method when - * the second argument is empty. - * - * @see org.postgresql.jdbc.PgConnection#prepareStatement(String, String[]) - **/ - String[] columnNames = (String[])allArguments[1]; - if (columnNames != null && columnNames.length == 0) { - return ret; - } - return new SWPreparedStatement((Connection)objInst, (PreparedStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java deleted file mode 100644 index 2fe0638d4d69..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; - -/** - * {@link StatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor methods. - * - * @author zhangxin - */ -public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, cacheObject.getSql()); - span.setComponent(connectInfo.getComponent()); - - SpanLayer.asDB(span); - } - - @Override - public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - Object ret) throws Throwable { - StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - if (cacheObject.getConnectionInfo() != null) { - ContextManager.stopSpan(); - } - return ret; - } - - @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - if (cacheObject.getConnectionInfo() != null) { - ContextManager.activeSpan().errorOccurred().log(t); - } - } - - private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { - return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java deleted file mode 100644 index 3ebce25ba22e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link AbstractJdbc2StatementInstrumentation} intercept the following methods that the class which extend {@link - * org.postgresql.jdbc2.AbstractJdbc2Statement} by {@link org.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor}.
- * 1. the execute with non parameter - * 2. the execute with one parameter - * 3. the executeBatch - * 4. the executeQuery with non parameter - * 5. the executeQuery with one parameter - * 6. the executeUpdate with non parameter - * 7. the executeUpdate with one parameter - * 8. the addBatch with non parameter - * 9. the addBatch with one parameter - * - * @author zhangxin - */ -public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.postgresql.jdbc2.AbstractJdbc2Statement"; - private static final String INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute").and(takesArguments(0)) - .or(named("execute").and(takesArguments(1))) - .or(named("executeBatch")) - .or(named("executeQuery").and(takesArguments(0))) - .or(named("executeQuery").and(takesArguments(1))) - .or(named("executeUpdate").and(takesArguments(0))) - .or(named("executeUpdate").and(takesArguments(1))) - .or(named("addBatch").and(takesArguments(1))) - .or(named("addBatch").and(takesArguments(0))); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java deleted file mode 100644 index d383a4a2d804..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_STATEMENT_INTERCEPTOR_CLASS; - -/** - * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link - * org.postgresql.jdbc.PgConnection}.
- * - * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareStatement that the seconds argument type is java.lang.String[] by - * org.skywalking.apm.plugin.jdbc.postgresql.JDBCPrepareStatementWithStringArrayInterceptor - * 3. Enhance prepareCall by - * org.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 4. Enhance createStatement - * by org.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 5. Enhance commit, rollback, close, releaseSavepoint by org.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor - * - * @author zhangxin - */ -public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jdbc.postgresql.JDBCPrepareStatementWithStringArrayInterceptor"; - public static final String ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection"; - public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArgumentWithType(1, STRING_ARRAY_ARGUMENT_TYPE)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_CALL_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_STATEMENT_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(COMMIT_METHOD_NAME).or(named(ROLLBACK_METHOD_NAME)).or(named(CLOSE_METHOD_NAME)).or(named(RELEASE_SAVE_POINT_METHOD_NAME)); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java deleted file mode 100644 index 7a0c24828cb5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql.define; - -/** - * Interceptor class name constant variable - * - * @author zhangxin - */ -public class Constants { - public static final String CREATE_STATEMENT_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jdbc.postgresql.CreateStatementInterceptor"; - public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jdbc.postgresql.CreatePreparedStatementInterceptor"; - public static final String CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jdbc.postgresql.CreateCallableStatementInterceptor"; - -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java deleted file mode 100644 index cc749866155b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/DriverInstrumentation.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; - -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link DriverInstrumentation} presents that skywalking intercepts {@link org.postgresql.Driver}. - * - * @author zhangxin - */ -public class DriverInstrumentation extends AbstractDriverInstrumentation { - - @Override - protected ClassMatch enhanceClass() { - return byName("org.postgresql.Driver"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java deleted file mode 100644 index eee1fefc1201..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_STATEMENT_INTERCEPTOR_CLASS; - -/** - * {@link Jdbc3ConnectionInstrumentation} intercept the following methods that the class which extend {@link - * org.postgresql.jdbc3.Jdbc3Connection}.
- * - * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareCall by - * org.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 3. Enhance createStatement - * by org.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 4. Enhance commit, rollback, close, releaseSavepoint by org.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor - * - * @author zhangxin - */ -public class Jdbc3ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String ENHANCE_CLASS = "org.postgresql.jdbc3.Jdbc3Connection"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_CALL_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_STATEMENT_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(COMMIT_METHOD_NAME).or(named(ROLLBACK_METHOD_NAME)).or(named(CLOSE_METHOD_NAME)) - .or(named(RELEASE_SAVE_POINT_METHOD_NAME)); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java deleted file mode 100644 index b7535f0da2d0..000000000000 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.jdbc.postgresql.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; -import static org.skywalking.apm.plugin.jdbc.postgresql.define.Constants.CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; - -/** - * {@link Jdbc4ConnectionInstrumentation} intercept the following methods that the class which extend {@link - * org.postgresql.jdbc4.Jdbc4Connection}.
- * - * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareCall by - * org.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 3. Enhance createStatement - * by org.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 4. Enhance commit, rollback, close, releaseSavepoint by org.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor - * - * @author zhangxin - */ -public class Jdbc4ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String ENHANCE_CLASS = "org.postgresql.jdbc4.Jdbc4Connection"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(PREPARE_CALL_METHOD_NAME).and(takesArguments(4)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_STATEMENT_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return CREATE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(COMMIT_METHOD_NAME).or(named(ROLLBACK_METHOD_NAME)).or(named(CLOSE_METHOD_NAME)).or(named(RELEASE_SAVE_POINT_METHOD_NAME)); - } - - @Override public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def index b069baff8ab1..363b2f24133e 100644 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,5 +1,5 @@ -postgresql-8.x=org.skywalking.apm.plugin.jdbc.postgresql.define.DriverInstrumentation -postgresql-8.x=org.skywalking.apm.plugin.jdbc.postgresql.define.Jdbc3ConnectionInstrumentation -postgresql-8.x=org.skywalking.apm.plugin.jdbc.postgresql.define.Jdbc4ConnectionInstrumentation -postgresql-8.x=org.skywalking.apm.plugin.jdbc.postgresql.define.ConnectionInstrumentation -postgresql-8.x=org.skywalking.apm.plugin.jdbc.postgresql.define.AbstractJdbc2StatementInstrumentation +postgresql-8.x=DriverInstrumentation +postgresql-8.x=Jdbc3ConnectionInstrumentation +postgresql-8.x=Jdbc4ConnectionInstrumentation +postgresql-8.x=ConnectionInstrumentation +postgresql-8.x=AbstractJdbc2StatementInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java new file mode 100644 index 000000000000..7fc7438764df --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.resin.v3; + +import com.caucho.server.connection.CauchoRequest; +import com.caucho.server.http.HttpResponse; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link ResinV3Interceptor} intercept method of{@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse)} record the resin host, port ,url. + * + * @author baiyang + */ +public class ResinV3Interceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + CauchoRequest request = (CauchoRequest)allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHeader(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(request.getPageURI(), contextCarrier); + span.setComponent(ComponentsDefine.RESIN); + Tags.URL.set(span, appendRequestURL(request)); + SpanLayer.asHttp(span); + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + HttpResponse response = (HttpResponse)allArguments[1]; + AbstractSpan span = ContextManager.activeSpan(); + + if (response.getStatusCode() >= 400) { + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatusCode())); + span.errorOccurred(); + } + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.log(t); + activeSpan.errorOccurred(); + } + + /** + * Append request URL. + * + * @param request + * @return + */ + private String appendRequestURL(CauchoRequest request) { + StringBuffer sb = new StringBuffer(); + sb.append(request.getScheme()); + sb.append("://"); + sb.append(request.getServerName()); + sb.append(":"); + sb.append(request.getServerPort()); + sb.append(request.getPageURI()); + return sb.toString(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java new file mode 100644 index 000000000000..c9604109915d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.resin.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.resin.v3.ResinV3Interceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ResinV3Instrumentation} presents that skywalking intercepts {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse)} by using {@link ResinV3Interceptor}. + * + * @author baiyang + */ +public class ResinV3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.caucho.server.dispatch.ServletInvocation"; + + private static final String METHOD_INTERCET_CLASS = "ResinV3Interceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("service"); + } + + @Override + public String getMethodsInterceptor() { + return METHOD_INTERCET_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected String[] witnessClasses() { + return new String[] {"com.caucho.server.connection.AbstractHttpResponse"}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java deleted file mode 100644 index aed7106130fb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.resin.v3; - -import com.caucho.server.connection.CauchoRequest; -import com.caucho.server.http.HttpResponse; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link ResinV3Interceptor} intercept method of{@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest, - * javax.servlet.ServletResponse)} record the resin host, port ,url. - * - * @author baiyang - */ -public class ResinV3Interceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - CauchoRequest request = (CauchoRequest)allArguments[0]; - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHeader(next.getHeadKey())); - } - - AbstractSpan span = ContextManager.createEntrySpan(request.getPageURI(), contextCarrier); - span.setComponent(ComponentsDefine.RESIN); - Tags.URL.set(span, appendRequestURL(request)); - SpanLayer.asHttp(span); - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - HttpResponse response = (HttpResponse)allArguments[1]; - AbstractSpan span = ContextManager.activeSpan(); - - if (response.getStatusCode() >= 400) { - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatusCode())); - span.errorOccurred(); - } - ContextManager.stopSpan(); - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.log(t); - activeSpan.errorOccurred(); - } - - /** - * Append request URL. - * - * @param request - * @return - */ - private String appendRequestURL(CauchoRequest request) { - StringBuffer sb = new StringBuffer(); - sb.append(request.getScheme()); - sb.append("://"); - sb.append(request.getServerName()); - sb.append(":"); - sb.append(request.getServerPort()); - sb.append(request.getPageURI()); - return sb.toString(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java deleted file mode 100644 index b4125b9525d0..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.resin.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.resin.v3.ResinV3Interceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link ResinV3Instrumentation} presents that skywalking intercepts {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest, - * javax.servlet.ServletResponse)} by using {@link ResinV3Interceptor}. - * - * @author baiyang - */ -public class ResinV3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.caucho.server.dispatch.ServletInvocation"; - - private static final String METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.resin.v3.ResinV3Interceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("service"); - } - - @Override - public String getMethodsInterceptor() { - return METHOD_INTERCET_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected String[] witnessClasses() { - return new String[] {"com.caucho.server.connection.AbstractHttpResponse"}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/resources/skywalking-plugin.def index 86586edb85fc..1bab5044defb 100644 --- a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -resin-3.x=org.skywalking.apm.plugin.resin.v3.define.ResinV3Instrumentation \ No newline at end of file +resin-3.x=ResinV3Instrumentation diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java new file mode 100644 index 000000000000..89c47aabca3e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.resin.v3; + +import com.caucho.server.connection.CauchoRequest; +import com.caucho.server.http.HttpResponse; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.hamcrest.MatcherAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +/** + * ResinInterceptorTest + * + * @author baiyang + */ +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ResinV3InterceptorTest { + private ResinV3Interceptor interceptor; + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private CauchoRequest request; + @Mock + private HttpResponse response; + @Mock + private MethodInterceptResult methodInterceptResult; + + private Object[] arguments; + private Class[] argumentType; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new ResinV3Interceptor(); + when(request.getPageURI()).thenReturn("/test/testRequestURL"); + when(request.getScheme()).thenReturn("http"); + when(request.getServerName()).thenReturn("localhost"); + when(request.getServerPort()).thenReturn(8080); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatusCode()).thenReturn(200); + arguments = new Object[] {request, response}; + argumentType = new Class[] {request.getClass(), response.getClass()}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithSerializedContextData() throws Throwable { + when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.333.2345|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + + interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + MatcherAssert.assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + MatcherAssert.assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.333.2345")); + } + + private void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.RESIN); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java deleted file mode 100644 index 030d12e7e990..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.resin.v3; - -import com.caucho.server.connection.CauchoRequest; -import com.caucho.server.http.HttpResponse; -import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -/** - * ResinInterceptorTest - * - * @author baiyang - */ -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ResinV3InterceptorTest { - private ResinV3Interceptor interceptor; - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private CauchoRequest request; - @Mock - private HttpResponse response; - @Mock - private MethodInterceptResult methodInterceptResult; - - private Object[] arguments; - private Class[] argumentType; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new ResinV3Interceptor(); - when(request.getPageURI()).thenReturn("/test/testRequestURL"); - when(request.getScheme()).thenReturn("http"); - when(request.getServerName()).thenReturn("localhost"); - when(request.getServerPort()).thenReturn(8080); - when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); - when(response.getStatusCode()).thenReturn(200); - arguments = new Object[] {request, response}; - argumentType = new Class[] {request.getClass(), response.getClass()}; - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithSerializedContextData() throws Throwable { - when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.333.2345|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); - - interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - assertTraceSegmentRef(traceSegment.getRefs().get(0)); - } - - @Test - public void testWithOccurException() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.333.2345")); - } - - private void assertHttpSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("/test/testRequestURL")); - assertComponent(span, ComponentsDefine.RESIN); - assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java new file mode 100644 index 000000000000..0eee924d657c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.resin.v4; + +import com.caucho.server.http.CauchoRequest; +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * Created by Baiyang on 2017/5/2. + */ +public class ResinV4Interceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + CauchoRequest request = (CauchoRequest)allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHeader(next.getHeadKey())); + } + AbstractSpan span = ContextManager.createEntrySpan(request.getPageURI(), contextCarrier); + span.setComponent(ComponentsDefine.RESIN); + Tags.URL.set(span, appendRequestURL(request)); + SpanLayer.asHttp(span); + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + HttpServletResponse response = (HttpServletResponse)allArguments[1]; + AbstractSpan span = ContextManager.activeSpan(); + + if (response.getStatus() >= 400) { + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + span.errorOccurred(); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.log(t); + activeSpan.errorOccurred(); + } + + /** + * Append request URL. + * + * @param request + * @return + */ + private String appendRequestURL(CauchoRequest request) { + StringBuffer sb = new StringBuffer(); + sb.append(request.getScheme()); + sb.append("://"); + sb.append(request.getServerName()); + sb.append(":"); + sb.append(request.getServerPort()); + sb.append(request.getPageURI()); + return sb.toString(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java new file mode 100644 index 000000000000..dbe5d8cae8c6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.resin.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.resin.v4.ResinV4Interceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link ResinV4Instrumentation} presents that skywalking intercepts {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest, + * javax.servlet.ServletResponse)} by using {@link ResinV4Interceptor}. + * + * @author baiyang + */ +public class ResinV4Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.caucho.server.dispatch.ServletInvocation"; + + private static final String METHOD_INTERCET_CLASS = "ResinV4Interceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("service"); + } + + @Override + public String getMethodsInterceptor() { + return METHOD_INTERCET_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + protected String[] witnessClasses() { + return new String[] {"com.caucho.server.http.HttpServletResponseImpl"}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java deleted file mode 100644 index b148625cf50c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.resin.v4; - -import com.caucho.server.http.CauchoRequest; -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletResponse; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * Created by Baiyang on 2017/5/2. - */ -public class ResinV4Interceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - CauchoRequest request = (CauchoRequest)allArguments[0]; - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHeader(next.getHeadKey())); - } - AbstractSpan span = ContextManager.createEntrySpan(request.getPageURI(), contextCarrier); - span.setComponent(ComponentsDefine.RESIN); - Tags.URL.set(span, appendRequestURL(request)); - SpanLayer.asHttp(span); - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - HttpServletResponse response = (HttpServletResponse)allArguments[1]; - AbstractSpan span = ContextManager.activeSpan(); - - if (response.getStatus() >= 400) { - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); - span.errorOccurred(); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.log(t); - activeSpan.errorOccurred(); - } - - /** - * Append request URL. - * - * @param request - * @return - */ - private String appendRequestURL(CauchoRequest request) { - StringBuffer sb = new StringBuffer(); - sb.append(request.getScheme()); - sb.append("://"); - sb.append(request.getServerName()); - sb.append(":"); - sb.append(request.getServerPort()); - sb.append(request.getPageURI()); - return sb.toString(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java deleted file mode 100644 index 553fe03f49f2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.resin.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.resin.v4.ResinV4Interceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link ResinV4Instrumentation} presents that skywalking intercepts {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest, - * javax.servlet.ServletResponse)} by using {@link ResinV4Interceptor}. - * - * @author baiyang - */ -public class ResinV4Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "com.caucho.server.dispatch.ServletInvocation"; - - private static final String METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.resin.v4.ResinV4Interceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("service"); - } - - @Override - public String getMethodsInterceptor() { - return METHOD_INTERCET_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected String[] witnessClasses() { - return new String[] {"com.caucho.server.http.HttpServletResponseImpl"}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/resources/skywalking-plugin.def index 3bab53d039f9..3d879538d6b4 100644 --- a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -resin-4.x=org.skywalking.apm.plugin.resin.v4.define.ResinV4Instrumentation \ No newline at end of file +resin-4.x=ResinV4Instrumentation diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java new file mode 100644 index 000000000000..13ea9924d307 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.resin.v4; + +import com.caucho.server.http.CauchoRequest; +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +/** + * Created by Baiyang on 2017/5/6. + */ +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ResinV4InterceptorTest { + private ResinV4Interceptor interceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private CauchoRequest request; + @Mock + private HttpServletResponse response; + @Mock + private MethodInterceptResult methodInterceptResult; + + private Object[] arguments; + private Class[] argumentType; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + + interceptor = new ResinV4Interceptor(); + + when(request.getPageURI()).thenReturn("/test/testRequestURL"); + when(request.getScheme()).thenReturn("http"); + when(request.getServerName()).thenReturn("localhost"); + when(request.getServerPort()).thenReturn(8080); + when(request.getRequestURI()).thenReturn("/test/testRequestURL"); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatus()).thenReturn(200); + arguments = new Object[] {request, response}; + argumentType = new Class[] {request.getClass(), response.getClass()}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithSerializedContextData() throws Throwable { + when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.444.555|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + + interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555")); + } + + private void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.RESIN); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java deleted file mode 100644 index 1db6fa9639f2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.resin.v4; - -import com.caucho.server.http.CauchoRequest; -import java.util.List; -import javax.servlet.http.HttpServletResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -/** - * Created by Baiyang on 2017/5/6. - */ -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ResinV4InterceptorTest { - private ResinV4Interceptor interceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private CauchoRequest request; - @Mock - private HttpServletResponse response; - @Mock - private MethodInterceptResult methodInterceptResult; - - private Object[] arguments; - private Class[] argumentType; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - - interceptor = new ResinV4Interceptor(); - - when(request.getPageURI()).thenReturn("/test/testRequestURL"); - when(request.getScheme()).thenReturn("http"); - when(request.getServerName()).thenReturn("localhost"); - when(request.getServerPort()).thenReturn(8080); - when(request.getRequestURI()).thenReturn("/test/testRequestURL"); - when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); - when(response.getStatus()).thenReturn(200); - arguments = new Object[] {request, response}; - argumentType = new Class[] {request.getClass(), response.getClass()}; - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithSerializedContextData() throws Throwable { - when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.444.555|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); - - interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - assertTraceSegmentRef(traceSegment.getRefs().get(0)); - } - - @Test - public void testWithOccurException() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); - assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555")); - } - - private void assertHttpSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("/test/testRequestURL")); - assertComponent(span, ComponentsDefine.RESIN); - assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java new file mode 100644 index 000000000000..8eb452634c49 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import java.util.List; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link AbstractMessageConsumeInterceptor} create entry span when the consumeMessage in the {@link + * org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently} and {@link + * org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly} class. + * + * @author zhangxin + */ +public abstract class AbstractMessageConsumeInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String COMSUMER_OPERATION_NAME_PREFIX = "RocketMQ/"; + + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + List msgs = (List)allArguments[0]; + + ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0)); + AbstractSpan span = ContextManager.createEntrySpan(COMSUMER_OPERATION_NAME_PREFIX + msgs.get(0).getTopic() + "/Consumer", contextCarrier); + + span.setComponent(ComponentsDefine.ROCKET_MQ); + span.setLayer(SpanLayer.MQ); + for (int i = 1; i < msgs.size(); i++) { + ContextManager.extract(getContextCarrierFromMessage(msgs.get(i))); + } + + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } + + private ContextCarrier getContextCarrierFromMessage(MessageExt message) { + ContextCarrier contextCarrier = new ContextCarrier(); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(message.getUserProperty(next.getHeadKey())); + } + + return contextCarrier; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java new file mode 100644 index 000000000000..332c8dc76909 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; + +/** + * {@link MessageConcurrentlyConsumeInterceptor} set the process status after the {@link + * org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List, + * org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method execute. + * + * @author zhang xin + */ +public class MessageConcurrentlyConsumeInterceptor extends AbstractMessageConsumeInterceptor { + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ConsumeConcurrentlyStatus status = (ConsumeConcurrentlyStatus)ret; + if (status == ConsumeConcurrentlyStatus.RECONSUME_LATER) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + Tags.STATUS_CODE.set(activeSpan, status.name()); + } + ContextManager.stopSpan(); + return ret; + } +} + diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java new file mode 100644 index 000000000000..222c1181974c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; + +/** + * {@link MessageOrderlyConsumeInterceptor} set the process status after the {@link + * org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List, + * org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method execute. + * + * @author zhang xin + */ +public class MessageOrderlyConsumeInterceptor extends AbstractMessageConsumeInterceptor { + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + + ConsumeOrderlyStatus status = (ConsumeOrderlyStatus)ret; + if (status == ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + Tags.STATUS_CODE.set(activeSpan, status.name()); + } + ContextManager.stopSpan(); + return ret; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java new file mode 100644 index 000000000000..ae381dc0dc88 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import org.apache.rocketmq.client.impl.CommunicationMode; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; +import org.apache.skywalking.apm.util.StringUtil; + +import static org.apache.rocketmq.common.message.MessageDecoder.NAME_VALUE_SEPARATOR; +import static org.apache.rocketmq.common.message.MessageDecoder.PROPERTY_SEPARATOR; + +/** + * {@link MessageSendInterceptor} create exit span when the method {@link org.apache.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String, + * String, Message, org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader, long, + * org.apache.rocketmq.client.impl.CommunicationMode, org.apache.rocketmq.client.producer.SendCallback, + * org.apache.rocketmq.client.impl.producer.TopicPublishInfo, org.apache.rocketmq.client.impl.factory.MQClientInstance, + * int, org.apache.rocketmq.client.hook.SendMessageContext, org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl)} + * execute. + * + * @author zhang xin + */ +public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/"; + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Message message = (Message)allArguments[2]; + ContextCarrier contextCarrier = new ContextCarrier(); + String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField()); + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress); + span.setComponent(ComponentsDefine.ROCKET_MQ); + span.setLayer(SpanLayer.MQ); + span.tag("brokerName", (String)allArguments[1]); + span.tag("tags", message.getTags()); + span.tag("communication.mode", ((CommunicationMode)allArguments[5]).name()); + + SendMessageRequestHeader requestHeader = (SendMessageRequestHeader)allArguments[3]; + StringBuilder properties = new StringBuilder(requestHeader.getProperties()); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + if (!StringUtil.isEmpty(next.getHeadValue())) { + properties.append(next.getHeadKey()); + properties.append(NAME_VALUE_SEPARATOR); + properties.append(next.getHeadValue()); + properties.append(PROPERTY_SEPARATOR); + } + } + requestHeader.setProperties(properties.toString()); + + if (allArguments[6] != null) { + ((EnhancedInstance)allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager.capture())); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } + + private String buildOperationName(String topicName) { + return ASYNC_SEND_OPERATION_NAME_PREFIX + topicName + "/Producer"; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java new file mode 100644 index 000000000000..05390e3045ff --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link OnExceptionInterceptor} create local span when the method {@link org.apache.rocketmq.client.producer.SendCallback#onException(Throwable)} + * execute. + * + * @author zhang xin + */ +public class OnExceptionInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String CALLBACK_OPERATION_NAME_PREFIX = "RocketMQ/"; + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo)objInst.getSkyWalkingDynamicField(); + AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback"); + activeSpan.setComponent(ComponentsDefine.ROCKET_MQ); + activeSpan.errorOccurred().log((Throwable)allArguments[0]); + ContextManager.continued(enhanceInfo.getContextSnapshot()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java new file mode 100644 index 000000000000..ef70559392dc --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.SendStatus; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; + +/** + * {@link OnSuccessInterceptor} create local span when the method {@link org.apache.rocketmq.client.producer.SendCallback#onSuccess(SendResult)} + * execute. + * + * @author zhang xin + */ +public class OnSuccessInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String CALLBACK_OPERATION_NAME_PREFIX = "RocketMQ/"; + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo)objInst.getSkyWalkingDynamicField(); + AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback"); + activeSpan.setComponent(ComponentsDefine.ROCKET_MQ); + SendStatus sendStatus = ((SendResult)allArguments[0]).getSendStatus(); + if (sendStatus != SendStatus.SEND_OK) { + activeSpan.errorOccurred(); + Tags.STATUS_CODE.set(activeSpan, sendStatus.name()); + } + ContextManager.continued(enhanceInfo.getContextSnapshot()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java new file mode 100644 index 000000000000..3771698b5814 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class UpdateNameServerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + objInst.setSkyWalkingDynamicField(allArguments[0]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java new file mode 100644 index 000000000000..7ae23c4c7de4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ConsumeMessageConcurrentlyInstrumentation} intercepts the {@link org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List, + * org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method by using {@link + * org.apache.skywalking.apm.plugin.rocketMQ.v4.MessageConcurrentlyConsumeInterceptor}. + * + * @author zhang xin + */ +public class ConsumeMessageConcurrentlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently"; + private static final String CONSUMER_MESSAGE_METHOD = "consumeMessage"; + private static final String INTERCEPTOR_CLASS = "org.apache.rocketmq.common.message.MessageConcurrentlyConsumeInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(CONSUMER_MESSAGE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return HierarchyMatch.byHierarchyMatch(new String[] {ENHANCE_CLASS}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java new file mode 100644 index 000000000000..be3780e0f044 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; + +/** + * {@link ConsumeMessageOrderlyInstrumentation} intercepts the {@link org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List, + * org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method by using {@link + * org.apache.skywalking.apm.plugin.rocketMQ.v4.MessageConcurrentlyConsumeInterceptor}. + * + * @author zhang xin + */ +public class ConsumeMessageOrderlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly"; + private static final String ENHANCE_METHOD = "consumeMessage"; + private static final String INTERCEPTOR_CLASS = "org.apache.rocketmq.common.message.MessageOrderlyConsumeInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byHierarchyMatch(new String[] {ENHANCE_CLASS}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java new file mode 100644 index 000000000000..e81329aeedd6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.rocketMQ.v4.MessageSendInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link MQClientAPIImplInstrumentation} intercepts the {@link org.apache.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String, + * String, org.apache.rocketmq.common.message.Message, org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader, + * long, org.apache.rocketmq.client.impl.CommunicationMode, org.apache.rocketmq.client.producer.SendCallback, + * org.apache.rocketmq.client.impl.producer.TopicPublishInfo, org.apache.rocketmq.client.impl.factory.MQClientInstance, + * int, org.apache.rocketmq.client.hook.SendMessageContext, org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl)} + * method by using {@link MessageSendInterceptor}. + * + * @author zhang xin + */ +public class MQClientAPIImplInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.impl.MQClientAPIImpl"; + private static final String SEND_MESSAGE_METHOD_NAME = "sendMessage"; + private static final String ASYNC_METHOD_INTERCEPTOR = "MessageSendInterceptor"; + public static final String UPDATE_NAME_SERVER_INTERCEPT_CLASS = "UpdateNameServerInterceptor"; + public static final String UPDATE_NAME_SERVER_METHOD_NAME = "updateNameServerAddressList"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(SEND_MESSAGE_METHOD_NAME).and(takesArguments(12)); + } + + @Override public String getMethodsInterceptor() { + return ASYNC_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(UPDATE_NAME_SERVER_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return UPDATE_NAME_SERVER_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java new file mode 100644 index 000000000000..15f7732a3153 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4.define; + +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; + +/** + * {@link SendCallBackEnhanceInfo} saves the topic Id and {@link ContextSnapshot} instance for trace. + * + * @author zhang xin + */ +public class SendCallBackEnhanceInfo { + private String topicId; + private ContextSnapshot contextSnapshot; + + public SendCallBackEnhanceInfo(String topicId, ContextSnapshot contextSnapshot) { + this.topicId = topicId; + this.contextSnapshot = contextSnapshot; + } + + public String getTopicId() { + return topicId; + } + + public ContextSnapshot getContextSnapshot() { + return contextSnapshot; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java new file mode 100644 index 000000000000..3e437f53aa4d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; + +/** + * {@link SendCallbackInstrumentation} intercepts {@link org.apache.rocketmq.client.producer.SendCallback#onSuccess(SendResult)} + * method by using {@link org.apache.skywalking.apm.plugin.rocketMQ.v4.OnSuccessInterceptor} and also intercepts {@link + * org.apache.rocketmq.client.producer.SendCallback#onException(Throwable)} by using {@link + * org.apache.skywalking.apm.plugin.rocketMQ.v4.OnExceptionInterceptor}. + * + * @author zhang xin + */ +public class SendCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.producer.SendCallback"; + private static final String ON_SUCCESS_ENHANCE_METHOD = "onSuccess"; + private static final String ON_SUCCESS_INTERCEPTOR = "OnSuccessInterceptor"; + private static final String ON_EXCEPTION_METHOD = "onException"; + private static final String ON_EXCEPTION_INTERCEPTOR = "OnExceptionInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_SUCCESS_ENHANCE_METHOD).and(takesArgumentWithType(0, "org.apache.rocketmq.client.producer.SendResult")); + } + + @Override public String getMethodsInterceptor() { + return ON_SUCCESS_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ON_EXCEPTION_METHOD).and(takesArgumentWithType(0, "java.lang.Throwable")); + } + + @Override public String getMethodsInterceptor() { + return ON_EXCEPTION_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byHierarchyMatch(new String[] {ENHANCE_CLASS}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java deleted file mode 100644 index 7737c5a911a8..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/AbstractMessageConsumeInterceptor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import java.util.List; -import org.apache.rocketmq.common.message.MessageExt; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link AbstractMessageConsumeInterceptor} create entry span when the consumeMessage in the {@link - * org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently} and {@link - * org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly} class. - * - * @author zhangxin - */ -public abstract class AbstractMessageConsumeInterceptor implements InstanceMethodsAroundInterceptor { - - public static final String COMSUMER_OPERATION_NAME_PREFIX = "RocketMQ/"; - - @Override - public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - List msgs = (List)allArguments[0]; - - ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0)); - AbstractSpan span = ContextManager.createEntrySpan(COMSUMER_OPERATION_NAME_PREFIX + msgs.get(0).getTopic() + "/Consumer", contextCarrier); - - span.setComponent(ComponentsDefine.ROCKET_MQ); - span.setLayer(SpanLayer.MQ); - for (int i = 1; i < msgs.size(); i++) { - ContextManager.extract(getContextCarrierFromMessage(msgs.get(i))); - } - - } - - @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } - - private ContextCarrier getContextCarrierFromMessage(MessageExt message) { - ContextCarrier contextCarrier = new ContextCarrier(); - - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(message.getUserProperty(next.getHeadKey())); - } - - return contextCarrier; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java deleted file mode 100644 index 3e78b843c97c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageConcurrentlyConsumeInterceptor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -/** - * {@link MessageConcurrentlyConsumeInterceptor} set the process status after the {@link - * org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List, - * org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method execute. - * - * @author zhang xin - */ -public class MessageConcurrentlyConsumeInterceptor extends AbstractMessageConsumeInterceptor { - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ConsumeConcurrentlyStatus status = (ConsumeConcurrentlyStatus)ret; - if (status == ConsumeConcurrentlyStatus.RECONSUME_LATER) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.errorOccurred(); - Tags.STATUS_CODE.set(activeSpan, status.name()); - } - ContextManager.stopSpan(); - return ret; - } -} - diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java deleted file mode 100644 index db303cfd6afe..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageOrderlyConsumeInterceptor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -/** - * {@link MessageOrderlyConsumeInterceptor} set the process status after the {@link - * org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List, - * org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method execute. - * - * @author zhang xin - */ -public class MessageOrderlyConsumeInterceptor extends AbstractMessageConsumeInterceptor { - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - - ConsumeOrderlyStatus status = (ConsumeOrderlyStatus)ret; - if (status == ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.errorOccurred(); - Tags.STATUS_CODE.set(activeSpan, status.name()); - } - ContextManager.stopSpan(); - return ret; - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java deleted file mode 100644 index 39ea4fd8ad6d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import org.apache.rocketmq.client.impl.CommunicationMode; -import org.apache.rocketmq.common.message.Message; -import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; -import org.skywalking.apm.util.StringUtil; - -import static org.apache.rocketmq.common.message.MessageDecoder.NAME_VALUE_SEPARATOR; -import static org.apache.rocketmq.common.message.MessageDecoder.PROPERTY_SEPARATOR; - -/** - * {@link MessageSendInterceptor} create exit span when the method {@link org.apache.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String, - * String, Message, org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader, long, - * org.apache.rocketmq.client.impl.CommunicationMode, org.apache.rocketmq.client.producer.SendCallback, - * org.apache.rocketmq.client.impl.producer.TopicPublishInfo, org.apache.rocketmq.client.impl.factory.MQClientInstance, - * int, org.apache.rocketmq.client.hook.SendMessageContext, org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl)} - * execute. - * - * @author zhang xin - */ -public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor { - - public static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/"; - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Message message = (Message)allArguments[2]; - ContextCarrier contextCarrier = new ContextCarrier(); - String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField()); - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress); - span.setComponent(ComponentsDefine.ROCKET_MQ); - span.setLayer(SpanLayer.MQ); - span.tag("brokerName", (String)allArguments[1]); - span.tag("tags", message.getTags()); - span.tag("communication.mode", ((CommunicationMode)allArguments[5]).name()); - - SendMessageRequestHeader requestHeader = (SendMessageRequestHeader)allArguments[3]; - StringBuilder properties = new StringBuilder(requestHeader.getProperties()); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - if (!StringUtil.isEmpty(next.getHeadValue())) { - properties.append(next.getHeadKey()); - properties.append(NAME_VALUE_SEPARATOR); - properties.append(next.getHeadValue()); - properties.append(PROPERTY_SEPARATOR); - } - } - requestHeader.setProperties(properties.toString()); - - if (allArguments[6] != null) { - ((EnhancedInstance)allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager.capture())); - } - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } - - private String buildOperationName(String topicName) { - return ASYNC_SEND_OPERATION_NAME_PREFIX + topicName + "/Producer"; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java deleted file mode 100644 index 2294ddd92330..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; - -/** - * {@link OnExceptionInterceptor} create local span when the method {@link org.apache.rocketmq.client.producer.SendCallback#onException(Throwable)} - * execute. - * - * @author zhang xin - */ -public class OnExceptionInterceptor implements InstanceMethodsAroundInterceptor { - - public static final String CALLBACK_OPERATION_NAME_PREFIX = "RocketMQ/"; - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo)objInst.getSkyWalkingDynamicField(); - AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback"); - activeSpan.setComponent(ComponentsDefine.ROCKET_MQ); - activeSpan.errorOccurred().log((Throwable)allArguments[0]); - ContextManager.continued(enhanceInfo.getContextSnapshot()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java deleted file mode 100644 index d6386ebb546b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import org.apache.rocketmq.client.producer.SendResult; -import org.apache.rocketmq.client.producer.SendStatus; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; - -/** - * {@link OnSuccessInterceptor} create local span when the method {@link org.apache.rocketmq.client.producer.SendCallback#onSuccess(SendResult)} - * execute. - * - * @author zhang xin - */ -public class OnSuccessInterceptor implements InstanceMethodsAroundInterceptor { - - public static final String CALLBACK_OPERATION_NAME_PREFIX = "RocketMQ/"; - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo)objInst.getSkyWalkingDynamicField(); - AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback"); - activeSpan.setComponent(ComponentsDefine.ROCKET_MQ); - SendStatus sendStatus = ((SendResult)allArguments[0]).getSendStatus(); - if (sendStatus != SendStatus.SEND_OK) { - activeSpan.errorOccurred(); - Tags.STATUS_CODE.set(activeSpan, sendStatus.name()); - } - ContextManager.continued(enhanceInfo.getContextSnapshot()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java deleted file mode 100644 index 4388d890542c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/UpdateNameServerInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class UpdateNameServerInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - objInst.setSkyWalkingDynamicField(allArguments[0]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java deleted file mode 100644 index b30ef139a82b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageConcurrentlyInstrumentation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; - -/** - * {@link ConsumeMessageConcurrentlyInstrumentation} intercepts the {@link org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List, - * org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method by using {@link - * org.skywalking.apm.plugin.rocketMQ.v4.MessageConcurrentlyConsumeInterceptor}. - * - * @author zhang xin - */ -public class ConsumeMessageConcurrentlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently"; - private static final String CONSUMER_MESSAGE_METHOD = "consumeMessage"; - private static final String INTERCEPTOR_CLASS = "org.apache.rocketmq.common.message.MessageConcurrentlyConsumeInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CONSUMER_MESSAGE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byHierarchyMatch(new String[] {ENHANCE_CLASS}); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java deleted file mode 100644 index 48f64b219fbe..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/ConsumeMessageOrderlyInstrumentation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; - -/** - * {@link ConsumeMessageOrderlyInstrumentation} intercepts the {@link org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List, - * org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method by using {@link - * org.skywalking.apm.plugin.rocketMQ.v4.MessageConcurrentlyConsumeInterceptor}. - * - * @author zhang xin - */ -public class ConsumeMessageOrderlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly"; - private static final String ENHANCE_METHOD = "consumeMessage"; - private static final String INTERCEPTOR_CLASS = "org.apache.rocketmq.common.message.MessageOrderlyConsumeInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byHierarchyMatch(new String[] {ENHANCE_CLASS}); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java deleted file mode 100644 index d0eb6d17b221..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/MQClientAPIImplInstrumentation.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link MQClientAPIImplInstrumentation} intercepts the {@link org.apache.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String, - * String, org.apache.rocketmq.common.message.Message, org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader, - * long, org.apache.rocketmq.client.impl.CommunicationMode, org.apache.rocketmq.client.producer.SendCallback, - * org.apache.rocketmq.client.impl.producer.TopicPublishInfo, org.apache.rocketmq.client.impl.factory.MQClientInstance, - * int, org.apache.rocketmq.client.hook.SendMessageContext, org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl)} - * method by using {@link org.skywalking.apm.plugin.rocketMQ.v4.MessageSendInterceptor}. - * - * @author zhang xin - */ -public class MQClientAPIImplInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.impl.MQClientAPIImpl"; - private static final String SEND_MESSAGE_METHOD_NAME = "sendMessage"; - private static final String ASYNC_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.rocketMQ.v4.MessageSendInterceptor"; - public static final String UPDATE_NAME_SERVER_INTERCEPT_CLASS = "org.skywalking.apm.plugin.rocketMQ.v4.UpdateNameServerInterceptor"; - public static final String UPDATE_NAME_SERVER_METHOD_NAME = "updateNameServerAddressList"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(SEND_MESSAGE_METHOD_NAME).and(takesArguments(12)); - } - - @Override public String getMethodsInterceptor() { - return ASYNC_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(UPDATE_NAME_SERVER_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return UPDATE_NAME_SERVER_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java deleted file mode 100644 index cc35cf57fa71..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallBackEnhanceInfo.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4.define; - -import org.skywalking.apm.agent.core.context.ContextSnapshot; - -/** - * {@link SendCallBackEnhanceInfo} saves the topic Id and {@link ContextSnapshot} instance for trace. - * - * @author zhang xin - */ -public class SendCallBackEnhanceInfo { - private String topicId; - private ContextSnapshot contextSnapshot; - - public SendCallBackEnhanceInfo(String topicId, ContextSnapshot contextSnapshot) { - this.topicId = topicId; - this.contextSnapshot = contextSnapshot; - } - - public String getTopicId() { - return topicId; - } - - public ContextSnapshot getContextSnapshot() { - return contextSnapshot; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java deleted file mode 100644 index 8ae5508341e7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/skywalking/apm/plugin/rocketMQ/v4/define/SendCallbackInstrumentation.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.rocketmq.client.producer.SendResult; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; - -/** - * {@link SendCallbackInstrumentation} intercepts {@link org.apache.rocketmq.client.producer.SendCallback#onSuccess(SendResult)} - * method by using {@link org.skywalking.apm.plugin.rocketMQ.v4.OnSuccessInterceptor} and also intercepts {@link - * org.apache.rocketmq.client.producer.SendCallback#onException(Throwable)} by using {@link - * org.skywalking.apm.plugin.rocketMQ.v4.OnExceptionInterceptor}. - * - * @author zhang xin - */ -public class SendCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.producer.SendCallback"; - private static final String ON_SUCCESS_ENHANCE_METHOD = "onSuccess"; - private static final String ON_SUCCESS_INTERCEPTOR = "org.skywalking.apm.plugin.rocketMQ.v4.OnSuccessInterceptor"; - private static final String ON_EXCEPTION_METHOD = "onException"; - private static final String ON_EXCEPTION_INTERCEPTOR = "org.skywalking.apm.plugin.rocketMQ.v4.OnExceptionInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_SUCCESS_ENHANCE_METHOD).and(takesArgumentWithType(0, "org.apache.rocketmq.client.producer.SendResult")); - } - - @Override public String getMethodsInterceptor() { - return ON_SUCCESS_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ON_EXCEPTION_METHOD).and(takesArgumentWithType(0, "java.lang.Throwable")); - } - - @Override public String getMethodsInterceptor() { - return ON_EXCEPTION_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byHierarchyMatch(new String[] {ENHANCE_CLASS}); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/resources/skywalking-plugin.def index 1accc2bff023..bba21da0ad8a 100644 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -rocketMQ-4.x=org.skywalking.apm.plugin.rocketMQ.v4.define.ConsumeMessageConcurrentlyInstrumentation -rocketMQ-4.x=org.skywalking.apm.plugin.rocketMQ.v4.define.ConsumeMessageOrderlyInstrumentation -rocketMQ-4.x=org.skywalking.apm.plugin.rocketMQ.v4.define.MQClientAPIImplInstrumentation -rocketMQ-4.x=org.skywalking.apm.plugin.rocketMQ.v4.define.SendCallbackInstrumentation +rocketMQ-4.x=ConsumeMessageConcurrentlyInstrumentation +rocketMQ-4.x=ConsumeMessageOrderlyInstrumentation +rocketMQ-4.x=MQClientAPIImplInstrumentation +rocketMQ-4.x=SendCallbackInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java new file mode 100644 index 000000000000..84a110d9527b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.util.List; +import org.apache.rocketmq.client.impl.CommunicationMode; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MessageSendInterceptorTest { + + private MessageSendInterceptor messageSendInterceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private Object[] arguments; + + private Object[] argumentsWithoutCallback; + + @Mock + private Message message; + + @Mock + private SendMessageRequestHeader messageRequestHeader; + + @Mock + private EnhancedInstance callBack; + + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() { + messageSendInterceptor = new MessageSendInterceptor(); + enhancedInstance = new EnhancedInstance() { + @Override public Object getSkyWalkingDynamicField() { + return "127.0.0.1:6543"; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + }; + + arguments = new Object[] {"127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, callBack}; + argumentsWithoutCallback = new Object[] {"127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, null}; + when(messageRequestHeader.getProperties()).thenReturn(""); + when(message.getTags()).thenReturn("TagA"); + } + + @Test + public void testSendMessage() throws Throwable { + messageSendInterceptor.beforeMethod(enhancedInstance, null, arguments, null, null); + messageSendInterceptor.afterMethod(enhancedInstance, null, arguments, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan mqSpan = spans.get(0); + + SpanAssert.assertLayer(mqSpan, SpanLayer.MQ); + SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ); + SpanAssert.assertTag(mqSpan, 0, "test"); + SpanAssert.assertTag(mqSpan, 1, "TagA"); + verify(messageRequestHeader, times(1)).setProperties(anyString()); + verify(callBack, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testSendMessageWithoutCallBack() throws Throwable { + messageSendInterceptor.beforeMethod(enhancedInstance, null, argumentsWithoutCallback, null, null); + messageSendInterceptor.afterMethod(enhancedInstance, null, argumentsWithoutCallback, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan mqSpan = spans.get(0); + + SpanAssert.assertLayer(mqSpan, SpanLayer.MQ); + SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ); + SpanAssert.assertTag(mqSpan, 0, "test"); + SpanAssert.assertTag(mqSpan, 1, "TagA"); + verify(messageRequestHeader, times(1)).setProperties(anyString()); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java new file mode 100644 index 000000000000..5e3f0598dd3c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class OnExceptionInterceptorTest { + + private OnExceptionInterceptor exceptionInterceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private ContextSnapshot contextSnapshot; + private SendCallBackEnhanceInfo enhanceInfo; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() { + exceptionInterceptor = new OnExceptionInterceptor(); + + enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot); + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo); + } + + @Test + public void testOnException() throws Throwable { + exceptionInterceptor.beforeMethod(enhancedInstance, null, new Object[] {new RuntimeException()}, null, null); + exceptionInterceptor.afterMethod(enhancedInstance, null, new Object[] {new RuntimeException()}, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan exceptionSpan = spans.get(0); + SpanAssert.assertException(SpanHelper.getLogs(exceptionSpan).get(0), RuntimeException.class); + SpanAssert.assertOccurException(exceptionSpan, true); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java new file mode 100644 index 000000000000..044310ced313 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.rocketMQ.v4; + +import java.util.List; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.SendStatus; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class OnSuccessInterceptorTest { + + private OnSuccessInterceptor successInterceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private ContextSnapshot contextSnapshot; + @Mock + private SendResult sendResult; + + private SendCallBackEnhanceInfo enhanceInfo; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() { + successInterceptor = new OnSuccessInterceptor(); + + enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot); + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo); + when(sendResult.getSendStatus()).thenReturn(SendStatus.SEND_OK); + } + + @Test + public void testOnSuccess() throws Throwable { + successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); + successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan successSpan = spans.get(0); + + SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ); + + } + + @Test + public void testOnSuccessWithErrorStatus() throws Throwable { + when(sendResult.getSendStatus()).thenReturn(SendStatus.FLUSH_SLAVE_TIMEOUT); + successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); + successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan successSpan = spans.get(0); + + SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ); + SpanAssert.assertOccurException(successSpan, true); + + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java deleted file mode 100644 index 4ded3af74002..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptorTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.util.List; -import org.apache.rocketmq.client.impl.CommunicationMode; -import org.apache.rocketmq.common.message.Message; -import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.SpanAssert; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class MessageSendInterceptorTest { - - private MessageSendInterceptor messageSendInterceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private Object[] arguments; - - private Object[] argumentsWithoutCallback; - - @Mock - private Message message; - - @Mock - private SendMessageRequestHeader messageRequestHeader; - - @Mock - private EnhancedInstance callBack; - - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() { - messageSendInterceptor = new MessageSendInterceptor(); - enhancedInstance = new EnhancedInstance() { - @Override public Object getSkyWalkingDynamicField() { - return "127.0.0.1:6543"; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - - } - }; - - arguments = new Object[] {"127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, callBack}; - argumentsWithoutCallback = new Object[] {"127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, null}; - when(messageRequestHeader.getProperties()).thenReturn(""); - when(message.getTags()).thenReturn("TagA"); - } - - @Test - public void testSendMessage() throws Throwable { - messageSendInterceptor.beforeMethod(enhancedInstance, null, arguments, null, null); - messageSendInterceptor.afterMethod(enhancedInstance, null, arguments, null, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan mqSpan = spans.get(0); - - SpanAssert.assertLayer(mqSpan, SpanLayer.MQ); - SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ); - SpanAssert.assertTag(mqSpan, 0, "test"); - SpanAssert.assertTag(mqSpan, 1, "TagA"); - verify(messageRequestHeader, times(1)).setProperties(anyString()); - verify(callBack, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } - - @Test - public void testSendMessageWithoutCallBack() throws Throwable { - messageSendInterceptor.beforeMethod(enhancedInstance, null, argumentsWithoutCallback, null, null); - messageSendInterceptor.afterMethod(enhancedInstance, null, argumentsWithoutCallback, null, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan mqSpan = spans.get(0); - - SpanAssert.assertLayer(mqSpan, SpanLayer.MQ); - SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ); - SpanAssert.assertTag(mqSpan, 0, "test"); - SpanAssert.assertTag(mqSpan, 1, "TagA"); - verify(messageRequestHeader, times(1)).setProperties(anyString()); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java deleted file mode 100644 index b19428a014ab..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnExceptionInterceptorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.SpanAssert; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class OnExceptionInterceptorTest { - - private OnExceptionInterceptor exceptionInterceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private ContextSnapshot contextSnapshot; - private SendCallBackEnhanceInfo enhanceInfo; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() { - exceptionInterceptor = new OnExceptionInterceptor(); - - enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot); - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo); - } - - @Test - public void testOnException() throws Throwable { - exceptionInterceptor.beforeMethod(enhancedInstance, null, new Object[] {new RuntimeException()}, null, null); - exceptionInterceptor.afterMethod(enhancedInstance, null, new Object[] {new RuntimeException()}, null, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan exceptionSpan = spans.get(0); - SpanAssert.assertException(SpanHelper.getLogs(exceptionSpan).get(0), RuntimeException.class); - SpanAssert.assertOccurException(exceptionSpan, true); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java deleted file mode 100644 index 7e5d0cf90da2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/test/java/org/skywalking/apm/plugin/rocketMQ/v4/OnSuccessInterceptorTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.rocketMQ.v4; - -import java.util.List; -import org.apache.rocketmq.client.producer.SendResult; -import org.apache.rocketmq.client.producer.SendStatus; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.SpanAssert; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class OnSuccessInterceptorTest { - - private OnSuccessInterceptor successInterceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private ContextSnapshot contextSnapshot; - @Mock - private SendResult sendResult; - - private SendCallBackEnhanceInfo enhanceInfo; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() { - successInterceptor = new OnSuccessInterceptor(); - - enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot); - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo); - when(sendResult.getSendStatus()).thenReturn(SendStatus.SEND_OK); - } - - @Test - public void testOnSuccess() throws Throwable { - successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); - successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan successSpan = spans.get(0); - - SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ); - - } - - @Test - public void testOnSuccessWithErrorStatus() throws Throwable { - when(sendResult.getSendStatus()).thenReturn(SendStatus.FLUSH_SLAVE_TIMEOUT); - successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); - successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan successSpan = spans.get(0); - - SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ); - SpanAssert.assertOccurException(successSpan, true); - - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java new file mode 100644 index 000000000000..a4e0ce62bb88 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.sjdbc; + +import com.dangdang.ddframe.rdb.sharding.executor.event.AbstractExecutionEvent; +import com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent; +import com.dangdang.ddframe.rdb.sharding.executor.event.DQLExecutionEvent; +import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap; +import com.dangdang.ddframe.rdb.sharding.util.EventBusInstance; +import com.google.common.base.Joiner; +import com.google.common.eventbus.AllowConcurrentEvents; +import com.google.common.eventbus.Subscribe; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; + +/** + * Sharding-jdbc provides {@link EventBusInstance} to help external systems getDefault events of sql execution. + * {@link ExecuteEventListener} can getDefault sql statement start and end events, resulting in db span. + * + * @author gaohongtao + */ +public class ExecuteEventListener { + + public static void init() { + EventBusInstance.getInstance().register(new ExecuteEventListener()); + } + + @Subscribe + @AllowConcurrentEvents + public void listenDML(DMLExecutionEvent event) { + handle(event, "MODIFY"); + } + + @Subscribe + @AllowConcurrentEvents + public void listenDQL(DQLExecutionEvent event) { + handle(event, "QUERY"); + } + + private void handle(AbstractExecutionEvent event, String operation) { + switch (event.getEventExecutionType()) { + case BEFORE_EXECUTE: + AbstractSpan span = ContextManager.createExitSpan("/SJDBC/BRANCH/" + operation, event.getDataSource()); + if (ExecutorDataMap.getDataMap().containsKey(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)) { + ContextManager.continued((ContextSnapshot)ExecutorDataMap.getDataMap().get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)); + } + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, event.getDataSource()); + Tags.DB_STATEMENT.set(span, event.getSql()); + if (!event.getParameters().isEmpty()) { + Tags.DB_BIND_VARIABLES.set(span, Joiner.on(",").join(event.getParameters())); + } + span.setComponent(ComponentsDefine.SHARDING_JDBC); + SpanLayer.asDB(span); + break; + case EXECUTE_FAILURE: + span = ContextManager.activeSpan(); + span.errorOccurred(); + if (event.getException().isPresent()) { + span.log(event.getException().get()); + } + case EXECUTE_SUCCESS: + ContextManager.stopSpan(); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java new file mode 100644 index 000000000000..01d8d020908f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.sjdbc.define; + +import com.dangdang.ddframe.rdb.sharding.constant.SQLType; +import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback; +import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap; +import java.util.Collection; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +import java.lang.reflect.Method; + +/** + * {@link AsyncExecuteInterceptor} enhances {@link com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine#asyncExecute(SQLType, Collection, List, ExecuteCallback)} + * so that the sql executor can get a {@link ContextSnapshot} of main thread when it is executed asynchronously. + * + * @author gaohongtao + */ +public class AsyncExecuteInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String SNAPSHOT_DATA_KEY = "APM_SKYWALKING_SNAPSHOT_DATA"; + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ExecutorDataMap.getDataMap().put(SNAPSHOT_DATA_KEY, ContextManager.capture()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } +} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java new file mode 100644 index 000000000000..51ae62b9be3f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.sjdbc.define; + +import com.dangdang.ddframe.rdb.sharding.constant.SQLType; +import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.List; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link ExecuteInterceptor} enhances {@link com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine#execute(SQLType, Collection, List, ExecuteCallback)} + * ,creating a local span that records the overall execution of sql + * + * @author gaohongtao + */ +public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + SQLType sqlType = (SQLType)allArguments[0]; + ContextManager.createLocalSpan("/SJDBC/TRUNK/" + sqlType.name()).setComponent(ComponentsDefine.SHARDING_JDBC); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java new file mode 100644 index 000000000000..392a4c28cf4f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.sjdbc.define; + +import com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.sjdbc.ExecuteEventListener; + +/** + * {@link ExecutorEngineConstructorInterceptor} enhances {@link ExecutorEngine#}'s constructor, initializing {@link ExecuteEventListener} + * + * @author gaohongtao + */ +public class ExecutorEngineConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + ExecuteEventListener.init(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java new file mode 100644 index 000000000000..b6a60f551035 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.sjdbc.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ExecutorInstrumentation} presents that skywalking intercepts {@link com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine}. + * + * @author gaohongtao + */ +public class ExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine"; + + private static final String EXECUTOR_ENGINE_CONSTRUCTOR_INTERCEPTOR_CLASS = "ExecutorEngineConstructorInterceptor"; + + private static final String EXECUTE_INTERCEPTOR_CLASS = "ExecuteInterceptor"; + + private static final String ASYNC_EXECUTE_INTERCEPTOR_CLASS = "AsyncExecuteInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return EXECUTOR_ENGINE_CONSTRUCTOR_INTERCEPTOR_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override + public String getMethodsInterceptor() { + return EXECUTE_INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("asyncExecute"); + } + + @Override + public String getMethodsInterceptor() { + return ASYNC_EXECUTE_INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java deleted file mode 100644 index 7846bad13996..000000000000 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.sjdbc; - -import com.dangdang.ddframe.rdb.sharding.executor.event.AbstractExecutionEvent; -import com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent; -import com.dangdang.ddframe.rdb.sharding.executor.event.DQLExecutionEvent; -import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap; -import com.dangdang.ddframe.rdb.sharding.util.EventBusInstance; -import com.google.common.base.Joiner; -import com.google.common.eventbus.AllowConcurrentEvents; -import com.google.common.eventbus.Subscribe; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor; - -/** - * Sharding-jdbc provides {@link EventBusInstance} to help external systems getDefault events of sql execution. - * {@link ExecuteEventListener} can getDefault sql statement start and end events, resulting in db span. - * - * @author gaohongtao - */ -public class ExecuteEventListener { - - public static void init() { - EventBusInstance.getInstance().register(new ExecuteEventListener()); - } - - @Subscribe - @AllowConcurrentEvents - public void listenDML(DMLExecutionEvent event) { - handle(event, "MODIFY"); - } - - @Subscribe - @AllowConcurrentEvents - public void listenDQL(DQLExecutionEvent event) { - handle(event, "QUERY"); - } - - private void handle(AbstractExecutionEvent event, String operation) { - switch (event.getEventExecutionType()) { - case BEFORE_EXECUTE: - AbstractSpan span = ContextManager.createExitSpan("/SJDBC/BRANCH/" + operation, event.getDataSource()); - if (ExecutorDataMap.getDataMap().containsKey(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)) { - ContextManager.continued((ContextSnapshot)ExecutorDataMap.getDataMap().get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)); - } - Tags.DB_TYPE.set(span, "sql"); - Tags.DB_INSTANCE.set(span, event.getDataSource()); - Tags.DB_STATEMENT.set(span, event.getSql()); - if (!event.getParameters().isEmpty()) { - Tags.DB_BIND_VARIABLES.set(span, Joiner.on(",").join(event.getParameters())); - } - span.setComponent(ComponentsDefine.SHARDING_JDBC); - SpanLayer.asDB(span); - break; - case EXECUTE_FAILURE: - span = ContextManager.activeSpan(); - span.errorOccurred(); - if (event.getException().isPresent()) { - span.log(event.getException().get()); - } - case EXECUTE_SUCCESS: - ContextManager.stopSpan(); - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java deleted file mode 100644 index 36bfdc4a4b98..000000000000 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.sjdbc.define; - -import com.dangdang.ddframe.rdb.sharding.constant.SQLType; -import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback; -import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap; -import java.util.Collection; -import java.util.List; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -import java.lang.reflect.Method; - -/** - * {@link AsyncExecuteInterceptor} enhances {@link com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine#asyncExecute(SQLType, Collection, List, ExecuteCallback)} - * so that the sql executor can get a {@link ContextSnapshot} of main thread when it is executed asynchronously. - * - * @author gaohongtao - */ -public class AsyncExecuteInterceptor implements InstanceMethodsAroundInterceptor { - - public static final String SNAPSHOT_DATA_KEY = "APM_SKYWALKING_SNAPSHOT_DATA"; - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ExecutorDataMap.getDataMap().put(SNAPSHOT_DATA_KEY, ContextManager.capture()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - } -} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java deleted file mode 100644 index a8051d629d23..000000000000 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.sjdbc.define; - -import com.dangdang.ddframe.rdb.sharding.constant.SQLType; -import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.List; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link ExecuteInterceptor} enhances {@link com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine#execute(SQLType, Collection, List, ExecuteCallback)} - * ,creating a local span that records the overall execution of sql - * - * @author gaohongtao - */ -public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - SQLType sqlType = (SQLType)allArguments[0]; - ContextManager.createLocalSpan("/SJDBC/TRUNK/" + sqlType.name()).setComponent(ComponentsDefine.SHARDING_JDBC); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java deleted file mode 100644 index 01bbc65f5027..000000000000 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.sjdbc.define; - -import com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.plugin.sjdbc.ExecuteEventListener; - -/** - * {@link ExecutorEngineConstructorInterceptor} enhances {@link ExecutorEngine#}'s constructor, initializing {@link ExecuteEventListener} - * - * @author gaohongtao - */ -public class ExecutorEngineConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - ExecuteEventListener.init(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java deleted file mode 100644 index 4aab9241ff40..000000000000 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.sjdbc.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link ExecutorInstrumentation} presents that skywalking intercepts {@link com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine}. - * - * @author gaohongtao - */ -public class ExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine"; - - private static final String EXECUTOR_ENGINE_CONSTRUCTOR_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.sjdbc.define.ExecutorEngineConstructorInterceptor"; - - private static final String EXECUTE_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.sjdbc.define.ExecuteInterceptor"; - - private static final String ASYNC_EXECUTE_INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return EXECUTOR_ENGINE_CONSTRUCTOR_INTERCEPTOR_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{ - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override - public String getMethodsInterceptor() { - return EXECUTE_INTERCEPTOR_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("asyncExecute"); - } - - @Override - public String getMethodsInterceptor() { - return ASYNC_EXECUTE_INTERCEPTOR_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/resources/skywalking-plugin.def index c30d53853bc6..56f3301f6009 100644 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -sharding-jdbc-1.5.x=org.skywalking.apm.plugin.sjdbc.define.ExecutorInstrumentation \ No newline at end of file +sharding-jdbc-1.5.x=ExecutorInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/sjdbc/InterceptorTest.java similarity index 78% rename from apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/sjdbc/InterceptorTest.java index 463a059ae111..2a6e53b4abbb 100644 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/sjdbc/InterceptorTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.sjdbc; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.sjdbc; import com.dangdang.ddframe.rdb.sharding.constant.SQLType; import com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent; @@ -32,6 +50,13 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor; +import org.apache.skywalking.apm.plugin.sjdbc.define.ExecutorEngineConstructorInterceptor; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -40,27 +65,18 @@ import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor; -import org.skywalking.apm.plugin.sjdbc.define.ExecuteInterceptor; -import org.skywalking.apm.plugin.sjdbc.define.ExecutorEngineConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.sjdbc.define.ExecuteInterceptor; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertOccurException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(TracingSegmentRunner.class) @@ -175,16 +191,16 @@ public void assertExecuteError() throws Throwable { private void assertSpan(AbstractTracingSpan span, int index) { assertComponent(span, ComponentsDefine.SHARDING_JDBC); - assertLayer(span, SpanLayer.DB); - assertTag(span, 0, "sql"); - assertTag(span, 1, "ds_" + index); - assertTag(span, 2, "select * from t_order_" + index); + SpanAssert.assertLayer(span, SpanLayer.DB); + SpanAssert.assertTag(span, 0, "sql"); + SpanAssert.assertTag(span, 1, "ds_" + index); + SpanAssert.assertTag(span, 2, "select * from t_order_" + index); assertThat(span.isExit(), is(true)); assertThat(span.getOperationName(), is("/SJDBC/BRANCH/QUERY")); } private void assertErrorSpan(AbstractTracingSpan span) { - assertOccurException(span, true); + SpanAssert.assertOccurException(span, true); } private void sendEvent(String datasource, String sql) { diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java new file mode 100644 index 000000000000..499a09b7e6e7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent; + +import java.lang.reflect.Method; +import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class FailureCallbackInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); + if (cacheValues == null) { + return; + } + + URI uri = (URI)cacheValues[0]; + AbstractSpan span = ContextManager.createLocalSpan("future/failureCallback:" + uri.getPath()); + span.errorOccurred().log((Throwable)allArguments[0]).setComponent(ComponentsDefine.SPRING_REST_TEMPLATE).setLayer(SpanLayer.HTTP); + Tags.URL.set(span, uri.getPath()); + ContextManager.continued((ContextSnapshot)cacheValues[2]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java new file mode 100644 index 000000000000..b15d60b53850 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent; + +import java.lang.reflect.Method; +import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class SuccessCallbackInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); + if (cacheValues == null) { + return; + } + + URI uri = (URI)cacheValues[0]; + AbstractSpan span = ContextManager.createLocalSpan("future/successCallback:" + uri.getPath()); + span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE).setLayer(SpanLayer.HTTP); + Tags.URL.set(span, uri.getPath()); + ContextManager.continued((ContextSnapshot)cacheValues[2]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java new file mode 100644 index 000000000000..69f798d200a9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.concurrent.FailureCallbackInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.spring.concurrent.match.FailedCallbackMatch.failedCallbackMatch; + +/** + * {@link FailureCallbackInstrumentation} enhance the onFailure method that class inherited + * org.springframework.util.concurrent.FailureCallback by {@link FailureCallbackInterceptor}. + * + * @author zhangxin + */ +public class FailureCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String FAILURE_CALLBACK_INTERCEPTOR = "FailureCallbackInterceptor"; + public static final String FAILURE_METHOD_NAME = "onFailure"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(FAILURE_METHOD_NAME); + } + + @Override + public String getMethodsInterceptor() { + return FAILURE_CALLBACK_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return failedCallbackMatch(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java new file mode 100644 index 000000000000..fd3639ce2caf --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.concurrent.match.ListenableFutureCallbackMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ListenableFutureCallbackInstrumentation} enhance onSuccess method and oonFailure + * that class inherited org.springframework.util.concurrent.ListenableFutureCallback by + * SuccessCallbackInterceptor and + * FailureCallbackInterceptor. + * + * @author zhangxin + */ +public class ListenableFutureCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(SuccessCallbackInstrumentation.SUCCESS_METHOD_NAME); + } + + @Override + public String getMethodsInterceptor() { + return SuccessCallbackInstrumentation.SUCCESS_CALLBACK_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(FailureCallbackInstrumentation.FAILURE_METHOD_NAME); + } + + @Override + public String getMethodsInterceptor() { + return FailureCallbackInstrumentation.FAILURE_CALLBACK_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return ListenableFutureCallbackMatch.listenableFutureCallbackMatch(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java new file mode 100644 index 000000000000..0401167a98ad --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.spring.concurrent.match.SuccessCallbackMatch.successCallbackMatch; + +/** + * {@link SuccessCallbackInstrumentation} enhance the onSuccess method that class inherited + * org.springframework.util.concurrent.SuccessCallback by SuccessCallbackInterceptor. + * + * @author zhangxin + */ +public class SuccessCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String SUCCESS_CALLBACK_INTERCEPTOR = + "SuccessCallbackInterceptor"; + public static final String SUCCESS_METHOD_NAME = "onSuccess"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(SUCCESS_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return SUCCESS_CALLBACK_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return successCallbackMatch(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java similarity index 78% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java rename to apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java index 7c6b31b241d0..537beba69485 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/EitherInterfaceMatch.java @@ -16,11 +16,29 @@ * */ -package org.skywalking.apm.plugin.spring.concurrent.match; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.match; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.match.IndirectMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java new file mode 100644 index 000000000000..34235068074c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.match; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +/** + * {@link FailedCallbackMatch} match the class that inherited org.springframework.util.concurrent.FailureCallback + * and not inherited org.springframework.util.concurrent.SuccessCallback + * + * @author zhangxin + */ +public class FailedCallbackMatch extends EitherInterfaceMatch { + + private static final String MATCH_INTERFACE = "org.springframework.util.concurrent.FailureCallback"; + private static final String MUTEX_INTERFACE = "org.springframework.util.concurrent.SuccessCallback"; + + private FailedCallbackMatch() { + + } + + @Override public String getMatchInterface() { + return MATCH_INTERFACE; + } + + @Override public String getMutexInterface() { + return MUTEX_INTERFACE; + } + + public static ClassMatch failedCallbackMatch() { + return new FailedCallbackMatch(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java similarity index 75% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java rename to apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java index b2b37caedd71..fe85f65210c0 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/ListenableFutureCallbackMatch.java @@ -16,12 +16,30 @@ * */ -package org.skywalking.apm.plugin.spring.concurrent.match; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.match; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.agent.core.plugin.match.IndirectMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java new file mode 100644 index 000000000000..a25cc1ac778d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.concurrent.match; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +/** + * {@link SuccessCallbackMatch} match the class that inherited org.springframework.util.concurrent.SuccessCallback + * and not inherited org.springframework.util.concurrent.FailureCallback + * + * @author zhangxin + */ +public class SuccessCallbackMatch extends EitherInterfaceMatch { + + private static final String MATCH_INTERFACE = "org.springframework.util.concurrent.SuccessCallback"; + private static final String MUTEX_INTERFACE = "org.springframework.util.concurrent.FailureCallback"; + + private SuccessCallbackMatch() { + } + + @Override + public String getMatchInterface() { + return MATCH_INTERFACE; + } + + @Override + public String getMutexInterface() { + return MUTEX_INTERFACE; + } + + public static ClassMatch successCallbackMatch() { + return new SuccessCallbackMatch(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java deleted file mode 100644 index 9eacc812d107..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent; - -import java.lang.reflect.Method; -import java.net.URI; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class FailureCallbackInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); - if (cacheValues == null) { - return; - } - - URI uri = (URI)cacheValues[0]; - AbstractSpan span = ContextManager.createLocalSpan("future/failureCallback:" + uri.getPath()); - span.errorOccurred().log((Throwable)allArguments[0]).setComponent(ComponentsDefine.SPRING_REST_TEMPLATE).setLayer(SpanLayer.HTTP); - Tags.URL.set(span, uri.getPath()); - ContextManager.continued((ContextSnapshot)cacheValues[2]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java deleted file mode 100644 index f18768ff30d1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent; - -import java.lang.reflect.Method; -import java.net.URI; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class SuccessCallbackInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); - if (cacheValues == null) { - return; - } - - URI uri = (URI)cacheValues[0]; - AbstractSpan span = ContextManager.createLocalSpan("future/successCallback:" + uri.getPath()); - span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE).setLayer(SpanLayer.HTTP); - Tags.URL.set(span, uri.getPath()); - ContextManager.continued((ContextSnapshot)cacheValues[2]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java deleted file mode 100644 index f44fa9b70d04..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/FailureCallbackInstrumentation.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.spring.concurrent.FailureCallbackInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.spring.concurrent.match.FailedCallbackMatch.failedCallbackMatch; - -/** - * {@link FailureCallbackInstrumentation} enhance the onFailure method that class inherited - * org.springframework.util.concurrent.FailureCallback by {@link FailureCallbackInterceptor}. - * - * @author zhangxin - */ -public class FailureCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String FAILURE_CALLBACK_INTERCEPTOR = "org.skywalking.apm.plugin.spring.concurrent.FailureCallbackInterceptor"; - public static final String FAILURE_METHOD_NAME = "onFailure"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(FAILURE_METHOD_NAME); - } - - @Override - public String getMethodsInterceptor() { - return FAILURE_CALLBACK_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return failedCallbackMatch(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java deleted file mode 100644 index ae9d236e7563..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/ListenableFutureCallbackInstrumentation.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.spring.concurrent.match.ListenableFutureCallbackMatch.listenableFutureCallbackMatch; - -/** - * {@link ListenableFutureCallbackInstrumentation} enhance onSuccess method and oonFailure - * that class inherited org.springframework.util.concurrent.ListenableFutureCallback by - * org.skywalking.apm.plugin.spring.concurrent.SuccessCallbackInterceptor and - * org.skywalking.apm.plugin.spring.concurrent.FailureCallbackInterceptor. - * - * @author zhangxin - */ -public class ListenableFutureCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(SuccessCallbackInstrumentation.SUCCESS_METHOD_NAME); - } - - @Override - public String getMethodsInterceptor() { - return SuccessCallbackInstrumentation.SUCCESS_CALLBACK_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(FailureCallbackInstrumentation.FAILURE_METHOD_NAME); - } - - @Override - public String getMethodsInterceptor() { - return FailureCallbackInstrumentation.FAILURE_CALLBACK_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return listenableFutureCallbackMatch(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java deleted file mode 100644 index 4c8dec2d35f1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/define/SuccessCallbackInstrumentation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.spring.concurrent.match.SuccessCallbackMatch.successCallbackMatch; - -/** - * {@link SuccessCallbackInstrumentation} enhance the onSuccess method that class inherited - * org.springframework.util.concurrent.SuccessCallback by org.skywalking.apm.plugin.spring.concurrent.SuccessCallbackInterceptor. - * - * @author zhangxin - */ -public class SuccessCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String SUCCESS_CALLBACK_INTERCEPTOR = - "org.skywalking.apm.plugin.spring.concurrent.SuccessCallbackInterceptor"; - public static final String SUCCESS_METHOD_NAME = "onSuccess"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(SUCCESS_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return SUCCESS_CALLBACK_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return successCallbackMatch(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java deleted file mode 100644 index 054182605bf7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/FailedCallbackMatch.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent.match; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -/** - * {@link FailedCallbackMatch} match the class that inherited org.springframework.util.concurrent.FailureCallback - * and not inherited org.springframework.util.concurrent.SuccessCallback - * - * @author zhangxin - */ -public class FailedCallbackMatch extends EitherInterfaceMatch { - - private static final String MATCH_INTERFACE = "org.springframework.util.concurrent.FailureCallback"; - private static final String MUTEX_INTERFACE = "org.springframework.util.concurrent.SuccessCallback"; - - private FailedCallbackMatch() { - - } - - @Override public String getMatchInterface() { - return MATCH_INTERFACE; - } - - @Override public String getMutexInterface() { - return MUTEX_INTERFACE; - } - - public static ClassMatch failedCallbackMatch() { - return new FailedCallbackMatch(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java deleted file mode 100644 index 29072348d331..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/concurrent/match/SuccessCallbackMatch.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.concurrent.match; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -/** - * {@link SuccessCallbackMatch} match the class that inherited org.springframework.util.concurrent.SuccessCallback - * and not inherited org.springframework.util.concurrent.FailureCallback - * - * @author zhangxin - */ -public class SuccessCallbackMatch extends EitherInterfaceMatch { - - private static final String MATCH_INTERFACE = "org.springframework.util.concurrent.SuccessCallback"; - private static final String MUTEX_INTERFACE = "org.springframework.util.concurrent.FailureCallback"; - - private SuccessCallbackMatch() { - } - - @Override - public String getMatchInterface() { - return MATCH_INTERFACE; - } - - @Override - public String getMutexInterface() { - return MUTEX_INTERFACE; - } - - public static ClassMatch successCallbackMatch() { - return new SuccessCallbackMatch(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/resources/skywalking-plugin.def index 795a7685c6e4..67ab86c550df 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,3 +1,3 @@ -spring-concurrent-util-4.x=org.skywalking.apm.plugin.spring.concurrent.define.FailureCallbackInstrumentation -spring-concurrent-util-4.x=org.skywalking.apm.plugin.spring.concurrent.define.SuccessCallbackInstrumentation -spring-concurrent-util-4.x=org.skywalking.apm.plugin.spring.concurrent.define.ListenableFutureCallbackInstrumentation +spring-concurrent-util-4.x=FailureCallbackInstrumentation +spring-concurrent-util-4.x=SuccessCallbackInstrumentation +spring-concurrent-util-4.x=ListenableFutureCallbackInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java similarity index 80% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java index 876b0df4926b..8e1084af6f3b 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.spring.patch; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.patch; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -25,10 +43,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; /** * {@link AutowiredAnnotationProcessorInterceptor} return the correct constructor when the bean class is enhanced by diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java new file mode 100644 index 000000000000..6313cfe64079 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.patch; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.aop.framework.AdvisedSupport; + +/** + * CreateAopProxyInterceptor check that the bean has been implement {@link EnhancedInstance}.

+ * if yes, true will be returned. + * + * @author zhang xin + */ +public class CreateAopProxyInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + AdvisedSupport advisedSupport = (AdvisedSupport)allArguments[0]; + + if (EnhancedInstance.class.isAssignableFrom(advisedSupport.getTargetClass())) { + return true; + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java new file mode 100644 index 000000000000..d03ee2a36222 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.patch.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AopProxyFactoryInstrumentation} indicate that spring core patch plugin intercepts the {@link + * org.springframework.aop.framework.DefaultAopProxyFactory#hasNoUserSuppliedProxyInterfaces} method by using {@link + * org.apache.skywalking.apm.plugin.spring.patch.CreateAopProxyInterceptor} class. + * + * @author zhangxin + */ +public class AopProxyFactoryInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.springframework.aop.framework.DefaultAopProxyFactory"; + public static final String ENHANCE_METHOD = "hasNoUserSuppliedProxyInterfaces"; + public static final String INTERCEPT_CLASS = "CreateAopProxyInterceptor"; + + @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java new file mode 100644 index 000000000000..818c8bc727d8 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.patch.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AutowiredAnnotationProcessorInstrumentation} indicates a spring core class patch for making sure the + * determineCandidateConstructors method in the class {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor} + * works in spring designed ways + * + * @author zhang xin + */ +public class AutowiredAnnotationProcessorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"; + private static final String ENHANCE_METHOD = "determineCandidateConstructors"; + private static final String INTERCEPTOR_CLASS = "AutowiredAnnotationProcessorInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return INTERCEPTOR_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java deleted file mode 100644 index beed2fd45abc..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.patch; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.springframework.aop.framework.AdvisedSupport; - -/** - * {@link CreateAopProxyInterceptor} check that the bean has been implement {@link EnhancedInstance}.

- * if yes, true will be returned. - * - * @author zhang xin - */ -public class CreateAopProxyInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - AdvisedSupport advisedSupport = (AdvisedSupport)allArguments[0]; - - if (EnhancedInstance.class.isAssignableFrom(advisedSupport.getTargetClass())) { - return true; - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java deleted file mode 100644 index 9f9d9436cd2e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AopProxyFactoryInstrumentation.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.patch.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link AopProxyFactoryInstrumentation} indicate that spring core patch plugin intercepts the {@link - * org.springframework.aop.framework.DefaultAopProxyFactory#hasNoUserSuppliedProxyInterfaces} method by using {@link - * org.skywalking.apm.plugin.spring.patch.CreateAopProxyInterceptor} class. - * - * @author zhangxin - */ -public class AopProxyFactoryInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.springframework.aop.framework.DefaultAopProxyFactory"; - public static final String ENHANCE_METHOD = "hasNoUserSuppliedProxyInterfaces"; - public static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.spring.patch.CreateAopProxyInterceptor"; - - @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java deleted file mode 100644 index 6766016fe854..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/skywalking/apm/plugin/spring/patch/define/AutowiredAnnotationProcessorInstrumentation.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.patch.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link AutowiredAnnotationProcessorInstrumentation} indicates a spring core class patch for making sure the - * determineCandidateConstructors method in the class {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor} - * works in spring designed ways - * - * @author zhang xin - */ -public class AutowiredAnnotationProcessorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"; - private static final String ENHANCE_METHOD = "determineCandidateConstructors"; - private static final String INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.spring.patch.AutowiredAnnotationProcessorInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override public String getConstructorInterceptor() { - return INTERCEPTOR_CLASS; - } - } - }; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/resources/skywalking-plugin.def index 2d8504014734..91984358306b 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -spring-core-patch=org.skywalking.apm.plugin.spring.patch.define.AopProxyFactoryInstrumentation -spring-core-patch=org.skywalking.apm.plugin.spring.patch.define.AutowiredAnnotationProcessorInstrumentation +spring-core-patch=AopProxyFactoryInstrumentation +spring-core-patch=AutowiredAnnotationProcessorInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java new file mode 100644 index 000000000000..9c33df7f16ef --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.patch; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.aop.framework.AdvisedSupport; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doReturn; + +@RunWith(MockitoJUnitRunner.class) +public class CreateAopProxyInterceptorTest { + + private CreateAopProxyInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Mock + private AdvisedSupport advisedSupport; + + @Before + public void setUp() { + interceptor = new CreateAopProxyInterceptor(); + + } + + @Test + public void testInterceptNormalObject() throws Throwable { + doReturn(Object.class).when(advisedSupport).getTargetClass(); + assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); + } + + @Test + public void testInterceptEnhanceInstanceObject() throws Throwable { + doReturn(MockClass.class).when(advisedSupport).getTargetClass(); + assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); + } + + private class MockClass implements EnhancedInstance { + + @Override public Object getSkyWalkingDynamicField() { + return null; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java deleted file mode 100644 index 8129b2b20fa0..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/test/java/org/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptorTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.patch; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.springframework.aop.framework.AdvisedSupport; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.doReturn; - -@RunWith(MockitoJUnitRunner.class) -public class CreateAopProxyInterceptorTest { - - private CreateAopProxyInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Mock - private AdvisedSupport advisedSupport; - - @Before - public void setUp() { - interceptor = new CreateAopProxyInterceptor(); - - } - - @Test - public void testInterceptNormalObject() throws Throwable { - doReturn(Object.class).when(advisedSupport).getTargetClass(); - assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); - } - - @Test - public void testInterceptEnhanceInstanceObject() throws Throwable { - doReturn(MockClass.class).when(advisedSupport).getTargetClass(); - assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); - } - - private class MockClass implements EnhancedInstance { - - @Override public Object getSkyWalkingDynamicField() { - return null; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - - } - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java new file mode 100644 index 000000000000..85888e6b82c6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3; + +import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * {@link ControllerConstructorInterceptor} cache the value of {@link RequestMapping} annotation with method in class + * annotation with {@link org.springframework.stereotype.Controller}. + * + * @author zhangxin + */ +public class ControllerConstructorInterceptor implements InstanceConstructorInterceptor { + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String basePath = ""; + RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class); + if (basePathRequestMapping != null) { + if (basePathRequestMapping.value().length > 0) { + basePath = basePathRequestMapping.value()[0]; + } + } + + EnhanceRequireObjectCache enhanceCache = new EnhanceRequireObjectCache(); + enhanceCache.setPathMappingCache(new PathMappingCache(basePath)); + objInst.setSkyWalkingDynamicField(enhanceCache); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java new file mode 100644 index 000000000000..06b7c2b56702 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.web.context.request.NativeWebRequest; + +/** + * {@link HandlerMethodInvokerInterceptor} pass the {@link NativeWebRequest} object into the {@link + * org.springframework.stereotype.Controller} object. + * + * @author zhangxin + */ +public class HandlerMethodInvokerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Object handler = allArguments[1]; + if (handler instanceof EnhancedInstance) { + ((EnhanceRequireObjectCache)((EnhancedInstance)handler).getSkyWalkingDynamicField()).setNativeWebRequest((NativeWebRequest)allArguments[2]); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java new file mode 100644 index 000000000000..99a8fe79458f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; + +/** + * {@link AbstractSpring3Instrumentation} define witness classes of the spring mvc 3 plugin. all Instrumentations + * extends this class. + * + * @author zhangxin + */ +public abstract class AbstractSpring3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String WITHNESS_CLASSES = "org.springframework.web.servlet.view.xslt.AbstractXsltView"; + + @Override protected final String[] witnessClasses() { + return new String[] {WITHNESS_CLASSES}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java new file mode 100644 index 000000000000..635e3519446f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.REQUEST_MAPPING_METHOD_INTERCEPTOR; + +/** + * {@link ControllerInstrumentation} intercept the constructor and the methods annotated with {@link + * org.springframework.web.bind.annotation.RequestMapping} in the class annotated with {@link + * org.springframework.stereotype.Controller}. + * + * @author zhangxin + */ +public class ControllerInstrumentation extends AbstractSpring3Instrumentation { + public static final String CONTROLLER_ENHANCE_ANNOTATION = "org.springframework.stereotype.Controller"; + public static final String CONSTRUCTOR_INTERCEPTOR = "ControllerConstructorInterceptor"; + public static final String REQUEST_MAPPING_ENHANCE_ANNOTATION = "org.springframework.web.bind.annotation.RequestMapping"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPTOR; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return isAnnotatedWith(named(REQUEST_MAPPING_ENHANCE_ANNOTATION)); + } + + @Override + public String getMethodsInterceptor() { + return REQUEST_MAPPING_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return ClassAnnotationMatch.byClassAnnotationMatch(new String[] {CONTROLLER_ENHANCE_ANNOTATION}); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java new file mode 100644 index 000000000000..a366153de476 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link HandlerMethodInstrumentation} intercept the getBean method in the + * org.springframework.web.method.HandlerMethod class. + * + * @author zhangxin + */ +public class HandlerMethodInstrumentation extends AbstractSpring3Instrumentation { + + public static final String ENHANCE_METHOD = "getBean"; + public static final String ENHANCE_CLASS = "org.springframework.web.method.HandlerMethod"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return Constants.GET_BEAN_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java new file mode 100644 index 000000000000..16d459b3d3c0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link HandlerMethodInvokerInstrumentation} intercept the invokeHandlerMethod method in the + * org.springframework.web.bind.annotation.support.HandlerMethodInvoker class. + * + * @author zhangxin + */ +public class HandlerMethodInvokerInstrumentation extends AbstractSpring3Instrumentation { + private static final String ENHANCE_CLASS = "org.springframework.web.bind.annotation.support.HandlerMethodInvoker"; + private static final String ENHANCE_METHOD = "invokeHandlerMethod"; + private static final String INTERCEPTOR_CLASS = "HandlerMethodInvokerInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java new file mode 100644 index 000000000000..e5852f4d5183 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.INVOKE_FOR_REQUEST_INTERCEPTOR; + +/** + * {@link InvocableHandlerInstrumentation} intercept the invokeForRequest method in the + * org.springframework.web.method.support.InvocableHandlerMethod class. + * + * @author zhangxin + */ +public class InvocableHandlerInstrumentation extends AbstractSpring3Instrumentation { + + public static final String ENHANCE_METHOD = "invokeForRequest"; + public static final String ENHANCE_CLASS = "org.springframework.web.method.support.InvocableHandlerMethod"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_FOR_REQUEST_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java deleted file mode 100644 index ae1146a9b7f9..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * {@link ControllerConstructorInterceptor} cache the value of {@link RequestMapping} annotation with method in class - * annotation with {@link org.springframework.stereotype.Controller}. - * - * @author zhangxin - */ -public class ControllerConstructorInterceptor implements InstanceConstructorInterceptor { - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String basePath = ""; - RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class); - if (basePathRequestMapping != null) { - if (basePathRequestMapping.value().length > 0) { - basePath = basePathRequestMapping.value()[0]; - } - } - - EnhanceRequireObjectCache enhanceCache = new EnhanceRequireObjectCache(); - enhanceCache.setPathMappingCache(new PathMappingCache(basePath)); - objInst.setSkyWalkingDynamicField(enhanceCache); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java deleted file mode 100644 index 18a608f36da6..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.springframework.web.context.request.NativeWebRequest; - -/** - * {@link HandlerMethodInvokerInterceptor} pass the {@link NativeWebRequest} object into the {@link - * org.springframework.stereotype.Controller} object. - * - * @author zhangxin - */ -public class HandlerMethodInvokerInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Object handler = allArguments[1]; - if (handler instanceof EnhancedInstance) { - ((EnhanceRequireObjectCache)((EnhancedInstance)handler).getSkyWalkingDynamicField()).setNativeWebRequest((NativeWebRequest)allArguments[2]); - } - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java deleted file mode 100644 index c8e848a46479..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/AbstractSpring3Instrumentation.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3.define; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; - -/** - * {@link AbstractSpring3Instrumentation} define witness classes of the spring mvc 3 plugin. all Instrumentations - * extends this class. - * - * @author zhangxin - */ -public abstract class AbstractSpring3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String WITHNESS_CLASSES = "org.springframework.web.servlet.view.xslt.AbstractXsltView"; - - @Override protected final String[] witnessClasses() { - return new String[] {WITHNESS_CLASSES}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java deleted file mode 100644 index 9982435b4e4a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/ControllerInstrumentation.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.REQUEST_MAPPING_METHOD_INTERCEPTOR; - -/** - * {@link ControllerInstrumentation} intercept the constructor and the methods annotated with {@link - * org.springframework.web.bind.annotation.RequestMapping} in the class annotated with {@link - * org.springframework.stereotype.Controller}. - * - * @author zhangxin - */ -public class ControllerInstrumentation extends AbstractSpring3Instrumentation { - public static final String CONTROLLER_ENHANCE_ANNOTATION = "org.springframework.stereotype.Controller"; - public static final String CONSTRUCTOR_INTERCEPTOR = "org.skywalking.apm.plugin.spring.mvc.v3.ControllerConstructorInterceptor"; - public static final String REQUEST_MAPPING_ENHANCE_ANNOTATION = "org.springframework.web.bind.annotation.RequestMapping"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_INTERCEPTOR; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return isAnnotatedWith(named(REQUEST_MAPPING_ENHANCE_ANNOTATION)); - } - - @Override - public String getMethodsInterceptor() { - return REQUEST_MAPPING_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(new String[] {CONTROLLER_ENHANCE_ANNOTATION}); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java deleted file mode 100644 index faf992bdc694..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInstrumentation.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.GET_BEAN_INTERCEPTOR; - -/** - * {@link HandlerMethodInstrumentation} intercept the getBean method in the - * org.springframework.web.method.HandlerMethod class. - * - * @author zhangxin - */ -public class HandlerMethodInstrumentation extends AbstractSpring3Instrumentation { - - public static final String ENHANCE_METHOD = "getBean"; - public static final String ENHANCE_CLASS = "org.springframework.web.method.HandlerMethod"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return GET_BEAN_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java deleted file mode 100644 index 38d10c03a058..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/HandlerMethodInvokerInstrumentation.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link HandlerMethodInvokerInstrumentation} intercept the invokeHandlerMethod method in the - * org.springframework.web.bind.annotation.support.HandlerMethodInvoker class. - * - * @author zhangxin - */ -public class HandlerMethodInvokerInstrumentation extends AbstractSpring3Instrumentation { - private static final String ENHANCE_CLASS = "org.springframework.web.bind.annotation.support.HandlerMethodInvoker"; - private static final String ENHANCE_METHOD = "invokeHandlerMethod"; - private static final String INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.spring.mvc.v3.HandlerMethodInvokerInterceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java deleted file mode 100644 index ed5b58e24f83..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v3/define/InvocableHandlerInstrumentation.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.INVOKE_FOR_REQUEST_INTERCEPTOR; - -/** - * {@link InvocableHandlerInstrumentation} intercept the invokeForRequest method in the - * org.springframework.web.method.support.InvocableHandlerMethod class. - * - * @author zhangxin - */ -public class InvocableHandlerInstrumentation extends AbstractSpring3Instrumentation { - - public static final String ENHANCE_METHOD = "invokeForRequest"; - public static final String ENHANCE_CLASS = "org.springframework.web.method.support.InvocableHandlerMethod"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return INVOKE_FOR_REQUEST_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/resources/skywalking-plugin.def index 8f4010b67f00..281c61197bc9 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.ControllerInstrumentation -spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.HandlerMethodInstrumentation -spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.InvocableHandlerInstrumentation -spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.HandlerMethodInvokerInstrumentation +spring-mvc-annotation-3.x=ControllerInstrumentation +spring-mvc-annotation-3.x=HandlerMethodInstrumentation +spring-mvc-annotation-3.x=InvocableHandlerInstrumentation +spring-mvc-annotation-3.x=HandlerMethodInvokerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java new file mode 100644 index 000000000000..0b7b0cf1af0d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3; + +import java.lang.reflect.Field; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.bind.annotation.RequestMapping; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +@RunWith(PowerMockRunner.class) +public class ControllerConstructorInterceptorTest { + + private ControllerConstructorInterceptor interceptor; + + private MockRequestMappingObject mappingObject; + + private MockRequestMappingObjectWithoutRequestMapping withoutRequestMapping; + + @Before + public void setUp() { + mappingObject = new MockRequestMappingObject(); + withoutRequestMapping = new MockRequestMappingObjectWithoutRequestMapping(); + interceptor = new ControllerConstructorInterceptor(); + } + + @Test + public void testClassAnnotationWithRequestMapping() throws NoSuchFieldException, IllegalAccessException { + interceptor.onConstruct(mappingObject, null); + + assertThat("/test", is(getBasePath(mappingObject.requireObjectCache.getPathMappingCache()))); + } + + @Test + public void testClassAnnotationWithoutRequestMapping() throws NoSuchFieldException, IllegalAccessException { + interceptor.onConstruct(withoutRequestMapping, null); + + assertThat("", is(getBasePath(withoutRequestMapping.requireObjectCache.getPathMappingCache()))); + } + + private String getBasePath(PathMappingCache mappingCache) throws NoSuchFieldException, IllegalAccessException { + Field classPath = mappingCache.getClass().getDeclaredField("classPath"); + classPath.setAccessible(true); + return (String)classPath.get(mappingCache); + } + + @RequestMapping("/test") + private class MockRequestMappingObject implements EnhancedInstance { + private EnhanceRequireObjectCache requireObjectCache; + + @RequestMapping("/test") + private void mockTestMethod() { + + } + + @Override public Object getSkyWalkingDynamicField() { + return requireObjectCache; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.requireObjectCache = (EnhanceRequireObjectCache)value; + } + } + + private class MockRequestMappingObjectWithoutRequestMapping implements EnhancedInstance { + private EnhanceRequireObjectCache requireObjectCache; + + private void mockTestMethod() { + + } + + @Override public Object getSkyWalkingDynamicField() { + return requireObjectCache; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.requireObjectCache = (EnhanceRequireObjectCache)value; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java new file mode 100644 index 000000000000..8a8b6fa3a1be --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.GetBeanInterceptor; +import org.springframework.web.context.request.NativeWebRequest; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class GetBeanInterceptorTest { + + @Mock + private EnhancedInstance enhancedInstance; + + @Mock + private NativeWebRequest request; + + @Mock + private EnhancedInstance enhanceRet; + + private GetBeanInterceptor interceptor; + + @Before + public void setUp() { + interceptor = new GetBeanInterceptor(); + + when(enhanceRet.getSkyWalkingDynamicField()).thenReturn(new EnhanceRequireObjectCache()); + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(request); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(enhancedInstance, null, null, null, new Object()); + + verify(enhanceRet, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(enhancedInstance, null, null, null, enhanceRet); + + verify(enhanceRet, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java new file mode 100644 index 000000000000..66559c464bc0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v3; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.InvokeForRequestInterceptor; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.web.context.request.NativeWebRequest; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class InvokeForRequestInterceptorTest { + private InvokeForRequestInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Mock + private NativeWebRequest nativeWebRequest; + + private Object argument[]; + + @Before + public void setUp() { + interceptor = new InvokeForRequestInterceptor(); + argument = new Object[] {nativeWebRequest}; + } + + @Test + public void testPassNativeWebRequest() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, argument, new Class[] {NativeWebRequest.class}, null); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java deleted file mode 100644 index 8d3b88e75744..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/ControllerConstructorInterceptorTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3; - -import java.lang.reflect.Field; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; -import org.springframework.web.bind.annotation.RequestMapping; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -@RunWith(PowerMockRunner.class) -public class ControllerConstructorInterceptorTest { - - private ControllerConstructorInterceptor interceptor; - - private MockRequestMappingObject mappingObject; - - private MockRequestMappingObjectWithoutRequestMapping withoutRequestMapping; - - @Before - public void setUp() { - mappingObject = new MockRequestMappingObject(); - withoutRequestMapping = new MockRequestMappingObjectWithoutRequestMapping(); - interceptor = new ControllerConstructorInterceptor(); - } - - @Test - public void testClassAnnotationWithRequestMapping() throws NoSuchFieldException, IllegalAccessException { - interceptor.onConstruct(mappingObject, null); - - assertThat("/test", is(getBasePath(mappingObject.requireObjectCache.getPathMappingCache()))); - } - - @Test - public void testClassAnnotationWithoutRequestMapping() throws NoSuchFieldException, IllegalAccessException { - interceptor.onConstruct(withoutRequestMapping, null); - - assertThat("", is(getBasePath(withoutRequestMapping.requireObjectCache.getPathMappingCache()))); - } - - private String getBasePath(PathMappingCache mappingCache) throws NoSuchFieldException, IllegalAccessException { - Field classPath = mappingCache.getClass().getDeclaredField("classPath"); - classPath.setAccessible(true); - return (String)classPath.get(mappingCache); - } - - @RequestMapping("/test") - private class MockRequestMappingObject implements EnhancedInstance { - private EnhanceRequireObjectCache requireObjectCache; - - @RequestMapping("/test") - private void mockTestMethod() { - - } - - @Override public Object getSkyWalkingDynamicField() { - return requireObjectCache; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - this.requireObjectCache = (EnhanceRequireObjectCache)value; - } - } - - private class MockRequestMappingObjectWithoutRequestMapping implements EnhancedInstance { - private EnhanceRequireObjectCache requireObjectCache; - - private void mockTestMethod() { - - } - - @Override public Object getSkyWalkingDynamicField() { - return requireObjectCache; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - this.requireObjectCache = (EnhanceRequireObjectCache)value; - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java deleted file mode 100644 index 10735b4d4cf3..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.skywalking.apm.plugin.spring.mvc.commons.interceptor.GetBeanInterceptor; -import org.springframework.web.context.request.NativeWebRequest; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class GetBeanInterceptorTest { - - @Mock - private EnhancedInstance enhancedInstance; - - @Mock - private NativeWebRequest request; - - @Mock - private EnhancedInstance enhanceRet; - - private GetBeanInterceptor interceptor; - - @Before - public void setUp() { - interceptor = new GetBeanInterceptor(); - - when(enhanceRet.getSkyWalkingDynamicField()).thenReturn(new EnhanceRequireObjectCache()); - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(request); - } - - @Test - public void testResultIsNotEnhanceInstance() throws Throwable { - interceptor.afterMethod(enhancedInstance, null, null, null, new Object()); - - verify(enhanceRet, times(0)).setSkyWalkingDynamicField(Matchers.any()); - } - - @Test - public void testResultIsEnhanceInstance() throws Throwable { - interceptor.afterMethod(enhancedInstance, null, null, null, enhanceRet); - - verify(enhanceRet, times(0)).setSkyWalkingDynamicField(Matchers.any()); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java deleted file mode 100644 index ec3513b53f88..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v3/InvokeForRequestInterceptorTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v3; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.plugin.spring.mvc.commons.interceptor.InvokeForRequestInterceptor; -import org.springframework.web.context.request.NativeWebRequest; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class InvokeForRequestInterceptorTest { - private InvokeForRequestInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Mock - private NativeWebRequest nativeWebRequest; - - private Object argument[]; - - @Before - public void setUp() { - interceptor = new InvokeForRequestInterceptor(); - argument = new Object[] {nativeWebRequest}; - } - - @Test - public void testPassNativeWebRequest() throws Throwable { - interceptor.beforeMethod(enhancedInstance, null, argument, new Class[] {NativeWebRequest.class}, null); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField(Matchers.any()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java new file mode 100644 index 000000000000..ffac8364d240 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * The ControllerConstructorInterceptor intercepts the Controller's constructor, in order to acquire the + * mapping annotation, if exist. + * + * But, you can see we only use the first mapping value, Why? + * + * Right now, we intercept the controller by annotation as you known, so we CAN'T know which uri patten is actually + * matched. Even we know, that costs a lot. + * + * If we want to resolve that, we must intercept the Spring MVC core codes, that is not a good choice for now. + * + * Comment by @wu-sheng + */ +public class ControllerConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String basePath = ""; + RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class); + if (basePathRequestMapping != null) { + if (basePathRequestMapping.value().length > 0) { + basePath = basePathRequestMapping.value()[0]; + } else if (basePathRequestMapping.path().length > 0) { + basePath = basePathRequestMapping.path()[0]; + } + } + EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache(); + enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath)); + objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java new file mode 100644 index 000000000000..24695fb696a5 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ControllerInstrumentation} enhance all constructor and method annotated with + * org.springframework.web.bind.annotation.RequestMapping that class has + * org.springframework.stereotype.Controller annotation. + * + * ControllerConstructorInterceptor set the controller base path to + * dynamic field before execute constructor. + * + * org.apache.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor get the request path from + * dynamic field first, if not found, RequestMappingMethodInterceptor generate request path that + * combine the path value of current annotation on current method and the base path and set the new path to the dynamic + * filed + * + * @author zhangxin + */ +public abstract class AbstractControllerInstrumentation extends AbstractSpring4Instrumentation { + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return "ControllerConstructorInterceptor"; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return isAnnotatedWith(named("org.springframework.web.bind.annotation.RequestMapping")); + } + + @Override + public String getMethodsInterceptor() { + return Constants.REQUEST_MAPPING_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return isAnnotatedWith(named("org.springframework.web.bind.annotation.GetMapping")) + .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.PostMapping"))) + .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.PutMapping"))) + .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.DeleteMapping"))) + .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.PatchMapping"))); + } + + @Override + public String getMethodsInterceptor() { + return Constants.REST_MAPPING_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return ClassAnnotationMatch.byClassAnnotationMatch(getEnhanceAnnotations()); + } + + protected abstract String[] getEnhanceAnnotations(); + +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java new file mode 100644 index 000000000000..803b14035316 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; + +public abstract class AbstractSpring4Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { + public static final String WITHNESS_CLASSES = "org.springframework.web.servlet.tags.ArgumentTag"; + + @Override + protected final String[] witnessClasses() { + return new String[] {WITHNESS_CLASSES}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java new file mode 100644 index 000000000000..25c8de57b78b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +public class ControllerInstrumentation extends AbstractControllerInstrumentation { + + public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Controller"; + + @Override protected String[] getEnhanceAnnotations() { + return new String[] {ENHANCE_ANNOTATION}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java new file mode 100644 index 000000000000..d088ab7b2e91 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.GET_BEAN_INTERCEPTOR; + +/** + * {@link HandlerMethodInstrumentation} intercept the getBean method in the + * org.springframework.web.method.HandlerMethod class. + * + * @author zhangxin + */ +public class HandlerMethodInstrumentation extends AbstractSpring4Instrumentation { + + public static final String ENHANCE_METHOD = "getBean"; + public static final String ENHANCE_CLASS = "org.springframework.web.method.HandlerMethod"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return GET_BEAN_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java new file mode 100644 index 000000000000..209b6505e3b0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.INVOKE_FOR_REQUEST_INTERCEPTOR; + +/** + * {@link InvocableHandlerInstrumentation} intercept the invokeForRequest method in the + * org.springframework.web.method.support.InvocableHandlerMethod class. + * + * @author zhangxin + */ +public class InvocableHandlerInstrumentation extends AbstractSpring4Instrumentation { + + public static final String ENHANCE_METHOD = "invokeForRequest"; + public static final String ENHANCE_CLASS = "org.springframework.web.method.support.InvocableHandlerMethod"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_FOR_REQUEST_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java new file mode 100644 index 000000000000..ff7dad95a89f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +public class RestControllerInstrumentation extends AbstractControllerInstrumentation { + + public static final String ENHANCE_ANNOTATION = "org.springframework.web.bind.annotation.RestController"; + + @Override protected String[] getEnhanceAnnotations() { + return new String[] {ENHANCE_ANNOTATION}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java deleted file mode 100644 index d4a96de497ba..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * The ControllerConstructorInterceptor intercepts the Controller's constructor, in order to acquire the - * mapping annotation, if exist. - * - * But, you can see we only use the first mapping value, Why? - * - * Right now, we intercept the controller by annotation as you known, so we CAN'T know which uri patten is actually - * matched. Even we know, that costs a lot. - * - * If we want to resolve that, we must intercept the Spring MVC core codes, that is not a good choice for now. - * - * Comment by @wu-sheng - */ -public class ControllerConstructorInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String basePath = ""; - RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class); - if (basePathRequestMapping != null) { - if (basePathRequestMapping.value().length > 0) { - basePath = basePathRequestMapping.value()[0]; - } else if (basePathRequestMapping.path().length > 0) { - basePath = basePathRequestMapping.path()[0]; - } - } - EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache(); - enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath)); - objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java deleted file mode 100644 index 43d406b2c603..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.REQUEST_MAPPING_METHOD_INTERCEPTOR; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.REST_MAPPING_METHOD_INTERCEPTOR; - -/** - * {@link ControllerInstrumentation} enhance all constructor and method annotated with - * org.springframework.web.bind.annotation.RequestMapping that class has - * org.springframework.stereotype.Controller annotation. - * - * org.skywalking.apm.plugin.spring.mvc.v4.ControllerConstructorInterceptor set the controller base path to - * dynamic field before execute constructor. - * - * org.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor get the request path from - * dynamic field first, if not found, RequestMappingMethodInterceptor generate request path that - * combine the path value of current annotation on current method and the base path and set the new path to the dynamic - * filed - * - * @author zhangxin - */ -public abstract class AbstractControllerInstrumentation extends AbstractSpring4Instrumentation { - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return "org.skywalking.apm.plugin.spring.mvc.v4.ControllerConstructorInterceptor"; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return isAnnotatedWith(named("org.springframework.web.bind.annotation.RequestMapping")); - } - - @Override - public String getMethodsInterceptor() { - return REQUEST_MAPPING_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return isAnnotatedWith(named("org.springframework.web.bind.annotation.GetMapping")) - .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.PostMapping"))) - .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.PutMapping"))) - .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.DeleteMapping"))) - .or(isAnnotatedWith(named("org.springframework.web.bind.annotation.PatchMapping"))); - } - - @Override - public String getMethodsInterceptor() { - return REST_MAPPING_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(getEnhanceAnnotations()); - } - - protected abstract String[] getEnhanceAnnotations(); - -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java deleted file mode 100644 index 81b980e22c92..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractSpring4Instrumentation.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; - -public abstract class AbstractSpring4Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { - public static final String WITHNESS_CLASSES = "org.springframework.web.servlet.tags.ArgumentTag"; - - @Override - protected final String[] witnessClasses() { - return new String[] {WITHNESS_CLASSES}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java deleted file mode 100644 index 31f8e98ea629..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentation.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -public class ControllerInstrumentation extends AbstractControllerInstrumentation { - - public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Controller"; - - @Override protected String[] getEnhanceAnnotations() { - return new String[] {ENHANCE_ANNOTATION}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java deleted file mode 100644 index 483cd3ae30d7..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/HandlerMethodInstrumentation.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.GET_BEAN_INTERCEPTOR; - -/** - * {@link HandlerMethodInstrumentation} intercept the getBean method in the - * org.springframework.web.method.HandlerMethod class. - * - * @author zhangxin - */ -public class HandlerMethodInstrumentation extends AbstractSpring4Instrumentation { - - public static final String ENHANCE_METHOD = "getBean"; - public static final String ENHANCE_CLASS = "org.springframework.web.method.HandlerMethod"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return GET_BEAN_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java deleted file mode 100644 index fdbf1c9f5ff8..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/InvocableHandlerInstrumentation.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.skywalking.apm.plugin.spring.mvc.commons.Constants.INVOKE_FOR_REQUEST_INTERCEPTOR; - -/** - * {@link InvocableHandlerInstrumentation} intercept the invokeForRequest method in the - * org.springframework.web.method.support.InvocableHandlerMethod class. - * - * @author zhangxin - */ -public class InvocableHandlerInstrumentation extends AbstractSpring4Instrumentation { - - public static final String ENHANCE_METHOD = "invokeForRequest"; - public static final String ENHANCE_CLASS = "org.springframework.web.method.support.InvocableHandlerMethod"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return INVOKE_FOR_REQUEST_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java deleted file mode 100644 index efeec1757a8a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentation.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -public class RestControllerInstrumentation extends AbstractControllerInstrumentation { - - public static final String ENHANCE_ANNOTATION = "org.springframework.web.bind.annotation.RestController"; - - @Override protected String[] getEnhanceAnnotations() { - return new String[] {ENHANCE_ANNOTATION}; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/resources/skywalking-plugin.def index 0cfc41c666f8..5198f6d2eb8b 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -spring-mvc-annotation-4.x=org.skywalking.apm.plugin.spring.mvc.v4.define.ControllerInstrumentation -spring-mvc-annotation-4.x=org.skywalking.apm.plugin.spring.mvc.v4.define.RestControllerInstrumentation -spring-mvc-annotation-4.x=org.skywalking.apm.plugin.spring.mvc.v4.define.HandlerMethodInstrumentation -spring-mvc-annotation-4.x=org.skywalking.apm.plugin.spring.mvc.v4.define.InvocableHandlerInstrumentation +spring-mvc-annotation-4.x=ControllerInstrumentation +spring-mvc-annotation-4.x=RestControllerInstrumentation +spring-mvc-annotation-4.x=HandlerMethodInstrumentation +spring-mvc-annotation-4.x=InvocableHandlerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java new file mode 100644 index 000000000000..e22389984b9a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4; + +import java.lang.reflect.Method; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.springframework.web.bind.annotation.RequestMapping; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ControllerConstructorInterceptorTest { + private ControllerConstructorInterceptor controllerConstructorInterceptor; + private final MockEnhancedInstance1 inst1 = new MockEnhancedInstance1(); + private final MockEnhancedInstance2 inst2 = new MockEnhancedInstance2(); + private final MockEnhancedInstance3 inst3 = new MockEnhancedInstance3(); + + @Before + public void setUp() throws Exception { + controllerConstructorInterceptor = new ControllerConstructorInterceptor(); + } + + @Test + public void testOnConstruct_Accuracy1() throws Throwable { + controllerConstructorInterceptor.onConstruct(inst1, null); + EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache)inst1.getSkyWalkingDynamicField(); + Assert.assertNotNull(cache); + + Object obj = new Object(); + Method m = obj.getClass().getMethods()[0]; + cache.addPathMapping(m, "#toString"); + + Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test1#toString"); + } + + @Test + public void testOnConstruct_Accuracy2() throws Throwable { + controllerConstructorInterceptor.onConstruct(inst2, null); + EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache)inst2.getSkyWalkingDynamicField(); + Assert.assertNotNull(cache); + + Object obj = new Object(); + Method m = obj.getClass().getMethods()[0]; + cache.addPathMapping(m, "#toString"); + + Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "#toString"); + } + + @Test + public void testOnConstruct_Accuracy3() throws Throwable { + controllerConstructorInterceptor.onConstruct(inst3, null); + EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache)inst3.getSkyWalkingDynamicField(); + Assert.assertNotNull(cache); + + Object obj = new Object(); + Method m = obj.getClass().getMethods()[0]; + cache.addPathMapping(m, "#toString"); + + Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test3#toString"); + } + + @RequestMapping(value = "/test1") + private class MockEnhancedInstance1 implements EnhancedInstance { + private Object value; + + @Override + public Object getSkyWalkingDynamicField() { + return value; + } + + @Override + public void setSkyWalkingDynamicField(Object value) { + this.value = value; + } + } + + private class MockEnhancedInstance2 implements EnhancedInstance { + private Object value; + + @Override + public Object getSkyWalkingDynamicField() { + return value; + } + + @Override + public void setSkyWalkingDynamicField(Object value) { + this.value = value; + } + } + + @RequestMapping(path = "/test3") + private class MockEnhancedInstance3 implements EnhancedInstance { + private Object value; + + @Override + public Object getSkyWalkingDynamicField() { + return value; + } + + @Override + public void setSkyWalkingDynamicField(Object value) { + this.value = value; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java new file mode 100644 index 000000000000..f5b09539a236 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class PathMappingCacheTest { + private PathMappingCache pathMappingCache; + + @Before + public void setUp() throws Exception { + pathMappingCache = new PathMappingCache("org.apache.skywalking.apm.plugin.spring.mvc"); + } + + @Test + public void testAddPathMapping1() throws Throwable { + Object obj = new Object(); + Method m = obj.getClass().getMethods()[0]; + pathMappingCache.addPathMapping(m, "#toString"); + + Assert.assertEquals("the two value should be equal", pathMappingCache.findPathMapping(m), "org.apache.skywalking.apm.plugin.spring.mvc#toString"); + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java new file mode 100644 index 000000000000..25840a979ca0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4; + +import java.lang.reflect.Method; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.RequestMappingMethodInterceptor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class RequestMappingMethodInterceptorTest { + private RequestMappingMethodInterceptor interceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private ServletRequestAttributes servletRequestAttributes; + + @Mock + private HttpServletRequest request; + + @Mock + private HttpServletResponse response; + @Mock + private MethodInterceptResult methodInterceptResult; + + private Object[] arguments; + private Class[] argumentType; + + private EnhancedInstance enhancedInstance; + + private ControllerConstructorInterceptor controllerConstructorInterceptor; + + @Mock + private NativeWebRequest nativeWebRequest; + + @Before + public void setUp() throws Exception { + interceptor = new RequestMappingMethodInterceptor(); + enhancedInstance = new MockEnhancedInstance1(); + controllerConstructorInterceptor = new ControllerConstructorInterceptor(); + servletRequestAttributes = new ServletRequestAttributes(request, response); + + when(request.getScheme()).thenReturn("http"); + when(request.getServerName()).thenReturn("localhost"); + when(request.getServerPort()).thenReturn(8080); + when(request.getRequestURI()).thenReturn("/test/testRequestURL"); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatus()).thenReturn(200); + when(nativeWebRequest.getNativeResponse()).thenReturn(response); + + arguments = new Object[] {request, response}; + argumentType = new Class[] {request.getClass(), response.getClass()}; + + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + controllerConstructorInterceptor.onConstruct(enhancedInstance, null); + RequestMappingClass1 mappingClass1 = new RequestMappingClass1(); + Method m = mappingClass1.getClass().getMethod("testRequestURL"); + RequestContextHolder.setRequestAttributes(servletRequestAttributes); + + interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + controllerConstructorInterceptor.onConstruct(enhancedInstance, null); + RequestMappingClass1 mappingClass1 = new RequestMappingClass1(); + Method m = mappingClass1.getClass().getMethod("testRequestURL"); + RequestContextHolder.setRequestAttributes(servletRequestAttributes); + + interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult); + interceptor.handleMethodException(enhancedInstance, m, arguments, argumentType, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555")); + } + + private void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.SPRING_MVC_ANNOTATION); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + } + + @RequestMapping(value = "/test") + private class MockEnhancedInstance1 implements EnhancedInstance { + private EnhanceRequireObjectCache value = new EnhanceRequireObjectCache(); + + @Override + public Object getSkyWalkingDynamicField() { + value.setPathMappingCache(new PathMappingCache("/test")); + value.setNativeWebRequest(nativeWebRequest); + return value; + } + + @Override + public void setSkyWalkingDynamicField(Object value) { + + } + } + + private class RequestMappingClass1 { + @RequestMapping("/testRequestURL") + public void testRequestURL() { + + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java similarity index 82% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java index 8be5df1be42d..36d1ee5016af 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java @@ -16,12 +16,50 @@ * */ -package org.skywalking.apm.plugin.spring.mvc.v4; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4; import java.lang.reflect.Method; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.RestMappingMethodInterceptor; +import org.hamcrest.MatcherAssert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -29,24 +67,6 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; -import org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RestMappingMethodInterceptor; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -60,10 +80,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(TracingSegmentRunner.class) @@ -252,21 +268,21 @@ public void testWithOccurException() throws Throwable { assertHttpSpan(spans.get(0), "/getRequestURL"); List logDataEntities = SpanHelper.getLogs(spans.get(0)); assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); } private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + MatcherAssert.assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555")); + MatcherAssert.assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555")); } private void assertHttpSpan(AbstractTracingSpan span, String suffix) { assertThat(span.getOperationName(), is("/test" + suffix)); - assertComponent(span, ComponentsDefine.SPRING_MVC_ANNOTATION); - assertTag(span, 0, "http://localhost:8080/test" + suffix); + SpanAssert.assertComponent(span, ComponentsDefine.SPRING_MVC_ANNOTATION); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test" + suffix); assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); + SpanAssert.assertLayer(span, SpanLayer.HTTP); } @RequestMapping(value = "/test") diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java new file mode 100644 index 000000000000..8d2217333e3b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +import net.bytebuddy.matcher.ElementMatchers; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class ControllerInstrumentationTest { + private ControllerInstrumentation controllerInstrumentation; + + @Before + public void setUp() throws Exception { + controllerInstrumentation = new ControllerInstrumentation(); + } + + @Test + public void testGetEnhanceAnnotations() throws Throwable { + Assert.assertArrayEquals(new String[] {ControllerInstrumentation.ENHANCE_ANNOTATION}, + controllerInstrumentation.getEnhanceAnnotations()); + } + + @Test + public void testGetInstanceMethodsInterceptPoints() throws Throwable { + InstanceMethodsInterceptPoint[] methodPoints = controllerInstrumentation.getInstanceMethodsInterceptPoints(); + assertThat(methodPoints.length, is(2)); + assertThat(methodPoints[0].getMethodsInterceptor(), is("RequestMappingMethodInterceptor")); + assertThat(methodPoints[1].getMethodsInterceptor(), is("RestMappingMethodInterceptor")); + + Assert.assertFalse(methodPoints[0].isOverrideArgs()); + Assert.assertFalse(methodPoints[1].isOverrideArgs()); + + Assert.assertNotNull(methodPoints[0].getMethodsMatcher()); + Assert.assertNotNull(methodPoints[1].getMethodsMatcher()); + + } + + @Test + public void testGetConstructorsInterceptPoints() throws Throwable { + ConstructorInterceptPoint[] cips = controllerInstrumentation.getConstructorsInterceptPoints(); + Assert.assertEquals(cips.length, 1); + ConstructorInterceptPoint cip = cips[0]; + Assert.assertNotNull(cip); + + Assert.assertEquals(cip.getConstructorInterceptor(), "ControllerConstructorInterceptor"); + Assert.assertTrue(cip.getConstructorMatcher().equals(ElementMatchers.any())); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java new file mode 100644 index 000000000000..2e71281e2bc0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.v4.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class RestControllerInstrumentationTest { + private RestControllerInstrumentation restControllerInstrumentation; + + @Before + public void setUp() throws Exception { + restControllerInstrumentation = new RestControllerInstrumentation(); + } + + @Test + public void testGetEnhanceAnnotations() throws Throwable { + Assert.assertArrayEquals(new String[] {restControllerInstrumentation.ENHANCE_ANNOTATION}, + restControllerInstrumentation.getEnhanceAnnotations()); + } + + @Test + public void testGetInstanceMethodsInterceptPoints() throws Throwable { + InstanceMethodsInterceptPoint[] methodPoints = restControllerInstrumentation.getInstanceMethodsInterceptPoints(); + assertThat(methodPoints.length, is(2)); + assertThat(methodPoints[0].getMethodsInterceptor(), is("RequestMappingMethodInterceptor")); + assertThat(methodPoints[1].getMethodsInterceptor(), is("RestMappingMethodInterceptor")); + + Assert.assertFalse(methodPoints[0].isOverrideArgs()); + Assert.assertFalse(methodPoints[1].isOverrideArgs()); + + Assert.assertNotNull(methodPoints[0].getMethodsMatcher()); + Assert.assertNotNull(methodPoints[1].getMethodsMatcher()); + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java deleted file mode 100644 index 46d7075e1e49..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/ControllerConstructorInterceptorTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4; - -import java.lang.reflect.Method; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.springframework.web.bind.annotation.RequestMapping; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ControllerConstructorInterceptorTest { - private ControllerConstructorInterceptor controllerConstructorInterceptor; - private final MockEnhancedInstance1 inst1 = new MockEnhancedInstance1(); - private final MockEnhancedInstance2 inst2 = new MockEnhancedInstance2(); - private final MockEnhancedInstance3 inst3 = new MockEnhancedInstance3(); - - @Before - public void setUp() throws Exception { - controllerConstructorInterceptor = new ControllerConstructorInterceptor(); - } - - @Test - public void testOnConstruct_Accuracy1() throws Throwable { - controllerConstructorInterceptor.onConstruct(inst1, null); - EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache)inst1.getSkyWalkingDynamicField(); - Assert.assertNotNull(cache); - - Object obj = new Object(); - Method m = obj.getClass().getMethods()[0]; - cache.addPathMapping(m, "#toString"); - - Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test1#toString"); - } - - @Test - public void testOnConstruct_Accuracy2() throws Throwable { - controllerConstructorInterceptor.onConstruct(inst2, null); - EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache)inst2.getSkyWalkingDynamicField(); - Assert.assertNotNull(cache); - - Object obj = new Object(); - Method m = obj.getClass().getMethods()[0]; - cache.addPathMapping(m, "#toString"); - - Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "#toString"); - } - - @Test - public void testOnConstruct_Accuracy3() throws Throwable { - controllerConstructorInterceptor.onConstruct(inst3, null); - EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache)inst3.getSkyWalkingDynamicField(); - Assert.assertNotNull(cache); - - Object obj = new Object(); - Method m = obj.getClass().getMethods()[0]; - cache.addPathMapping(m, "#toString"); - - Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test3#toString"); - } - - @RequestMapping(value = "/test1") - private class MockEnhancedInstance1 implements EnhancedInstance { - private Object value; - - @Override - public Object getSkyWalkingDynamicField() { - return value; - } - - @Override - public void setSkyWalkingDynamicField(Object value) { - this.value = value; - } - } - - private class MockEnhancedInstance2 implements EnhancedInstance { - private Object value; - - @Override - public Object getSkyWalkingDynamicField() { - return value; - } - - @Override - public void setSkyWalkingDynamicField(Object value) { - this.value = value; - } - } - - @RequestMapping(path = "/test3") - private class MockEnhancedInstance3 implements EnhancedInstance { - private Object value; - - @Override - public Object getSkyWalkingDynamicField() { - return value; - } - - @Override - public void setSkyWalkingDynamicField(Object value) { - this.value = value; - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java deleted file mode 100644 index ce50066d964d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/PathMappingCacheTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4; - -import java.lang.reflect.Method; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class PathMappingCacheTest { - private PathMappingCache pathMappingCache; - - @Before - public void setUp() throws Exception { - pathMappingCache = new PathMappingCache("org.skywalking.apm.plugin.spring.mvc"); - } - - @Test - public void testAddPathMapping1() throws Throwable { - Object obj = new Object(); - Method m = obj.getClass().getMethods()[0]; - pathMappingCache.addPathMapping(m, "#toString"); - - Assert.assertEquals("the two value should be equal", pathMappingCache.findPathMapping(m), "org.skywalking.apm.plugin.spring.mvc#toString"); - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java deleted file mode 100644 index 228e32f322e2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4; - -import java.lang.reflect.Method; -import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache; -import org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RequestMappingMethodInterceptor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class RequestMappingMethodInterceptorTest { - private RequestMappingMethodInterceptor interceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - private ServletRequestAttributes servletRequestAttributes; - - @Mock - private HttpServletRequest request; - - @Mock - private HttpServletResponse response; - @Mock - private MethodInterceptResult methodInterceptResult; - - private Object[] arguments; - private Class[] argumentType; - - private EnhancedInstance enhancedInstance; - - private ControllerConstructorInterceptor controllerConstructorInterceptor; - - @Mock - private NativeWebRequest nativeWebRequest; - - @Before - public void setUp() throws Exception { - interceptor = new RequestMappingMethodInterceptor(); - enhancedInstance = new MockEnhancedInstance1(); - controllerConstructorInterceptor = new ControllerConstructorInterceptor(); - servletRequestAttributes = new ServletRequestAttributes(request, response); - - when(request.getScheme()).thenReturn("http"); - when(request.getServerName()).thenReturn("localhost"); - when(request.getServerPort()).thenReturn(8080); - when(request.getRequestURI()).thenReturn("/test/testRequestURL"); - when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); - when(response.getStatus()).thenReturn(200); - when(nativeWebRequest.getNativeResponse()).thenReturn(response); - - arguments = new Object[] {request, response}; - argumentType = new Class[] {request.getClass(), response.getClass()}; - - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - controllerConstructorInterceptor.onConstruct(enhancedInstance, null); - RequestMappingClass1 mappingClass1 = new RequestMappingClass1(); - Method m = mappingClass1.getClass().getMethod("testRequestURL"); - RequestContextHolder.setRequestAttributes(servletRequestAttributes); - - interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult); - interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithOccurException() throws Throwable { - controllerConstructorInterceptor.onConstruct(enhancedInstance, null); - RequestMappingClass1 mappingClass1 = new RequestMappingClass1(); - Method m = mappingClass1.getClass().getMethod("testRequestURL"); - RequestContextHolder.setRequestAttributes(servletRequestAttributes); - - interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult); - interceptor.handleMethodException(enhancedInstance, m, arguments, argumentType, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); - assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555")); - } - - private void assertHttpSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("/test/testRequestURL")); - assertComponent(span, ComponentsDefine.SPRING_MVC_ANNOTATION); - assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); - } - - @RequestMapping(value = "/test") - private class MockEnhancedInstance1 implements EnhancedInstance { - private EnhanceRequireObjectCache value = new EnhanceRequireObjectCache(); - - @Override - public Object getSkyWalkingDynamicField() { - value.setPathMappingCache(new PathMappingCache("/test")); - value.setNativeWebRequest(nativeWebRequest); - return value; - } - - @Override - public void setSkyWalkingDynamicField(Object value) { - - } - } - - private class RequestMappingClass1 { - @RequestMapping("/testRequestURL") - public void testRequestURL() { - - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java deleted file mode 100644 index 885fe79193e5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -import net.bytebuddy.matcher.ElementMatchers; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ControllerInstrumentationTest { - private ControllerInstrumentation controllerInstrumentation; - - @Before - public void setUp() throws Exception { - controllerInstrumentation = new ControllerInstrumentation(); - } - - @Test - public void testGetEnhanceAnnotations() throws Throwable { - Assert.assertArrayEquals(new String[] {ControllerInstrumentation.ENHANCE_ANNOTATION}, - controllerInstrumentation.getEnhanceAnnotations()); - } - - @Test - public void testGetInstanceMethodsInterceptPoints() throws Throwable { - InstanceMethodsInterceptPoint[] methodPoints = controllerInstrumentation.getInstanceMethodsInterceptPoints(); - assertThat(methodPoints.length, is(2)); - assertThat(methodPoints[0].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RequestMappingMethodInterceptor")); - assertThat(methodPoints[1].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RestMappingMethodInterceptor")); - - Assert.assertFalse(methodPoints[0].isOverrideArgs()); - Assert.assertFalse(methodPoints[1].isOverrideArgs()); - - Assert.assertNotNull(methodPoints[0].getMethodsMatcher()); - Assert.assertNotNull(methodPoints[1].getMethodsMatcher()); - - } - - @Test - public void testGetConstructorsInterceptPoints() throws Throwable { - ConstructorInterceptPoint[] cips = controllerInstrumentation.getConstructorsInterceptPoints(); - Assert.assertEquals(cips.length, 1); - ConstructorInterceptPoint cip = cips[0]; - Assert.assertNotNull(cip); - - Assert.assertEquals(cip.getConstructorInterceptor(), "org.skywalking.apm.plugin.spring.mvc.v4.ControllerConstructorInterceptor"); - Assert.assertTrue(cip.getConstructorMatcher().equals(ElementMatchers.any())); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java deleted file mode 100644 index b50dd2364677..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.v4.define; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class RestControllerInstrumentationTest { - private RestControllerInstrumentation restControllerInstrumentation; - - @Before - public void setUp() throws Exception { - restControllerInstrumentation = new RestControllerInstrumentation(); - } - - @Test - public void testGetEnhanceAnnotations() throws Throwable { - Assert.assertArrayEquals(new String[] {restControllerInstrumentation.ENHANCE_ANNOTATION}, - restControllerInstrumentation.getEnhanceAnnotations()); - } - - @Test - public void testGetInstanceMethodsInterceptPoints() throws Throwable { - InstanceMethodsInterceptPoint[] methodPoints = restControllerInstrumentation.getInstanceMethodsInterceptPoints(); - assertThat(methodPoints.length, is(2)); - assertThat(methodPoints[0].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RequestMappingMethodInterceptor")); - assertThat(methodPoints[1].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RestMappingMethodInterceptor")); - - Assert.assertFalse(methodPoints[0].isOverrideArgs()); - Assert.assertFalse(methodPoints[1].isOverrideArgs()); - - Assert.assertNotNull(methodPoints[0].getMethodsMatcher()); - Assert.assertNotNull(methodPoints[1].getMethodsMatcher()); - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java new file mode 100644 index 000000000000..be50a0a2ad4f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons; + +/** + * Interceptor class name constant variables + * + * @author zhangxin + */ +public class Constants { + public static final String GET_BEAN_INTERCEPTOR = "GetBeanInterceptor"; + + public static final String INVOKE_FOR_REQUEST_INTERCEPTOR = "InvokeForRequestInterceptor"; + + public static final String REQUEST_MAPPING_METHOD_INTERCEPTOR = "RequestMappingMethodInterceptor"; + + public static final String REST_MAPPING_METHOD_INTERCEPTOR = "RestMappingMethodInterceptor"; +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java new file mode 100644 index 000000000000..f3fb126ffa84 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletResponse; +import org.springframework.web.context.request.NativeWebRequest; + +public class EnhanceRequireObjectCache { + private PathMappingCache pathMappingCache; + private NativeWebRequest nativeWebRequest; + + public void setPathMappingCache(PathMappingCache pathMappingCache) { + this.pathMappingCache = pathMappingCache; + } + + public HttpServletResponse getHttpServletResponse() { + return (HttpServletResponse)nativeWebRequest.getNativeResponse(); + } + + public void setNativeWebRequest(NativeWebRequest nativeWebRequest) { + this.nativeWebRequest = nativeWebRequest; + } + + public String findPathMapping(Method method) { + return pathMappingCache.findPathMapping(method); + } + + public void addPathMapping(Method method, String url) { + pathMappingCache.addPathMapping(method, url); + } + + public PathMappingCache getPathMappingCache() { + return pathMappingCache; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java new file mode 100644 index 000000000000..011689c81e95 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons; + +import java.lang.reflect.Method; +import java.util.concurrent.ConcurrentHashMap; + +/** + * {@link PathMappingCache} cache all request urls of {@link org.springframework.stereotype.Controller} . + * + * @author zhangxin + */ +public class PathMappingCache { + private String classPath = ""; + + private ConcurrentHashMap methodPathMapping = new ConcurrentHashMap(); + + public PathMappingCache(String classPath) { + this.classPath = classPath; + } + + public String findPathMapping(Method method) { + return methodPathMapping.get(method); + } + + public void addPathMapping(Method method, String methodPath) { + methodPathMapping.put(method, classPath + methodPath); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java new file mode 100644 index 000000000000..165b6fff6dfc --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +/** + * the abstract method inteceptor + */ +public abstract class AbstractMethodInteceptor implements InstanceMethodsAroundInterceptor { + public abstract String getRequestURL(Method method); + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); + String requestURL = pathMappingCache.findPathMapping(method); + if (requestURL == null) { + requestURL = getRequestURL(method); + pathMappingCache.addPathMapping(method, requestURL); + requestURL = pathMappingCache.findPathMapping(method); + } + + HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); + + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHeader(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); + Tags.URL.set(span, request.getRequestURL().toString()); + Tags.HTTP.METHOD.set(span, request.getMethod()); + span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); + SpanLayer.asHttp(span); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + HttpServletResponse response = ((EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField()).getHttpServletResponse(); + + AbstractSpan span = ContextManager.activeSpan(); + if (response.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + } + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java new file mode 100644 index 000000000000..82f7df1588fe --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.springframework.web.context.request.NativeWebRequest; + +/** + * {@link GetBeanInterceptor} pass the {@link NativeWebRequest} object into the {@link + * org.springframework.stereotype.Controller} object. + * + * @author zhangxin + */ +public class GetBeanInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhanceRequireObjectCache)((EnhancedInstance)ret).getSkyWalkingDynamicField()).setNativeWebRequest((NativeWebRequest)objInst.getSkyWalkingDynamicField()); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java new file mode 100644 index 000000000000..61ef76be4155 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.web.context.request.NativeWebRequest; + +import java.lang.reflect.Method; + +/** + * {@link InvokeForRequestInterceptor} pass the {@link NativeWebRequest} object into the {@link + * org.springframework.stereotype.Controller} object. + * + * @author zhangxin + */ +public class InvokeForRequestInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + objInst.setSkyWalkingDynamicField(allArguments[0]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java new file mode 100644 index 000000000000..b0260290cde0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; + +import java.lang.reflect.Method; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * The RequestMappingMethodInterceptor only use the first mapping value. + * it will inteceptor with @RequestMapping + * + * @author clevertension + */ +public class RequestMappingMethodInterceptor extends AbstractMethodInteceptor { + @Override + public String getRequestURL(Method method) { + String requestURL = ""; + RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + if (methodRequestMapping.value().length > 0) { + requestURL = methodRequestMapping.value()[0]; + } else if (methodRequestMapping.path().length > 0) { + requestURL = methodRequestMapping.path()[0]; + } + return requestURL; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java similarity index 79% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java rename to apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java index d16fabaf98f3..7545fba8dd6b 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.spring.mvc.commons.interceptor; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; import java.lang.reflect.Method; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/Constants.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/Constants.java deleted file mode 100644 index 2342e8f6c713..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/Constants.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons; - -/** - * Interceptor class name constant variables - * - * @author zhangxin - */ -public class Constants { - public static final String GET_BEAN_INTERCEPTOR = "org.skywalking.apm.plugin.spring.mvc.commons.interceptor.GetBeanInterceptor"; - - public static final String INVOKE_FOR_REQUEST_INTERCEPTOR = "org.skywalking.apm.plugin.spring.mvc.commons.interceptor.InvokeForRequestInterceptor"; - - public static final String REQUEST_MAPPING_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RequestMappingMethodInterceptor"; - - public static final String REST_MAPPING_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.spring.mvc.commons.interceptor.RestMappingMethodInterceptor"; -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java deleted file mode 100644 index 18f27f09ec91..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletResponse; -import org.springframework.web.context.request.NativeWebRequest; - -public class EnhanceRequireObjectCache { - private PathMappingCache pathMappingCache; - private NativeWebRequest nativeWebRequest; - - public void setPathMappingCache(PathMappingCache pathMappingCache) { - this.pathMappingCache = pathMappingCache; - } - - public HttpServletResponse getHttpServletResponse() { - return (HttpServletResponse)nativeWebRequest.getNativeResponse(); - } - - public void setNativeWebRequest(NativeWebRequest nativeWebRequest) { - this.nativeWebRequest = nativeWebRequest; - } - - public String findPathMapping(Method method) { - return pathMappingCache.findPathMapping(method); - } - - public void addPathMapping(Method method, String url) { - pathMappingCache.addPathMapping(method, url); - } - - public PathMappingCache getPathMappingCache() { - return pathMappingCache; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java deleted file mode 100644 index ff7a13edf9c6..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/PathMappingCache.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons; - -import java.lang.reflect.Method; -import java.util.concurrent.ConcurrentHashMap; - -/** - * {@link PathMappingCache} cache all request urls of {@link org.springframework.stereotype.Controller} . - * - * @author zhangxin - */ -public class PathMappingCache { - private String classPath = ""; - - private ConcurrentHashMap methodPathMapping = new ConcurrentHashMap(); - - public PathMappingCache(String classPath) { - this.classPath = classPath; - } - - public String findPathMapping(Method method) { - return methodPathMapping.get(method); - } - - public void addPathMapping(Method method, String methodPath) { - methodPathMapping.put(method, classPath + methodPath); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java deleted file mode 100644 index 4d5fa4f13073..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInteceptor.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons.interceptor; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -/** - * the abstract method inteceptor - */ -public abstract class AbstractMethodInteceptor implements InstanceMethodsAroundInterceptor { - public abstract String getRequestURL(Method method); - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); - String requestURL = pathMappingCache.findPathMapping(method); - if (requestURL == null) { - requestURL = getRequestURL(method); - pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); - } - - HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); - - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHeader(next.getHeadKey())); - } - - AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); - Tags.URL.set(span, request.getRequestURL().toString()); - Tags.HTTP.METHOD.set(span, request.getMethod()); - span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); - SpanLayer.asHttp(span); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - HttpServletResponse response = ((EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField()).getHttpServletResponse(); - - AbstractSpan span = ContextManager.activeSpan(); - if (response.getStatus() >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); - } - ContextManager.stopSpan(); - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java deleted file mode 100644 index 6463885cfb55..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons.interceptor; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; -import org.springframework.web.context.request.NativeWebRequest; - -/** - * {@link GetBeanInterceptor} pass the {@link NativeWebRequest} object into the {@link - * org.springframework.stereotype.Controller} object. - * - * @author zhangxin - */ -public class GetBeanInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - if (ret instanceof EnhancedInstance) { - ((EnhanceRequireObjectCache)((EnhancedInstance)ret).getSkyWalkingDynamicField()).setNativeWebRequest((NativeWebRequest)objInst.getSkyWalkingDynamicField()); - } - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java deleted file mode 100644 index c2a9d30f0dbb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons.interceptor; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.springframework.web.context.request.NativeWebRequest; - -import java.lang.reflect.Method; - -/** - * {@link InvokeForRequestInterceptor} pass the {@link NativeWebRequest} object into the {@link - * org.springframework.stereotype.Controller} object. - * - * @author zhangxin - */ -public class InvokeForRequestInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - objInst.setSkyWalkingDynamicField(allArguments[0]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java deleted file mode 100644 index 1159bdbf87f5..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.mvc.commons.interceptor; - -import java.lang.reflect.Method; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * The RequestMappingMethodInterceptor only use the first mapping value. - * it will inteceptor with @RequestMapping - * - * @author clevertension - */ -public class RequestMappingMethodInterceptor extends AbstractMethodInteceptor { - @Override - public String getRequestURL(Method method) { - String requestURL = ""; - RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); - if (methodRequestMapping.value().length > 0) { - requestURL = methodRequestMapping.value()[0]; - } else if (methodRequestMapping.path().length > 0) { - requestURL = methodRequestMapping.path()[0]; - } - return requestURL; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java new file mode 100644 index 000000000000..d6d31d515a06 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.async; + +import java.lang.reflect.Method; +import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class FutureGetInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); + ContextManager.createLocalSpan("future/get:" + ((URI)cacheValues[0]).getPath()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java new file mode 100644 index 000000000000..8aed3df1c022 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.async; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class ResponseCallBackInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + EnhancedInstance successCallBak = (EnhancedInstance)allArguments[0]; + successCallBak.setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField()); + + if (allArguments.length == 2) { + EnhancedInstance failedCallBack = (EnhancedInstance)allArguments[1]; + failedCallBack.setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField()); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java new file mode 100644 index 000000000000..bf9aa2f09b97 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.async; + +import java.lang.reflect.Method; +import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.springframework.http.HttpMethod; + +public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + final URI requestURL = (URI)allArguments[0]; + final HttpMethod httpMethod = (HttpMethod)allArguments[1]; + final ContextCarrier contextCarrier = new ContextCarrier(); + String remotePeer = requestURL.getHost() + ":" + requestURL.getPort(); + AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer); + + span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); + Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath()); + Tags.HTTP.METHOD.set(span, httpMethod.toString()); + SpanLayer.asHttp(span); + Object[] cacheValues = new Object[3]; + cacheValues[0] = requestURL; + cacheValues[1] = contextCarrier; + objInst.setSkyWalkingDynamicField(cacheValues); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); + cacheValues[2] = ContextManager.capture(); + if (ret != null) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(cacheValues); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java new file mode 100644 index 000000000000..84cdde2001f6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.async; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.http.client.AsyncClientHttpRequest; + +public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + AsyncClientHttpRequest clientHttpRequest = (AsyncClientHttpRequest)ret; + if (ret != null) { + Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); + ContextCarrier contextCarrier = (ContextCarrier)cacheValues[1]; + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + clientHttpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue()); + } + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java new file mode 100644 index 000000000000..0592b45acbc2 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.async.define; + +import java.net.URI; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.plugin.spring.resttemplate.async.ResponseCallBackInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ResponseExtractorFutureInstrumentation} enhance the addCallback method and getDefault + * method of org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture by + * ResponseCallBackInterceptor and + * FutureGetInterceptor. + * + * {@link ResponseCallBackInterceptor} set the {@link URI} and {@link ContextSnapshot} to inherited + * org.springframework.util.concurrent.SuccessCallback and org.springframework.util.concurrent.FailureCallback + * + * @author zhangxin + */ +public class ResponseExtractorFutureInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ADD_CALLBACK_METHOD_NAME = "addCallback"; + private static final String ADD_CALLBACK_INTERCEPTOR = "ResponseCallBackInterceptor"; + private static final String ENHANCE_CLASS = "org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture"; + private static final String GET_METHOD_INTERCEPTOR = "FutureGetInterceptor"; + private static final String GET_METHOD_NAME = "get"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ADD_CALLBACK_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return ADD_CALLBACK_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(GET_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return GET_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java new file mode 100644 index 000000000000..f81b9f9369da --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.async.define; + +import java.net.URI; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link RestTemplateInstrumentation} enhance the doExecute method and createAsyncRequest + * method of org.springframework.web.client.AsyncRestTemplate by RestExecuteInterceptor + * and org.springframework.http.client.RestRequestInterceptor. + * + * org.springframework.http.client.RestRequestInterceptor set {@link URI} and {@link ContextSnapshot} to + * org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture for propagate trace context + * after execute doExecute . + * + * @author zhangxin + */ +public class RestTemplateInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.springframework.web.client.AsyncRestTemplate"; + private static final String DO_EXECUTE_METHOD_NAME = "doExecute"; + private static final String DO_EXECUTE_INTERCEPTOR = "RestExecuteInterceptor"; + private static final String CREATE_REQUEST_METHOD_NAME = "createAsyncRequest"; + private static final String CREATE_REQUEST_INTERCEPTOR = "RestRequestInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(DO_EXECUTE_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return DO_EXECUTE_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(CREATE_REQUEST_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return CREATE_REQUEST_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java new file mode 100644 index 000000000000..4583d2fb4586 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.sync; + +import java.lang.reflect.Method; +import java.net.URI; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.springframework.http.HttpMethod; + +public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + final URI requestURL = (URI)allArguments[0]; + final HttpMethod httpMethod = (HttpMethod)allArguments[1]; + final ContextCarrier contextCarrier = new ContextCarrier(); + String remotePeer = requestURL.getHost() + ":" + requestURL.getPort(); + AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer); + + span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); + Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath()); + Tags.HTTP.METHOD.set(span, httpMethod.toString()); + SpanLayer.asHttp(span); + + objInst.setSkyWalkingDynamicField(contextCarrier); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java new file mode 100644 index 000000000000..983adc5bca83 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.sync; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.http.client.AbstractClientHttpRequest; +import org.springframework.http.client.ClientHttpRequest; + +public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ClientHttpRequest clientHttpRequest = (ClientHttpRequest)ret; + if (clientHttpRequest instanceof AbstractClientHttpRequest) { + AbstractClientHttpRequest httpRequest = (AbstractClientHttpRequest)clientHttpRequest; + ContextCarrier contextCarrier = (ContextCarrier)objInst.getSkyWalkingDynamicField(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + httpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue()); + } + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java new file mode 100644 index 000000000000..fbe28b131a7d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.sync; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.springframework.http.client.ClientHttpResponse; + +public class RestResponseInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + + ClientHttpResponse response = (ClientHttpResponse)allArguments[2]; + int statusCode = response.getStatusCode().value(); + AbstractSpan span = ContextManager.activeSpan(); + if (statusCode >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java new file mode 100644 index 000000000000..952d0324d81a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.resttemplate.sync.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link RestTemplateInstrumentation} enhance the doExecute method,handleResponse method and + * handleResponse method of org.springframework.web.client.RestTemplate by + * RestExecuteInterceptor, + * RestResponseInterceptor and + * RestRequestInterceptor. + * + * RestResponseInterceptor set context to header for + * propagate trace context after execute createRequest. + * + * @author zhangxin + */ +public class RestTemplateInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.springframework.web.client.RestTemplate"; + private static final String DO_EXECUTE_METHOD_NAME = "doExecute"; + private static final String DO_EXECUTE_INTERCEPTOR = "RestExecuteInterceptor"; + private static final String HANDLE_REQUEST_METHOD_NAME = "handleResponse"; + private static final String HAND_REQUEST_INTERCEPTOR = "RestResponseInterceptor"; + private static final String CREATE_REQUEST_METHOD_NAME = "createRequest"; + private static final String CREATE_REQUEST_INTERCEPTOR = "RestRequestInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(DO_EXECUTE_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return DO_EXECUTE_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(HANDLE_REQUEST_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return HAND_REQUEST_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(CREATE_REQUEST_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return CREATE_REQUEST_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java deleted file mode 100644 index bb6ff6f677e2..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/FutureGetInterceptor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.async; - -import java.lang.reflect.Method; -import java.net.URI; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class FutureGetInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); - ContextManager.createLocalSpan("future/get:" + ((URI)cacheValues[0]).getPath()); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan activeSpan = ContextManager.activeSpan(); - activeSpan.errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java deleted file mode 100644 index 287a33f6d42d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.async; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class ResponseCallBackInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - EnhancedInstance successCallBak = (EnhancedInstance)allArguments[0]; - successCallBak.setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField()); - - if (allArguments.length == 2) { - EnhancedInstance failedCallBack = (EnhancedInstance)allArguments[1]; - failedCallBack.setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField()); - } - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java deleted file mode 100644 index 5b0946dfbbf4..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.async; - -import java.lang.reflect.Method; -import java.net.URI; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.springframework.http.HttpMethod; - -public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - final URI requestURL = (URI)allArguments[0]; - final HttpMethod httpMethod = (HttpMethod)allArguments[1]; - final ContextCarrier contextCarrier = new ContextCarrier(); - String remotePeer = requestURL.getHost() + ":" + requestURL.getPort(); - AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer); - - span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); - Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath()); - Tags.HTTP.METHOD.set(span, httpMethod.toString()); - SpanLayer.asHttp(span); - Object[] cacheValues = new Object[3]; - cacheValues[0] = requestURL; - cacheValues[1] = contextCarrier; - objInst.setSkyWalkingDynamicField(cacheValues); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); - cacheValues[2] = ContextManager.capture(); - if (ret != null) { - ((EnhancedInstance)ret).setSkyWalkingDynamicField(cacheValues); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java deleted file mode 100644 index e7dcf6259920..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.async; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.springframework.http.client.AsyncClientHttpRequest; - -public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - AsyncClientHttpRequest clientHttpRequest = (AsyncClientHttpRequest)ret; - if (ret != null) { - Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField(); - ContextCarrier contextCarrier = (ContextCarrier)cacheValues[1]; - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - clientHttpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue()); - } - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java deleted file mode 100644 index 0f8f2454f131..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/ResponseExtractorFutureInstrumentation.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.async.define; - -import java.net.URI; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.spring.resttemplate.async.ResponseCallBackInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link ResponseExtractorFutureInstrumentation} enhance the addCallback method and getDefault - * method of org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture by - * org.skywalking.apm.plugin.spring.resttemplate.async.ResponseCallBackInterceptor and - * org.skywalking.apm.plugin.spring.resttemplate.async.FutureGetInterceptor. - * - * {@link ResponseCallBackInterceptor} set the {@link URI} and {@link ContextSnapshot} to inherited - * org.springframework.util.concurrent.SuccessCallback and org.springframework.util.concurrent.FailureCallback - * - * @author zhangxin - */ -public class ResponseExtractorFutureInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ADD_CALLBACK_METHOD_NAME = "addCallback"; - private static final String ADD_CALLBACK_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.async.ResponseCallBackInterceptor"; - private static final String ENHANCE_CLASS = "org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture"; - private static final String GET_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.async.FutureGetInterceptor"; - private static final String GET_METHOD_NAME = "get"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ADD_CALLBACK_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return ADD_CALLBACK_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(GET_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return GET_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java deleted file mode 100644 index 1e6e1874481f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/async/define/RestTemplateInstrumentation.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.async.define; - -import java.net.URI; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link RestTemplateInstrumentation} enhance the doExecute method and createAsyncRequest - * method of org.springframework.web.client.AsyncRestTemplate by org.skywalking.apm.plugin.spring.resttemplate.async.RestExecuteInterceptor - * and org.springframework.http.client.RestRequestInterceptor. - * - * org.springframework.http.client.RestRequestInterceptor set {@link URI} and {@link ContextSnapshot} to - * org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture for propagate trace context - * after execute doExecute . - * - * @author zhangxin - */ -public class RestTemplateInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.springframework.web.client.AsyncRestTemplate"; - private static final String DO_EXECUTE_METHOD_NAME = "doExecute"; - private static final String DO_EXECUTE_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.async.RestExecuteInterceptor"; - private static final String CREATE_REQUEST_METHOD_NAME = "createAsyncRequest"; - private static final String CREATE_REQUEST_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.async.RestRequestInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(DO_EXECUTE_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return DO_EXECUTE_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_REQUEST_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return CREATE_REQUEST_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java deleted file mode 100644 index 841cfef6b944..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.sync; - -import java.lang.reflect.Method; -import java.net.URI; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; -import org.springframework.http.HttpMethod; - -public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - final URI requestURL = (URI)allArguments[0]; - final HttpMethod httpMethod = (HttpMethod)allArguments[1]; - final ContextCarrier contextCarrier = new ContextCarrier(); - String remotePeer = requestURL.getHost() + ":" + requestURL.getPort(); - AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer); - - span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); - Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath()); - Tags.HTTP.METHOD.set(span, httpMethod.toString()); - SpanLayer.asHttp(span); - - objInst.setSkyWalkingDynamicField(contextCarrier); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java deleted file mode 100644 index 8cad96f6d998..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestRequestInterceptor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.sync; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.springframework.http.client.AbstractClientHttpRequest; -import org.springframework.http.client.ClientHttpRequest; - -public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ClientHttpRequest clientHttpRequest = (ClientHttpRequest)ret; - if (clientHttpRequest instanceof AbstractClientHttpRequest) { - AbstractClientHttpRequest httpRequest = (AbstractClientHttpRequest)clientHttpRequest; - ContextCarrier contextCarrier = (ContextCarrier)objInst.getSkyWalkingDynamicField(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - httpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue()); - } - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java deleted file mode 100644 index c2d5a6cff43e..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/RestResponseInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.sync; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.springframework.http.client.ClientHttpResponse; - -public class RestResponseInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - - ClientHttpResponse response = (ClientHttpResponse)allArguments[2]; - int statusCode = response.getStatusCode().value(); - AbstractSpan span = ContextManager.activeSpan(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java deleted file mode 100644 index c800e9b2b94d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/resttemplate/sync/define/RestTemplateInstrumentation.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.resttemplate.sync.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link RestTemplateInstrumentation} enhance the doExecute method,handleResponse method and - * handleResponse method of org.springframework.web.client.RestTemplate by - * org.skywalking.apm.plugin.spring.resttemplate.sync.RestExecuteInterceptor, - * org.skywalking.apm.plugin.spring.resttemplate.sync.RestResponseInterceptor and - * org.skywalking.apm.plugin.spring.resttemplate.sync.RestRequestInterceptor. - * - * org.skywalking.apm.plugin.spring.resttemplate.sync.RestResponseInterceptor set context to header for - * propagate trace context after execute createRequest. - * - * @author zhangxin - */ -public class RestTemplateInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.springframework.web.client.RestTemplate"; - private static final String DO_EXECUTE_METHOD_NAME = "doExecute"; - private static final String DO_EXECUTE_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.sync.RestExecuteInterceptor"; - private static final String HANDLE_REQUEST_METHOD_NAME = "handleResponse"; - private static final String HAND_REQUEST_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.sync.RestResponseInterceptor"; - private static final String CREATE_REQUEST_METHOD_NAME = "createRequest"; - private static final String CREATE_REQUEST_INTERCEPTOR = "org.skywalking.apm.plugin.spring.resttemplate.sync.RestRequestInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(DO_EXECUTE_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return DO_EXECUTE_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(HANDLE_REQUEST_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return HAND_REQUEST_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(CREATE_REQUEST_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return CREATE_REQUEST_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/resources/skywalking-plugin.def index aa695c514736..07498b3ee826 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,3 +1,3 @@ -spring-resttemplate-4.x=org.skywalking.apm.plugin.spring.resttemplate.async.define.RestTemplateInstrumentation -spring-resttemplate-4.x=org.skywalking.apm.plugin.spring.resttemplate.async.define.ResponseExtractorFutureInstrumentation -spring-resttemplate-4.x=org.skywalking.apm.plugin.spring.resttemplate.sync.define.RestTemplateInstrumentation +spring-resttemplate-4.x=RestTemplateInstrumentation +spring-resttemplate-4.x=ResponseExtractorFutureInstrumentation +spring-resttemplate-4.x=RestTemplateInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java new file mode 100644 index 000000000000..5ee6232147b4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spring.cloud.netflix.feign.v11.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link NetflixFeignInstrumentation} presents that skywalking intercepts {@link org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient#execute(feign.Request, + * feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}. + * + * @author zhangxin + */ +public class NetflixFeignInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient"; + + /** + * Intercept class. + */ + private static final String INTERCEPT_CLASS = "DefaultHttpClientInterceptor"; + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java deleted file mode 100644 index 2fd17ed2781b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/cloud/netflix/feign/v11/define/NetflixFeignInstrumentation.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spring.cloud.netflix.feign.v11.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link NetflixFeignInstrumentation} presents that skywalking intercepts {@link org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient#execute(feign.Request, - * feign.Request.Options)} by using {@link org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor}. - * - * @author zhangxin - */ -public class NetflixFeignInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * Enhance class. - */ - private static final String ENHANCE_CLASS = "org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient"; - - /** - * Intercept class. - */ - private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor"; - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/resources/skywalking-plugin.def index 80e07cebdc26..e641f2eaa4f7 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/netflix-plugins/spring-cloud-feign-1.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -spring-cloud-feign-1.x=org.skywalking.apm.plugin.spring.cloud.netflix.feign.v11.define.NetflixFeignInstrumentation +spring-cloud-feign-1.x=NetflixFeignInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java new file mode 100644 index 000000000000..86c77b892570 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spymemcached.v2; + +import java.net.InetSocketAddress; +import java.util.List; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class MemcachedConstructorWithInetSocketAddressListArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + StringBuilder memcachConnInfo = new StringBuilder(); + @SuppressWarnings("unchecked") + List inetSocketAddressList = (List)allArguments[1]; + for (InetSocketAddress inetSocketAddress : inetSocketAddressList) { + String host = inetSocketAddress.getAddress().getHostAddress(); + int port = inetSocketAddress.getPort(); + memcachConnInfo.append(host).append(":").append(port).append(";"); + } + if (memcachConnInfo.length() > 1) { + memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, memcachConnInfo.length() - 1)); + } + objInst.setSkyWalkingDynamicField(memcachConnInfo.toString()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java new file mode 100644 index 000000000000..8197b36bf81e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spymemcached.v2; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class MemcachedMethodInterceptor implements InstanceMethodsAroundInterceptor { + + private static final String SPY_MEMCACHE = "SpyMemcached/"; + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); + AbstractSpan span = ContextManager.createExitSpan(SPY_MEMCACHE + method.getName(), peer); + span.setComponent(ComponentsDefine.MEMCACHED); + Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName()); + SpanLayer.asDB(span); + Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java new file mode 100644 index 000000000000..287e4bcd12d7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spymemcached.v2.define; + +import java.util.List; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; + +/** + * {@link MemcachedInstrumentation} presents that skywalking intercept all constructors and methods of + * {@link net.spy.memcached.MemcachedClient}. + * MemcachedConstructorWithInetSocketAddressListArgInterceptor intercepts the constructor with + * argument {@link java.net.InetSocketAddress}. + * + * @author IluckySi + */ +public class MemcachedInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "net.spy.memcached.MemcachedClient"; + private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS = "MemcachedConstructorWithInetSocketAddressListArgInterceptor"; + private static final String METHOD_INTERCEPT_CLASS = "MemcachedMethodInterceptor"; + + @Override + public ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(1, List.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("touch").or(named("append")).or(named("prepend")).or(named("asyncCAS")) + .or(named("cas")).or(named("add")).or(named("set")).or(named("replace")) + .or(named("asyncGet")).or(named("asyncGets")).or(named("gets")).or(named("getAndTouch")) + .or(named("get")).or(named("asyncGetBulk")).or(named("asyncGetAndTouch")) + .or(named("getBulk")).or(named("getStats")).or(named("incr")) + .or(named("decr")).or(named("asyncIncr")).or(named("asyncDecr")) + .or(named("delete")); + } + + @Override + public String getMethodsInterceptor() { + return METHOD_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java deleted file mode 100644 index e3f9f51a0bc4..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spymemcached.v2; - -import java.net.InetSocketAddress; -import java.util.List; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class MemcachedConstructorWithInetSocketAddressListArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - StringBuilder memcachConnInfo = new StringBuilder(); - @SuppressWarnings("unchecked") - List inetSocketAddressList = (List)allArguments[1]; - for (InetSocketAddress inetSocketAddress : inetSocketAddressList) { - String host = inetSocketAddress.getAddress().getHostAddress(); - int port = inetSocketAddress.getPort(); - memcachConnInfo.append(host).append(":").append(port).append(";"); - } - if (memcachConnInfo.length() > 1) { - memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, memcachConnInfo.length() - 1)); - } - objInst.setSkyWalkingDynamicField(memcachConnInfo.toString()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java deleted file mode 100644 index d0d31a38867d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spymemcached.v2; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class MemcachedMethodInterceptor implements InstanceMethodsAroundInterceptor { - - private static final String SPY_MEMCACHE = "SpyMemcached/"; - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); - AbstractSpan span = ContextManager.createExitSpan(SPY_MEMCACHE + method.getName(), peer); - span.setComponent(ComponentsDefine.MEMCACHED); - Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName()); - SpanLayer.asDB(span); - Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java deleted file mode 100644 index 46efa403da25..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/define/MemcachedInstrumentation.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spymemcached.v2.define; - -import java.util.List; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link MemcachedInstrumentation} presents that skywalking intercept all constructors and methods of - * {@link net.spy.memcached.MemcachedClient}. - * org.skywalking.apm.plugin.spymemcached.v2.MemcachedConstructorWithInetSocketAddressListArgInterceptor intercepts the constructor with - * argument {@link java.net.InetSocketAddress}. - * - * @author IluckySi - */ -public class MemcachedInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "net.spy.memcached.MemcachedClient"; - private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.spymemcached.v2.MemcachedConstructorWithInetSocketAddressListArgInterceptor"; - private static final String METHOD_INTERCEPT_CLASS = "org.skywalking.apm.plugin.spymemcached.v2.MemcachedMethodInterceptor"; - - @Override - public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(1, List.class); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("touch").or(named("append")).or(named("prepend")).or(named("asyncCAS")) - .or(named("cas")).or(named("add")).or(named("set")).or(named("replace")) - .or(named("asyncGet")).or(named("asyncGets")).or(named("gets")).or(named("getAndTouch")) - .or(named("get")).or(named("asyncGetBulk")).or(named("asyncGetAndTouch")) - .or(named("getBulk")).or(named("getStats")).or(named("incr")) - .or(named("decr")).or(named("asyncIncr")).or(named("asyncDecr")) - .or(named("delete")); - } - - @Override - public String getMethodsInterceptor() { - return METHOD_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/resources/skywalking-plugin.def index f552f1602dc0..2baae8572f0e 100644 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -spymemcached-2.x=org.skywalking.apm.plugin.spymemcached.v2.define.MemcachedInstrumentation \ No newline at end of file +spymemcached-2.x=MemcachedInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java new file mode 100644 index 000000000000..466e0842ccb2 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spymemcached.v2; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class MemcachedConstructorWithInetSocketAddressListArgInterceptorTest { + + private MemcachedConstructorWithInetSocketAddressListArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new MemcachedConstructorWithInetSocketAddressListArgInterceptor(); + } + + @Test + public void onConstructWithInetSocketAddressList() { + List inetSocketAddressList = new ArrayList(); + inetSocketAddressList.add(new InetSocketAddress("127.0.0.1", 11211)); + inetSocketAddressList.add(new InetSocketAddress("127.0.0.2", 11211)); + interceptor.onConstruct(enhancedInstance, new Object[] {null, inetSocketAddressList}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java new file mode 100644 index 000000000000..4038b17d75be --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.spymemcached.v2; + +import java.lang.reflect.Method; +import java.util.List; +import net.spy.memcached.MemcachedClient; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.hamcrest.CoreMatchers; +import org.hamcrest.MatcherAssert; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static junit.framework.TestCase.assertNotNull; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MemcachedMethodInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + @Mock + private EnhancedInstance enhancedInstance; + private MemcachedMethodInterceptor interceptor; + + private Object[] allArgument; + private Class[] argumentType; + + @Before + public void setUp() throws Exception { + allArgument = new Object[] {"OperationKey", "OperationValue"}; + argumentType = new Class[] {String.class, String.class}; + + interceptor = new MemcachedMethodInterceptor(); + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:11211"); + } + + @Test + public void testIntercept() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); + interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null); + + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + assertMemcacheSpan(spans.get(0)); + } + + @Test + public void testInterceptWithException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); + interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); + + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + assertMemcacheSpan(spans.get(0)); + + assertLogData(SpanHelper.getLogs(spans.get(0))); + } + + private void assertLogData(List logDataEntities) { + assertThat(logDataEntities.size(), is(1)); + LogDataEntity logData = logDataEntities.get(0); + Assert.assertThat(logData.getLogs().size(), is(4)); + Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.is("error")); + Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.is(RuntimeException.class.getName())); + Assert.assertNull(logData.getLogs().get(2).getValue()); + assertNotNull(logData.getLogs().get(3).getValue()); + } + + private void assertMemcacheSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("SpyMemcached/set")); + assertThat(span.isExit(), is(true)); + assertThat(SpanHelper.getComponentId(span), is(20)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(0).getValue(), is("Memcached")); + assertThat(tags.get(1).getValue(), is("set OperationKey")); + MatcherAssert.assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB)); + } + + private Method getMockSetMethod() { + try { + return MemcachedClient.class.getMethod("set", String.class, int.class, Object.class); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + return null; + } + } + + private Method getMockGetMethod() { + try { + return MemcachedClient.class.getMethod("get", String.class); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java deleted file mode 100644 index 558c4f0b214c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spymemcached.v2; - -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class MemcachedConstructorWithInetSocketAddressListArgInterceptorTest { - - private MemcachedConstructorWithInetSocketAddressListArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new MemcachedConstructorWithInetSocketAddressListArgInterceptor(); - } - - @Test - public void onConstructWithInetSocketAddressList() { - List inetSocketAddressList = new ArrayList(); - inetSocketAddressList.add(new InetSocketAddress("127.0.0.1", 11211)); - inetSocketAddressList.add(new InetSocketAddress("127.0.0.2", 11211)); - interceptor.onConstruct(enhancedInstance, new Object[] {null, inetSocketAddressList}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java deleted file mode 100644 index c5843c217b7c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.spymemcached.v2; - -import java.lang.reflect.Method; -import java.util.List; -import net.spy.memcached.MemcachedClient; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import static junit.framework.TestCase.assertNotNull; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class MemcachedMethodInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - @Mock - private EnhancedInstance enhancedInstance; - private MemcachedMethodInterceptor interceptor; - - private Object[] allArgument; - private Class[] argumentType; - - @Before - public void setUp() throws Exception { - allArgument = new Object[] {"OperationKey", "OperationValue"}; - argumentType = new Class[] {String.class, String.class}; - - interceptor = new MemcachedMethodInterceptor(); - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:11211"); - } - - @Test - public void testIntercept() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); - interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null); - - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - assertMemcacheSpan(spans.get(0)); - } - - @Test - public void testInterceptWithException() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); - interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); - - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - assertMemcacheSpan(spans.get(0)); - - assertLogData(SpanHelper.getLogs(spans.get(0))); - } - - private void assertLogData(List logDataEntities) { - assertThat(logDataEntities.size(), is(1)); - LogDataEntity logData = logDataEntities.get(0); - Assert.assertThat(logData.getLogs().size(), is(4)); - Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.is("error")); - Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.is(RuntimeException.class.getName())); - Assert.assertNull(logData.getLogs().get(2).getValue()); - assertNotNull(logData.getLogs().get(3).getValue()); - } - - private void assertMemcacheSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("SpyMemcached/set")); - assertThat(span.isExit(), is(true)); - assertThat(SpanHelper.getComponentId(span), is(20)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("Memcached")); - assertThat(tags.get(1).getValue(), is("set OperationKey")); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); - } - - private Method getMockSetMethod() { - try { - return MemcachedClient.class.getMethod("set", String.class, int.class, Object.class); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - return null; - } - } - - private Method getMockGetMethod() { - try { - return MemcachedClient.class.getMethod("get", String.class); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - return null; - } - } -} diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java new file mode 100644 index 000000000000..757de94f36f7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.struts2; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.struts2.ServletActionContext; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class Struts2Interceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpServletRequest request = ServletActionContext.getRequest(); + ContextCarrier contextCarrier = new ContextCarrier(); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHeader(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier); + Tags.URL.set(span, request.getRequestURL().toString()); + Tags.HTTP.METHOD.set(span, request.getMethod()); + span.setComponent(ComponentsDefine.STRUTS2); + SpanLayer.asHttp(span); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + HttpServletResponse response = ServletActionContext.getResponse(); + + AbstractSpan span = ContextManager.activeSpan(); + if (response.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java new file mode 100644 index 000000000000..6ae04f5cb6c3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.struts2.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link Struts2Instrumentation} enhance the invokeAction method + * in com.opensymphony.xwork2.DefaultActionInvocation class by + * Struts2Interceptor class + * + * @author zhangxin + */ +public class Struts2Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.opensymphony.xwork2.DefaultActionInvocation"; + private static final String ENHANCE_METHOD = "invokeAction"; + private static final String INTERCEPT_CLASS = "Struts2Interceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/Struts2Interceptor.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/Struts2Interceptor.java deleted file mode 100644 index 46267aa81f0b..000000000000 --- a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/Struts2Interceptor.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.struts2; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.struts2.ServletActionContext; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -public class Struts2Interceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - HttpServletRequest request = ServletActionContext.getRequest(); - ContextCarrier contextCarrier = new ContextCarrier(); - - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHeader(next.getHeadKey())); - } - - AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier); - Tags.URL.set(span, request.getRequestURL().toString()); - Tags.HTTP.METHOD.set(span, request.getMethod()); - span.setComponent(ComponentsDefine.STRUTS2); - SpanLayer.asHttp(span); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - HttpServletResponse response = ServletActionContext.getResponse(); - - AbstractSpan span = ContextManager.activeSpan(); - if (response.getStatus() >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java deleted file mode 100644 index a1c6429d7ead..000000000000 --- a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/skywalking/apm/plugin/struts2/define/Struts2Instrumentation.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.struts2.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link Struts2Instrumentation} enhance the invokeAction method - * in com.opensymphony.xwork2.DefaultActionInvocation class by - * org.skywalking.apm.plugin.struts2.Struts2Interceptor class - * - * @author zhangxin - */ -public class Struts2Instrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "com.opensymphony.xwork2.DefaultActionInvocation"; - private static final String ENHANCE_METHOD = "invokeAction"; - private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.struts2.Struts2Interceptor"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(ENHANCE_METHOD); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/resources/skywalking-plugin.def index 775e3a65bda3..ea021e9e02fe 100644 --- a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -struts2-2.x=org.skywalking.apm.plugin.struts2.define.Struts2Instrumentation +struts2-2.x=Struts2Instrumentation diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java new file mode 100644 index 000000000000..1790f55e8f49 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.struts2; + +import com.opensymphony.xwork2.ActionContext; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.struts2.StrutsStatics; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertException; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertTag; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@PrepareForTest({ActionContext.class}) +public class Struts2InterceptorTest { + + private Struts2Interceptor struts2Interceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + private ActionContext actionContext; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private HttpServletRequest request; + @Mock + private HttpServletResponse response; + @Mock + private MethodInterceptResult methodInterceptResult; + + @Mock + private EnhancedInstance enhancedInstance; + + private Object[] arguments; + private Class[] argumentType; + + private Object[] exceptionArguments; + private Class[] exceptionArgumentType; + + @Before + public void setUp() throws Exception { + struts2Interceptor = new Struts2Interceptor(); + when(request.getRequestURI()).thenReturn("/test/testRequestURL"); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatus()).thenReturn(200); + + mockStatic(ActionContext.class); + actionContext = mock(ActionContext.class); + when(actionContext.get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE)).thenReturn(response); + when(actionContext.get(StrutsStatics.HTTP_REQUEST)).thenReturn(request); + when(ActionContext.getContext()).thenReturn(actionContext); + + arguments = new Object[] {request, response}; + argumentType = new Class[] {request.getClass(), response.getClass()}; + + exceptionArguments = new Object[] {request, response, new RuntimeException()}; + exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + struts2Interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + struts2Interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithSerializedContextData() throws Throwable { + when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + + struts2Interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + struts2Interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + struts2Interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + struts2Interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + struts2Interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); + } + + private void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.STRUTS2); + assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + assertLayer(span, SpanLayer.HTTP); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java deleted file mode 100644 index d8167d626608..000000000000 --- a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/test/java/org/skywalking/apm/plugin/struts2/Struts2InterceptorTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.struts2; - -import com.opensymphony.xwork2.ActionContext; -import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.struts2.StrutsStatics; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -@PrepareForTest({ActionContext.class}) -public class Struts2InterceptorTest { - - private Struts2Interceptor struts2Interceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - private ActionContext actionContext; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private HttpServletRequest request; - @Mock - private HttpServletResponse response; - @Mock - private MethodInterceptResult methodInterceptResult; - - @Mock - private EnhancedInstance enhancedInstance; - - private Object[] arguments; - private Class[] argumentType; - - private Object[] exceptionArguments; - private Class[] exceptionArgumentType; - - @Before - public void setUp() throws Exception { - struts2Interceptor = new Struts2Interceptor(); - when(request.getRequestURI()).thenReturn("/test/testRequestURL"); - when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); - when(response.getStatus()).thenReturn(200); - - mockStatic(ActionContext.class); - actionContext = mock(ActionContext.class); - when(actionContext.get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE)).thenReturn(response); - when(actionContext.get(StrutsStatics.HTTP_REQUEST)).thenReturn(request); - when(ActionContext.getContext()).thenReturn(actionContext); - - arguments = new Object[] {request, response}; - argumentType = new Class[] {request.getClass(), response.getClass()}; - - exceptionArguments = new Object[] {request, response, new RuntimeException()}; - exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - struts2Interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - struts2Interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithSerializedContextData() throws Throwable { - when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); - - struts2Interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - struts2Interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - assertTraceSegmentRef(traceSegment.getRefs().get(0)); - } - - @Test - public void testWithOccurException() throws Throwable { - struts2Interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - struts2Interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); - struts2Interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); - assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); - } - - private void assertHttpSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("/test/testRequestURL")); - assertComponent(span, ComponentsDefine.STRUTS2); - assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java new file mode 100644 index 000000000000..482dfbaff400 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.tomcat78x; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class TomcatExceptionInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ContextManager.activeSpan().errorOccurred().log((Throwable)allArguments[2]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java new file mode 100644 index 000000000000..0c3a0396941f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.tomcat78x; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link TomcatInvokeInterceptor} fetch the serialized context data by using {@link + * HttpServletRequest#getHeader(String)}. The {@link TraceSegment#refs} of current trace segment will reference to the + * trace segment id of the previous level if the serialized context is not null. + */ +public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor { + + /** + * * The {@link TraceSegment#refs} of current trace segment will reference to the + * trace segment id of the previous level if the serialized context is not null. + * + * @param objInst + * @param method + * @param allArguments + * @param argumentsTypes + * @param result change this result, if you want to truncate the method. + * @throws Throwable + */ + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + HttpServletRequest request = (HttpServletRequest)allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHeader(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier); + Tags.URL.set(span, request.getRequestURL().toString()); + Tags.HTTP.METHOD.set(span, request.getMethod()); + span.setComponent(ComponentsDefine.TOMCAT); + SpanLayer.asHttp(span); + + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + HttpServletResponse response = (HttpServletResponse)allArguments[1]; + + AbstractSpan span = ContextManager.activeSpan(); + if (response.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan span = ContextManager.activeSpan(); + span.log(t); + span.errorOccurred(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java new file mode 100644 index 000000000000..dd6e9430d976 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.tomcat78x.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link TomcatInstrumentation} presents that skywalking using class {@link org.apache.skywalking.apm.plugin.tomcat78x.TomcatInvokeInterceptor} to intercept + * {@link org.apache.catalina.core.StandardWrapperValve#invoke} and using class {@link + * org.apache.skywalking.apm.plugin.tomcat78x.TomcatExceptionInterceptor} to intercept {@link + * org.apache.catalina.core.StandardWrapperValve#exception}. + * + * @author zhangxin + */ +public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "org.apache.catalina.core.StandardWrapperValve"; + + /** + * The intercept class for "invoke" method in the class "org.apache.catalina.core.StandardWrapperValve" + */ + private static final String INVOKE_INTERCEPT_CLASS = "TomcatInvokeInterceptor"; + + /** + * The intercept class for "exception" method in the class "org.apache.catalina.core.StandardWrapperValve" + */ + private static final String EXCEPTION_INTERCEPT_CLASS = "TomcatExceptionInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("invoke"); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("exception"); + } + + @Override public String getMethodsInterceptor() { + return EXCEPTION_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java deleted file mode 100644 index 640aef6a1273..000000000000 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.tomcat78x; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class TomcatExceptionInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ContextManager.activeSpan().errorOccurred().log((Throwable)allArguments[2]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java deleted file mode 100644 index cbb4bb1ba61a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.tomcat78x; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link TomcatInvokeInterceptor} fetch the serialized context data by using {@link - * HttpServletRequest#getHeader(String)}. The {@link TraceSegment#refs} of current trace segment will reference to the - * trace segment id of the previous level if the serialized context is not null. - */ -public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor { - - /** - * * The {@link TraceSegment#refs} of current trace segment will reference to the - * trace segment id of the previous level if the serialized context is not null. - * - * @param objInst - * @param method - * @param allArguments - * @param argumentsTypes - * @param result change this result, if you want to truncate the method. - * @throws Throwable - */ - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - HttpServletRequest request = (HttpServletRequest)allArguments[0]; - ContextCarrier contextCarrier = new ContextCarrier(); - - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHeader(next.getHeadKey())); - } - - AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier); - Tags.URL.set(span, request.getRequestURL().toString()); - Tags.HTTP.METHOD.set(span, request.getMethod()); - span.setComponent(ComponentsDefine.TOMCAT); - SpanLayer.asHttp(span); - - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - HttpServletResponse response = (HttpServletResponse)allArguments[1]; - - AbstractSpan span = ContextManager.activeSpan(); - if (response.getStatus() >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.log(t); - span.errorOccurred(); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java deleted file mode 100644 index 7f33796e6227..000000000000 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.tomcat78x.define; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.catalina.connector.Request; -import org.apache.catalina.connector.Response; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.skywalking.apm.plugin.tomcat78x.TomcatInvokeInterceptor; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link TomcatInstrumentation} presents that skywalking using class {@link TomcatInvokeInterceptor} to intercept - * {@link org.apache.catalina.core.StandardWrapperValve#invoke(Request, Response)} and using class {@link - * org.skywalking.apm.plugin.tomcat78x.TomcatExceptionInterceptor} to intercept {@link - * org.apache.catalina.core.StandardWrapperValve#exception(Request, Response, Throwable)}. - * - * @author zhangxin - */ -public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - /** - * Enhance class. - */ - private static final String ENHANCE_CLASS = "org.apache.catalina.core.StandardWrapperValve"; - - /** - * The intercept class for "invoke" method in the class "org.apache.catalina.core.StandardWrapperValve" - */ - private static final String INVOKE_INTERCEPT_CLASS = "org.skywalking.apm.plugin.tomcat78x.TomcatInvokeInterceptor"; - - /** - * The intercept class for "exception" method in the class "org.apache.catalina.core.StandardWrapperValve" - */ - private static final String EXCEPTION_INTERCEPT_CLASS = "org.skywalking.apm.plugin.tomcat78x.TomcatExceptionInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("invoke"); - } - - @Override - public String getMethodsInterceptor() { - return INVOKE_INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("exception"); - } - - @Override public String getMethodsInterceptor() { - return EXCEPTION_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def index fb17b3092387..df074e77628a 100644 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -tomcat-7.x/8.x=org.skywalking.apm.plugin.tomcat78x.define.TomcatInstrumentation \ No newline at end of file +tomcat-7.x/8.x=TomcatInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java new file mode 100644 index 000000000000..ab9f92927794 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.tomcat78x; + +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class TomcatInvokeInterceptorTest { + + private TomcatInvokeInterceptor tomcatInvokeInterceptor; + private TomcatExceptionInterceptor tomcatExceptionInterceptor; + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private HttpServletRequest request; + @Mock + private HttpServletResponse response; + @Mock + private MethodInterceptResult methodInterceptResult; + + @Mock + private EnhancedInstance enhancedInstance; + + private Object[] arguments; + private Class[] argumentType; + + private Object[] exceptionArguments; + private Class[] exceptionArgumentType; + + @Before + public void setUp() throws Exception { + tomcatInvokeInterceptor = new TomcatInvokeInterceptor(); + tomcatExceptionInterceptor = new TomcatExceptionInterceptor(); + when(request.getRequestURI()).thenReturn("/test/testRequestURL"); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatus()).thenReturn(200); + arguments = new Object[] {request, response}; + argumentType = new Class[] {request.getClass(), response.getClass()}; + + exceptionArguments = new Object[] {request, response, new RuntimeException()}; + exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithSerializedContextData() throws Throwable { + when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + + tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + tomcatInvokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + @Test + public void testWithTomcatException() throws Throwable { + tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + tomcatExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); + } + + private void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.TOMCAT); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java deleted file mode 100644 index 992a555f922a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.tomcat78x; - -import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertException; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLayer; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class TomcatInvokeInterceptorTest { - - private TomcatInvokeInterceptor tomcatInvokeInterceptor; - private TomcatExceptionInterceptor tomcatExceptionInterceptor; - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private HttpServletRequest request; - @Mock - private HttpServletResponse response; - @Mock - private MethodInterceptResult methodInterceptResult; - - @Mock - private EnhancedInstance enhancedInstance; - - private Object[] arguments; - private Class[] argumentType; - - private Object[] exceptionArguments; - private Class[] exceptionArgumentType; - - @Before - public void setUp() throws Exception { - tomcatInvokeInterceptor = new TomcatInvokeInterceptor(); - tomcatExceptionInterceptor = new TomcatExceptionInterceptor(); - when(request.getRequestURI()).thenReturn("/test/testRequestURL"); - when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); - when(response.getStatus()).thenReturn(200); - arguments = new Object[] {request, response}; - argumentType = new Class[] {request.getClass(), response.getClass()}; - - exceptionArguments = new Object[] {request, response, new RuntimeException()}; - exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithSerializedContextData() throws Throwable { - when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); - - tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - assertTraceSegmentRef(traceSegment.getRefs().get(0)); - } - - @Test - public void testWithOccurException() throws Throwable { - tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - tomcatInvokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); - tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - @Test - public void testWithTomcatException() throws Throwable { - tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - tomcatExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - assertException(logDataEntities.get(0), RuntimeException.class); - } - - private void assertTraceSegmentRef(TraceSegmentRef ref) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); - assertThat(SegmentRefHelper.getSpanId(ref), is(3)); - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); - } - - private void assertHttpSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("/test/testRequestURL")); - assertComponent(span, ComponentsDefine.TOMCAT); - assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); - assertThat(span.isEntry(), is(true)); - assertLayer(span, SpanLayer.HTTP); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java similarity index 76% rename from apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java rename to apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java index a81c8610d98b..987230c87246 100644 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java @@ -16,14 +16,32 @@ * */ -package org.skywalking.apm.plugin.xmemcached.v2; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; import java.net.InetSocketAddress; import java.util.Map; import java.util.Map.Entry; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; /** * {@link XMemcachedConstructorWithComplexArgInterceptor} intercept constructor of diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java new file mode 100644 index 000000000000..18911fbcd2be --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +/** + * {@link XMemcachedConstructorWithHostPortArgInterceptor} intercept constructor of + * {@link XMemcachedClient(final String host, final int port)} or + * {@link XMemcachedClient(final String host, final int port, int weight)}. + * + * @author IluckySi + */ +public class XMemcachedConstructorWithHostPortArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + Object host = allArguments[0]; + Object port = allArguments[1]; + objInst.setSkyWalkingDynamicField(host + ":" + port); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java new file mode 100644 index 000000000000..80e87655f38e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import java.net.InetSocketAddress; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +/** + * {@link XMemcachedConstructorWithInetSocketAddressArgInterceptor} intercept constructor of + * {@link XMemcachedClient(final InetSocketAddress inetSocketAddress)} or + * {@link XMemcachedClient(final InetSocketAddress inetSocketAddress, int weight)}. + * + * @author IluckySi + */ +public class XMemcachedConstructorWithInetSocketAddressArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + InetSocketAddress inetSocketAddress = (InetSocketAddress)allArguments[0]; + String host = inetSocketAddress.getAddress().getHostAddress(); + int port = inetSocketAddress.getPort(); + objInst.setSkyWalkingDynamicField(host + ":" + port); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java new file mode 100644 index 000000000000..fc9e5e4bc4a0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import java.net.InetSocketAddress; +import java.util.List; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +/** + * {@link XMemcachedConstructorWithInetSocketAddressListArgInterceptor} intercept constructor of + * {@link XMemcachedClient(List addressList). + * + * @author IluckySi + */ +public class XMemcachedConstructorWithInetSocketAddressListArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + StringBuilder memcachConnInfo = new StringBuilder(); + @SuppressWarnings("unchecked") + List inetSocketAddressList = (List)allArguments[0]; + for (InetSocketAddress inetSocketAddress : inetSocketAddressList) { + String host = inetSocketAddress.getAddress().getHostAddress(); + int port = inetSocketAddress.getPort(); + memcachConnInfo.append(host).append(":").append(port).append(";"); + } + int length = memcachConnInfo.length(); + if (length > 1) { + memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, length - 1)); + } + objInst.setSkyWalkingDynamicField(memcachConnInfo.toString()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java new file mode 100644 index 000000000000..c36ea6d20d8e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import java.lang.reflect.Method; + +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link XMemcachedMethodInterceptor} intercept the operation method, + * record the memcached host, operation name and the key of the operation. + * + * @author IluckySi + */ +public class XMemcachedMethodInterceptor implements InstanceMethodsAroundInterceptor { + + private static final String XMEMCACHED = "XMemcached/"; + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); + AbstractSpan span = ContextManager.createExitSpan(XMEMCACHED + method.getName(), peer); + span.setComponent(ComponentsDefine.MEMCACHED); + Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName()); + SpanLayer.asDB(span); + Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java similarity index 75% rename from apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java index 648e6c2a3ee9..7ffb617eb87c 100644 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.plugin.xmemcached.v2.define; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2.define; import java.net.InetSocketAddress; import java.util.List; @@ -24,15 +42,15 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** * {@link MemcachedInstrumentation} presents that skywalking intercept all constructors and methods of @@ -50,15 +68,15 @@ public class XMemcachedInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { private static final String ENHANCE_CLASS = "net.rubyeye.xmemcached.XMemcachedClient"; - private static final String CONSTRUCTOR_WITH_HOSTPORT_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithHostPortArgInterceptor"; - private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithInetSocketAddressArgInterceptor"; - private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithInetSocketAddressListArgInterceptor"; - private static final String CONSTRUCTOR_WITH_COMPLEX_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithComplexArgInterceptor"; - private static final String METHOD_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedMethodInterceptor"; + private static final String CONSTRUCTOR_WITH_HOSTPORT_ARG_INTERCEPT_CLASS = "XMemcachedConstructorWithHostPortArgInterceptor"; + private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_ARG_INTERCEPT_CLASS = "XMemcachedConstructorWithInetSocketAddressArgInterceptor"; + private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS = "XMemcachedConstructorWithInetSocketAddressListArgInterceptor"; + private static final String CONSTRUCTOR_WITH_COMPLEX_ARG_INTERCEPT_CLASS = "XMemcachedConstructorWithComplexArgInterceptor"; + private static final String METHOD_INTERCEPT_CLASS = "XMemcachedMethodInterceptor"; @Override public ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); + return NameMatch.byName(ENHANCE_CLASS); } @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java deleted file mode 100644 index 560b7011d7fb..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * {@link XMemcachedConstructorWithHostPortArgInterceptor} intercept constructor of - * {@link XMemcachedClient(final String host, final int port)} or - * {@link XMemcachedClient(final String host, final int port, int weight)}. - * - * @author IluckySi - */ -public class XMemcachedConstructorWithHostPortArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - Object host = allArguments[0]; - Object port = allArguments[1]; - objInst.setSkyWalkingDynamicField(host + ":" + port); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java deleted file mode 100644 index b4a1a7c189da..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import java.net.InetSocketAddress; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * {@link XMemcachedConstructorWithInetSocketAddressArgInterceptor} intercept constructor of - * {@link XMemcachedClient(final InetSocketAddress inetSocketAddress)} or - * {@link XMemcachedClient(final InetSocketAddress inetSocketAddress, int weight)}. - * - * @author IluckySi - */ -public class XMemcachedConstructorWithInetSocketAddressArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - InetSocketAddress inetSocketAddress = (InetSocketAddress)allArguments[0]; - String host = inetSocketAddress.getAddress().getHostAddress(); - int port = inetSocketAddress.getPort(); - objInst.setSkyWalkingDynamicField(host + ":" + port); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java deleted file mode 100644 index 3643da0aa176..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import java.net.InetSocketAddress; -import java.util.List; - -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -/** - * {@link XMemcachedConstructorWithInetSocketAddressListArgInterceptor} intercept constructor of - * {@link XMemcachedClient(List addressList). - * - * @author IluckySi - */ -public class XMemcachedConstructorWithInetSocketAddressListArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - StringBuilder memcachConnInfo = new StringBuilder(); - @SuppressWarnings("unchecked") - List inetSocketAddressList = (List)allArguments[0]; - for (InetSocketAddress inetSocketAddress : inetSocketAddressList) { - String host = inetSocketAddress.getAddress().getHostAddress(); - int port = inetSocketAddress.getPort(); - memcachConnInfo.append(host).append(":").append(port).append(";"); - } - int length = memcachConnInfo.length(); - if (length > 1) { - memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, length - 1)); - } - objInst.setSkyWalkingDynamicField(memcachConnInfo.toString()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java deleted file mode 100644 index 969214630e91..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import java.lang.reflect.Method; - -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.tag.Tags; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link XMemcachedMethodInterceptor} intercept the operation method, - * record the memcached host, operation name and the key of the operation. - * - * @author IluckySi - */ -public class XMemcachedMethodInterceptor implements InstanceMethodsAroundInterceptor { - - private static final String XMEMCACHED = "XMemcached/"; - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); - AbstractSpan span = ContextManager.createExitSpan(XMEMCACHED + method.getName(), peer); - span.setComponent(ComponentsDefine.MEMCACHED); - Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName()); - SpanLayer.asDB(span); - Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def index c04b8817ba5a..c91ef35c4e54 100644 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -memcache-2.x=org.skywalking.apm.plugin.xmemcached.v2.define.XMemcachedInstrumentation \ No newline at end of file +memcache-2.x=XMemcachedInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java new file mode 100644 index 000000000000..57b4fcf8d591 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.Map; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class XMemcachedConstructorWithComplexArgInterceptorTest { + + private XMemcachedConstructorWithComplexArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new XMemcachedConstructorWithComplexArgInterceptor(); + } + + @Test + public void onConstructWithComplex() { + Map inetSocketAddressMap = new HashMap(); + inetSocketAddressMap.put(new InetSocketAddress("127.0.0.1", 11211), new InetSocketAddress("127.0.0.2", 11211)); + interceptor.onConstruct(enhancedInstance, new Object[]{null, null, null, null, null, null, inetSocketAddressMap}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java new file mode 100644 index 000000000000..bd328bcd3154 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class XMemcachedConstructorWithHostPortArgInterceptorTest { + + private XMemcachedConstructorWithHostPortArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new XMemcachedConstructorWithHostPortArgInterceptor(); + } + + @Test + public void onConstructWithHostPort() { + interceptor.onConstruct(enhancedInstance, new Object[]{"127.0.0.1", 11211}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java new file mode 100644 index 000000000000..c4592019f180 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.net.InetSocketAddress; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class XMemcachedConstructorWithInetSocketAddressArgInterceptorTest { + + private XMemcachedConstructorWithInetSocketAddressArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new XMemcachedConstructorWithInetSocketAddressArgInterceptor(); + } + + @Test + public void onConstructWithInetSocketAddress() { + interceptor.onConstruct(enhancedInstance, new Object[]{new InetSocketAddress("127.0.0.1", 11211)}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java new file mode 100644 index 000000000000..982d24b684f0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest { + + private XMemcachedConstructorWithInetSocketAddressListArgInterceptor interceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Before + public void setUp() throws Exception { + interceptor = new XMemcachedConstructorWithInetSocketAddressListArgInterceptor(); + } + + @Test + public void onConstructWithInetSocketAddressList() { + List inetSocketAddressList = new ArrayList(); + inetSocketAddressList.add(new InetSocketAddress("127.0.0.1", 11211)); + inetSocketAddressList.add(new InetSocketAddress("127.0.0.2", 11211)); + interceptor.onConstruct(enhancedInstance, new Object[]{inetSocketAddressList}); + + verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java new file mode 100644 index 000000000000..f2c65c9b60c5 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.xmemcached.v2; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +import java.lang.reflect.Method; +import java.util.List; + +import junit.framework.TestCase; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import net.rubyeye.xmemcached.XMemcachedClient; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class XMemcachedMethodInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private EnhancedInstance enhancedInstance; + private XMemcachedMethodInterceptor interceptor; + + private Object[] allArgument; + private Class[] argumentType; + + @Before + public void setUp() throws Exception { + allArgument = new Object[] {"OperationKey", "OperationValue"}; + argumentType = new Class[] {String.class, String.class}; + + interceptor = new XMemcachedMethodInterceptor(); + when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:11211"); + } + + @Test + public void testIntercept() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); + interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null); + + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + assertMemcacheSpan(spans.get(0)); + } + + @Test + public void testInterceptWithException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); + interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); + + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + assertMemcacheSpan(spans.get(0)); + + assertLogData(SpanHelper.getLogs(spans.get(0))); + } + + private void assertLogData(List logDataEntities) { + assertThat(logDataEntities.size(), is(1)); + LogDataEntity logData = logDataEntities.get(0); + Assert.assertThat(logData.getLogs().size(), is(4)); + Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.is("error")); + Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.is(RuntimeException.class.getName())); + Assert.assertNull(logData.getLogs().get(2).getValue()); + TestCase.assertNotNull(logData.getLogs().get(3).getValue()); + } + + private void assertMemcacheSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("XMemcached/set")); + assertThat(span.isExit(), is(true)); + assertThat(SpanHelper.getComponentId(span), is(20)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(0).getValue(), is("Memcached")); + assertThat(tags.get(1).getValue(), is("set OperationKey")); + assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB)); + } + + private Method getMockSetMethod() throws Exception { + return XMemcachedClient.class.getMethod("set", String.class, int.class, Object.class); + } + + private Method getMockGetMethod() throws Exception { + return XMemcachedClient.class.getMethod("get", String.class); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java deleted file mode 100644 index a8ac1e0a7e8c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -@RunWith(MockitoJUnitRunner.class) -public class XMemcachedConstructorWithComplexArgInterceptorTest { - - private XMemcachedConstructorWithComplexArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new XMemcachedConstructorWithComplexArgInterceptor(); - } - - @Test - public void onConstructWithComplex() { - Map inetSocketAddressMap = new HashMap(); - inetSocketAddressMap.put(new InetSocketAddress("127.0.0.1", 11211), new InetSocketAddress("127.0.0.2", 11211)); - interceptor.onConstruct(enhancedInstance, new Object[]{null, null, null, null, null, null, inetSocketAddressMap}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java deleted file mode 100644 index f715e628f4d1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -@RunWith(MockitoJUnitRunner.class) -public class XMemcachedConstructorWithHostPortArgInterceptorTest { - - private XMemcachedConstructorWithHostPortArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new XMemcachedConstructorWithHostPortArgInterceptor(); - } - - @Test - public void onConstructWithHostPort() { - interceptor.onConstruct(enhancedInstance, new Object[]{"127.0.0.1", 11211}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java deleted file mode 100644 index 9e9370bf6150..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.net.InetSocketAddress; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -@RunWith(MockitoJUnitRunner.class) -public class XMemcachedConstructorWithInetSocketAddressArgInterceptorTest { - - private XMemcachedConstructorWithInetSocketAddressArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new XMemcachedConstructorWithInetSocketAddressArgInterceptor(); - } - - @Test - public void onConstructWithInetSocketAddress() { - interceptor.onConstruct(enhancedInstance, new Object[]{new InetSocketAddress("127.0.0.1", 11211)}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java deleted file mode 100644 index 3850da8d2b08..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; - -@RunWith(MockitoJUnitRunner.class) -public class XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest { - - private XMemcachedConstructorWithInetSocketAddressListArgInterceptor interceptor; - - @Mock - private EnhancedInstance enhancedInstance; - - @Before - public void setUp() throws Exception { - interceptor = new XMemcachedConstructorWithInetSocketAddressListArgInterceptor(); - } - - @Test - public void onConstructWithInetSocketAddressList() { - List inetSocketAddressList = new ArrayList(); - inetSocketAddressList.add(new InetSocketAddress("127.0.0.1", 11211)); - inetSocketAddressList.add(new InetSocketAddress("127.0.0.2", 11211)); - interceptor.onConstruct(enhancedInstance, new Object[]{inetSocketAddressList}); - - verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211"); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java deleted file mode 100644 index 311ad88bf619..000000000000 --- a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.plugin.xmemcached.v2; - -import static junit.framework.TestCase.assertNotNull; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; - -import java.lang.reflect.Method; -import java.util.List; - -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; - -import net.rubyeye.xmemcached.XMemcachedClient; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class XMemcachedMethodInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private EnhancedInstance enhancedInstance; - private XMemcachedMethodInterceptor interceptor; - - private Object[] allArgument; - private Class[] argumentType; - - @Before - public void setUp() throws Exception { - allArgument = new Object[] {"OperationKey", "OperationValue"}; - argumentType = new Class[] {String.class, String.class}; - - interceptor = new XMemcachedMethodInterceptor(); - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:11211"); - } - - @Test - public void testIntercept() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); - interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null); - - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - assertMemcacheSpan(spans.get(0)); - } - - @Test - public void testInterceptWithException() throws Throwable { - interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); - interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException()); - interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null); - - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - assertMemcacheSpan(spans.get(0)); - - assertLogData(SpanHelper.getLogs(spans.get(0))); - } - - private void assertLogData(List logDataEntities) { - assertThat(logDataEntities.size(), is(1)); - LogDataEntity logData = logDataEntities.get(0); - Assert.assertThat(logData.getLogs().size(), is(4)); - Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.is("error")); - Assert.assertThat(logData.getLogs().get(1).getValue(), CoreMatchers.is(RuntimeException.class.getName())); - Assert.assertNull(logData.getLogs().get(2).getValue()); - assertNotNull(logData.getLogs().get(3).getValue()); - } - - private void assertMemcacheSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("XMemcached/set")); - assertThat(span.isExit(), is(true)); - assertThat(SpanHelper.getComponentId(span), is(20)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("Memcached")); - assertThat(tags.get(1).getValue(), is("set OperationKey")); - assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB)); - } - - private Method getMockSetMethod() throws Exception { - return XMemcachedClient.class.getMethod("set", String.class, int.class, Object.class); - } - - private Method getMockGetMethod() throws Exception { - return XMemcachedClient.class.getMethod("get", String.class); - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldGetter.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldGetter.java new file mode 100644 index 000000000000..4095379e54a4 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldGetter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.helper; + +import java.lang.reflect.Field; + +public class FieldGetter { + public static T getValue(Object instance, + String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(instance); + } + + public static T getParentFieldValue(Object instance, + String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getClass().getSuperclass().getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(instance); + } + + public static T get2LevelParentFieldValue(Object instance, + String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getClass().getSuperclass().getSuperclass().getDeclaredField(fieldName); + field.setAccessible(true); + return (T)field.get(instance); + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldSetter.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldSetter.java new file mode 100644 index 000000000000..838cf7d1ebe5 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/FieldSetter.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.helper; + +import java.lang.reflect.Field; + +/** + * Created by xin on 2017/7/9. + */ +public class FieldSetter { + + public static void setValue(Object instance, + String fieldName, T value) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + field.set(instance, value); + } + + public static void setStaticValue(Class instance, + String fieldName, T value) throws IllegalAccessException, NoSuchFieldException { + Field field = instance.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(instance, value); + } + +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentHelper.java new file mode 100644 index 000000000000..f70b5d013e7b --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentHelper.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.helper; + +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; + +public class SegmentHelper { + + public static List getSpans(TraceSegment traceSegment) { + try { + return FieldGetter.getValue(traceSegment, "spans"); + } catch (Exception e) { + } + + return null; + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentRefHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentRefHelper.java new file mode 100644 index 000000000000..0074c9d76e32 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SegmentRefHelper.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.helper; + +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; + +public class SegmentRefHelper { + public static String getPeerHost(TraceSegmentRef ref) { + try { + return FieldGetter.getValue(ref, "peerHost"); + } catch (Exception e) { + } + + return null; + } + + public static ID getTraceSegmentId(TraceSegmentRef ref) { + try { + return FieldGetter.getValue(ref, "traceSegmentId"); + } catch (Exception e) { + } + + return null; + } + + public static int getSpanId(TraceSegmentRef ref) { + try { + return FieldGetter.getValue(ref, "spanId"); + } catch (Exception e) { + } + + return -1; + } + + public static int getEntryApplicationInstanceId(TraceSegmentRef ref) { + try { + return FieldGetter.getValue(ref, "entryApplicationInstanceId"); + } catch (Exception e) { + } + + return -1; + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SpanHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SpanHelper.java new file mode 100644 index 000000000000..55c7b85acd12 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/helper/SpanHelper.java @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.helper; + +import java.util.Collections; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; + +public class SpanHelper { + public static int getParentSpanId(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "parentSpanId"); + } catch (Exception e) { + try { + return FieldGetter.getParentFieldValue(tracingSpan, "parentSpanId"); + } catch (Exception e1) { + + } + } + + return -9999; + } + + public static List getLogs(AbstractSpan tracingSpan) { + try { + List logs = FieldGetter.get2LevelParentFieldValue(tracingSpan, "logs"); + if (logs != null) { + return logs; + } + } catch (Exception e) { + try { + List logs = FieldGetter.getParentFieldValue(tracingSpan, "logs"); + if (logs != null) { + return logs; + } + } catch (Exception e1) { + + } + } + + return Collections.emptyList(); + } + + public static List getTags(AbstractSpan tracingSpan) { + try { + List tags = FieldGetter.get2LevelParentFieldValue(tracingSpan, "tags"); + if (tags != null) { + return tags; + } + } catch (Exception e) { + try { + List tags = FieldGetter.getParentFieldValue(tracingSpan, "tags"); + if (tags != null) { + return tags; + } + } catch (Exception e1) { + + } + } + + return Collections.emptyList(); + } + + public static SpanLayer getLayer(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "layer"); + } catch (Exception e) { + try { + return FieldGetter.getParentFieldValue(tracingSpan, "layer"); + } catch (Exception e1) { + + } + } + + return null; + } + + public static String getComponentName(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "componentName"); + } catch (Exception e) { + try { + return FieldGetter.getParentFieldValue(tracingSpan, "componentName"); + } catch (Exception e1) { + + } + } + + return null; + } + + public static int getComponentId(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "componentId"); + } catch (Exception e) { + try { + return FieldGetter.getParentFieldValue(tracingSpan, "componentId"); + } catch (Exception e1) { + + } + } + + return -1; + } + + public static boolean getErrorOccurred(AbstractSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "errorOccurred"); + } catch (Exception e) { + try { + return FieldGetter.getParentFieldValue(tracingSpan, "errorOccurred"); + } catch (Exception e1) { + + } + } + + return false; + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/AgentServiceRule.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/AgentServiceRule.java new file mode 100644 index 000000000000..0f0a85c22517 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/AgentServiceRule.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.tools; + +import java.util.HashMap; +import java.util.LinkedList; +import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.junit.rules.ExternalResource; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; +import org.apache.skywalking.apm.agent.core.logging.core.LogLevel; +import org.apache.skywalking.apm.agent.test.helper.FieldSetter; + +public class AgentServiceRule extends ExternalResource { + + @Override + protected void after() { + super.after(); + try { + FieldSetter.setValue(ServiceManager.INSTANCE.getClass(), "bootedServices", new HashMap()); + FieldSetter.setValue(IgnoredTracerContext.ListenerManager.class, "LISTENERS", new LinkedList()); + FieldSetter.setValue(TracingContext.ListenerManager.class, "LISTENERS", new LinkedList()); + ServiceManager.INSTANCE.shutdown(); + } catch (Exception e) { + } + } + + @Override + protected void before() throws Throwable { + super.before(); + Config.Logging.LEVEL = LogLevel.OFF; + ServiceManager.INSTANCE.boot(); + RemoteDownstreamConfig.Agent.APPLICATION_ID = 1; + RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1; + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentRefAssert.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentRefAssert.java new file mode 100644 index 000000000000..e6441481c2b2 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentRefAssert.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.tools; + +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public class SegmentRefAssert { + public static void assertSegmentId(TraceSegmentRef ref, String segmentId) { + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is(segmentId)); + } + + public static void assertSpanId(TraceSegmentRef ref, int spanId) { + assertThat(SegmentRefHelper.getSpanId(ref), is(spanId)); + } + + public static void assertPeerHost(TraceSegmentRef ref, String peerHost) { + assertThat(SegmentRefHelper.getPeerHost(ref), is(peerHost)); + } + + public static void assertEntryApplicationInstanceId(TraceSegmentRef ref, int entryApplicationInstanceID) { + assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(entryApplicationInstanceID)); + } + +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStorage.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStorage.java new file mode 100644 index 000000000000..81f41e86e788 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStorage.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.tools; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; + +public class SegmentStorage { + private LinkedList traceSegments; + private LinkedList ignoredTracerContexts; + + public SegmentStorage() { + traceSegments = new LinkedList(); + ignoredTracerContexts = new LinkedList(); + } + + void addTraceSegment(TraceSegment segment) { + traceSegments.add(segment); + } + + public List getTraceSegments() { + return traceSegments; + } + + void addIgnoreTraceContext(IgnoredTracerContext context) { + this.ignoredTracerContexts.add(context); + } + + public LinkedList getIgnoredTracerContexts() { + return ignoredTracerContexts; + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStoragePoint.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStoragePoint.java new file mode 100644 index 000000000000..3b59184d3ba1 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SegmentStoragePoint.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.tools; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface SegmentStoragePoint { +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SpanAssert.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SpanAssert.java new file mode 100644 index 000000000000..ff013039bee4 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/SpanAssert.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.tools; + +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.network.trace.component.Component; + +import static junit.framework.TestCase.assertNotNull; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class SpanAssert { + public static void assertLogSize(AbstractSpan span, int exceptedSize) { + assertThat(SpanHelper.getLogs(span).size(), is(exceptedSize)); + } + + public static void assertTagSize(AbstractSpan span, int exceptedSize) { + assertThat(SpanHelper.getTags(span).size(), is(exceptedSize)); + } + + public static void assertException(LogDataEntity logDataEntity, Class throwableClass, + String message) { + Assert.assertThat(logDataEntity.getLogs().size(), is(4)); + Assert.assertThat(logDataEntity.getLogs().get(0).getValue(), CoreMatchers.is("error")); + Assert.assertThat(logDataEntity.getLogs().get(1).getValue(), CoreMatchers.is(throwableClass.getName())); + Assert.assertThat(logDataEntity.getLogs().get(2).getValue(), is(message)); + assertNotNull(logDataEntity.getLogs().get(3).getValue()); + } + + public static void assertException(LogDataEntity logDataEntity, Class throwableClass) { + Assert.assertThat(logDataEntity.getLogs().size(), is(4)); + Assert.assertThat(logDataEntity.getLogs().get(0).getValue(), CoreMatchers.is("error")); + Assert.assertThat(logDataEntity.getLogs().get(1).getValue(), CoreMatchers.is(throwableClass.getName())); + Assert.assertNull(logDataEntity.getLogs().get(2).getValue()); + assertNotNull(logDataEntity.getLogs().get(3).getValue()); + } + + public static void assertComponent(AbstractSpan span, Component component) { + assertThat(SpanHelper.getComponentId(span), is(component.getId())); + } + + public static void assertComponent(AbstractSpan span, String componentName) { + assertThat(SpanHelper.getComponentName(span), is(componentName)); + } + + public static void assertLayer(AbstractSpan span, SpanLayer spanLayer) { + assertThat(SpanHelper.getLayer(span), is(spanLayer)); + } + + public static void assertTag(AbstractSpan span, int index, String value) { + assertThat(SpanHelper.getTags(span).get(index).getValue(), is(value)); + } + + public static void assertOccurException(AbstractSpan span, boolean excepted) { + assertThat(SpanHelper.getErrorOccurred(span), is(excepted)); + } + +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/TracingSegmentRunner.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/TracingSegmentRunner.java new file mode 100644 index 000000000000..1813af8b217a --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/test/tools/TracingSegmentRunner.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.agent.test.tools; + +import java.lang.reflect.Field; +import org.apache.skywalking.apm.agent.core.context.IgnoreTracerContextListener; +import org.apache.skywalking.apm.agent.core.context.TracingContext; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; +import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext; +import org.apache.skywalking.apm.agent.core.context.TracingContextListener; + +public class TracingSegmentRunner extends BlockJUnit4ClassRunner { + private TracingContextListener tracingContextListener; + private IgnoreTracerContextListener ignoreTracerContextListener; + private Field field; + private Object targetObject; + private SegmentStorage tracingData; + + public TracingSegmentRunner(Class klass) throws InitializationError { + super(klass); + for (Field field : klass.getDeclaredFields()) { + if (field.isAnnotationPresent(SegmentStoragePoint.class) && field.getType().equals(SegmentStorage.class)) { + this.field = field; + this.field.setAccessible(true); + break; + } + } + } + + @Override + protected Object createTest() throws Exception { + targetObject = super.createTest(); + return targetObject; + } + + @Override protected Statement withAfters(FrameworkMethod method, Object target, final Statement statement) { + return new Statement() { + @Override public void evaluate() throws Throwable { + if (field != null) { + try { + tracingData = new SegmentStorage(); + field.set(targetObject, tracingData); + } catch (IllegalAccessException e) { + } + } + tracingContextListener = new TracingContextListener() { + @Override + public void afterFinished(TraceSegment traceSegment) { + tracingData.addTraceSegment(traceSegment); + } + }; + + ignoreTracerContextListener = new IgnoreTracerContextListener() { + @Override + public void afterFinished(IgnoredTracerContext tracerContext) { + tracingData.addIgnoreTraceContext(tracerContext); + } + }; + + TracingContext.ListenerManager.add(tracingContextListener); + IgnoredTracerContext.ListenerManager.add(ignoreTracerContextListener); + try { + statement.evaluate(); + } finally { + TracingContext.ListenerManager.remove(tracingContextListener); + IgnoredTracerContext.ListenerManager.remove(ignoreTracerContextListener); + } + } + }; + } +} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldGetter.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldGetter.java deleted file mode 100644 index 7df1dfad8114..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldGetter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.helper; - -import java.lang.reflect.Field; - -public class FieldGetter { - public static T getValue(Object instance, - String fieldName) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(instance); - } - - public static T getParentFieldValue(Object instance, - String fieldName) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getClass().getSuperclass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(instance); - } - - public static T get2LevelParentFieldValue(Object instance, - String fieldName) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getClass().getSuperclass().getSuperclass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T)field.get(instance); - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldSetter.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldSetter.java deleted file mode 100644 index 663beffdf0bf..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/FieldSetter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.helper; - -import java.lang.reflect.Field; - -/** - * Created by xin on 2017/7/9. - */ -public class FieldSetter { - - public static void setValue(Object instance, - String fieldName, T value) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - field.set(instance, value); - } - - public static void setStaticValue(Class instance, - String fieldName, T value) throws IllegalAccessException, NoSuchFieldException { - Field field = instance.getDeclaredField(fieldName); - field.setAccessible(true); - field.set(instance, value); - } - -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentHelper.java deleted file mode 100644 index 2956b479b215..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentHelper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.helper; - -import java.util.List; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public class SegmentHelper { - - public static List getSpans(TraceSegment traceSegment) { - try { - return FieldGetter.getValue(traceSegment, "spans"); - } catch (Exception e) { - } - - return null; - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentRefHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentRefHelper.java deleted file mode 100644 index d375731840b4..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SegmentRefHelper.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.helper; - -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; - -public class SegmentRefHelper { - public static String getPeerHost(TraceSegmentRef ref) { - try { - return FieldGetter.getValue(ref, "peerHost"); - } catch (Exception e) { - } - - return null; - } - - public static ID getTraceSegmentId(TraceSegmentRef ref) { - try { - return FieldGetter.getValue(ref, "traceSegmentId"); - } catch (Exception e) { - } - - return null; - } - - public static int getSpanId(TraceSegmentRef ref) { - try { - return FieldGetter.getValue(ref, "spanId"); - } catch (Exception e) { - } - - return -1; - } - - public static int getEntryApplicationInstanceId(TraceSegmentRef ref) { - try { - return FieldGetter.getValue(ref, "entryApplicationInstanceId"); - } catch (Exception e) { - } - - return -1; - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SpanHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SpanHelper.java deleted file mode 100644 index c1c8ac9a26d3..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/SpanHelper.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.helper; - -import java.util.Collections; -import java.util.List; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; - -public class SpanHelper { - public static int getParentSpanId(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "parentSpanId"); - } catch (Exception e) { - try { - return FieldGetter.getParentFieldValue(tracingSpan, "parentSpanId"); - } catch (Exception e1) { - - } - } - - return -9999; - } - - public static List getLogs(AbstractSpan tracingSpan) { - try { - List logs = FieldGetter.get2LevelParentFieldValue(tracingSpan, "logs"); - if (logs != null) { - return logs; - } - } catch (Exception e) { - try { - List logs = FieldGetter.getParentFieldValue(tracingSpan, "logs"); - if (logs != null) { - return logs; - } - } catch (Exception e1) { - - } - } - - return Collections.emptyList(); - } - - public static List getTags(AbstractSpan tracingSpan) { - try { - List tags = FieldGetter.get2LevelParentFieldValue(tracingSpan, "tags"); - if (tags != null) { - return tags; - } - } catch (Exception e) { - try { - List tags = FieldGetter.getParentFieldValue(tracingSpan, "tags"); - if (tags != null) { - return tags; - } - } catch (Exception e1) { - - } - } - - return Collections.emptyList(); - } - - public static SpanLayer getLayer(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "layer"); - } catch (Exception e) { - try { - return FieldGetter.getParentFieldValue(tracingSpan, "layer"); - } catch (Exception e1) { - - } - } - - return null; - } - - public static String getComponentName(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "componentName"); - } catch (Exception e) { - try { - return FieldGetter.getParentFieldValue(tracingSpan, "componentName"); - } catch (Exception e1) { - - } - } - - return null; - } - - public static int getComponentId(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "componentId"); - } catch (Exception e) { - try { - return FieldGetter.getParentFieldValue(tracingSpan, "componentId"); - } catch (Exception e1) { - - } - } - - return -1; - } - - public static boolean getErrorOccurred(AbstractSpan tracingSpan) { - try { - return FieldGetter.get2LevelParentFieldValue(tracingSpan, "errorOccurred"); - } catch (Exception e) { - try { - return FieldGetter.getParentFieldValue(tracingSpan, "errorOccurred"); - } catch (Exception e1) { - - } - } - - return false; - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/AgentServiceRule.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/AgentServiceRule.java deleted file mode 100644 index 820eaf6e142a..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/AgentServiceRule.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.tools; - -import java.util.HashMap; -import java.util.LinkedList; -import org.junit.rules.ExternalResource; -import org.skywalking.apm.agent.core.boot.BootService; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; -import org.skywalking.apm.agent.core.logging.core.LogLevel; -import org.skywalking.apm.agent.test.helper.FieldSetter; - -public class AgentServiceRule extends ExternalResource { - - @Override - protected void after() { - super.after(); - try { - FieldSetter.setValue(ServiceManager.INSTANCE.getClass(), "bootedServices", new HashMap()); - FieldSetter.setValue(IgnoredTracerContext.ListenerManager.class, "LISTENERS", new LinkedList()); - FieldSetter.setValue(TracingContext.ListenerManager.class, "LISTENERS", new LinkedList()); - ServiceManager.INSTANCE.shutdown(); - } catch (Exception e) { - } - } - - @Override - protected void before() throws Throwable { - super.before(); - Config.Logging.LEVEL = LogLevel.OFF; - ServiceManager.INSTANCE.boot(); - RemoteDownstreamConfig.Agent.APPLICATION_ID = 1; - RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1; - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentRefAssert.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentRefAssert.java deleted file mode 100644 index 8635469cc714..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentRefAssert.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.tools; - -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.test.helper.SegmentRefHelper; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class SegmentRefAssert { - public static void assertSegmentId(TraceSegmentRef ref, String segmentId) { - assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is(segmentId)); - } - - public static void assertSpanId(TraceSegmentRef ref, int spanId) { - assertThat(SegmentRefHelper.getSpanId(ref), is(spanId)); - } - - public static void assertPeerHost(TraceSegmentRef ref, String peerHost) { - assertThat(SegmentRefHelper.getPeerHost(ref), is(peerHost)); - } - - public static void assertEntryApplicationInstanceId(TraceSegmentRef ref, int entryApplicationInstanceID) { - assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(entryApplicationInstanceID)); - } - -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStorage.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStorage.java deleted file mode 100644 index d66e265276f3..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStorage.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.tools; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public class SegmentStorage { - private LinkedList traceSegments; - private LinkedList ignoredTracerContexts; - - public SegmentStorage() { - traceSegments = new LinkedList(); - ignoredTracerContexts = new LinkedList(); - } - - void addTraceSegment(TraceSegment segment) { - traceSegments.add(segment); - } - - public List getTraceSegments() { - return traceSegments; - } - - void addIgnoreTraceContext(IgnoredTracerContext context) { - this.ignoredTracerContexts.add(context); - } - - public LinkedList getIgnoredTracerContexts() { - return ignoredTracerContexts; - } -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStoragePoint.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStoragePoint.java deleted file mode 100644 index 90d18870540d..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentStoragePoint.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.tools; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SegmentStoragePoint { -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SpanAssert.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SpanAssert.java deleted file mode 100644 index 4cec9ebe372d..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SpanAssert.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.tools; - -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.network.trace.component.Component; - -import static junit.framework.TestCase.assertNotNull; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class SpanAssert { - public static void assertLogSize(AbstractSpan span, int exceptedSize) { - assertThat(SpanHelper.getLogs(span).size(), is(exceptedSize)); - } - - public static void assertTagSize(AbstractSpan span, int exceptedSize) { - assertThat(SpanHelper.getTags(span).size(), is(exceptedSize)); - } - - public static void assertException(LogDataEntity logDataEntity, Class throwableClass, - String message) { - Assert.assertThat(logDataEntity.getLogs().size(), is(4)); - Assert.assertThat(logDataEntity.getLogs().get(0).getValue(), CoreMatchers.is("error")); - Assert.assertThat(logDataEntity.getLogs().get(1).getValue(), CoreMatchers.is(throwableClass.getName())); - Assert.assertThat(logDataEntity.getLogs().get(2).getValue(), is(message)); - assertNotNull(logDataEntity.getLogs().get(3).getValue()); - } - - public static void assertException(LogDataEntity logDataEntity, Class throwableClass) { - Assert.assertThat(logDataEntity.getLogs().size(), is(4)); - Assert.assertThat(logDataEntity.getLogs().get(0).getValue(), CoreMatchers.is("error")); - Assert.assertThat(logDataEntity.getLogs().get(1).getValue(), CoreMatchers.is(throwableClass.getName())); - Assert.assertNull(logDataEntity.getLogs().get(2).getValue()); - assertNotNull(logDataEntity.getLogs().get(3).getValue()); - } - - public static void assertComponent(AbstractSpan span, Component component) { - assertThat(SpanHelper.getComponentId(span), is(component.getId())); - } - - public static void assertComponent(AbstractSpan span, String componentName) { - assertThat(SpanHelper.getComponentName(span), is(componentName)); - } - - public static void assertLayer(AbstractSpan span, SpanLayer spanLayer) { - assertThat(SpanHelper.getLayer(span), is(spanLayer)); - } - - public static void assertTag(AbstractSpan span, int index, String value) { - assertThat(SpanHelper.getTags(span).get(index).getValue(), is(value)); - } - - public static void assertOccurException(AbstractSpan span, boolean excepted) { - assertThat(SpanHelper.getErrorOccurred(span), is(excepted)); - } - -} diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/TracingSegmentRunner.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/TracingSegmentRunner.java deleted file mode 100644 index fc29609f3eaf..000000000000 --- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/TracingSegmentRunner.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.agent.test.tools; - -import java.lang.reflect.Field; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.Statement; -import org.skywalking.apm.agent.core.context.IgnoreTracerContextListener; -import org.skywalking.apm.agent.core.context.IgnoredTracerContext; -import org.skywalking.apm.agent.core.context.TracingContext; -import org.skywalking.apm.agent.core.context.TracingContextListener; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; - -public class TracingSegmentRunner extends BlockJUnit4ClassRunner { - private TracingContextListener tracingContextListener; - private IgnoreTracerContextListener ignoreTracerContextListener; - private Field field; - private Object targetObject; - private SegmentStorage tracingData; - - public TracingSegmentRunner(Class klass) throws InitializationError { - super(klass); - for (Field field : klass.getDeclaredFields()) { - if (field.isAnnotationPresent(SegmentStoragePoint.class) && field.getType().equals(SegmentStorage.class)) { - this.field = field; - this.field.setAccessible(true); - break; - } - } - } - - @Override - protected Object createTest() throws Exception { - targetObject = super.createTest(); - return targetObject; - } - - @Override protected Statement withAfters(FrameworkMethod method, Object target, final Statement statement) { - return new Statement() { - @Override public void evaluate() throws Throwable { - if (field != null) { - try { - tracingData = new SegmentStorage(); - field.set(targetObject, tracingData); - } catch (IllegalAccessException e) { - } - } - tracingContextListener = new TracingContextListener() { - @Override - public void afterFinished(TraceSegment traceSegment) { - tracingData.addTraceSegment(traceSegment); - } - }; - - ignoreTracerContextListener = new IgnoreTracerContextListener() { - @Override - public void afterFinished(IgnoredTracerContext tracerContext) { - tracingData.addIgnoreTraceContext(tracerContext); - } - }; - - TracingContext.ListenerManager.add(tracingContextListener); - IgnoredTracerContext.ListenerManager.add(ignoreTracerContextListener); - try { - statement.evaluate(); - } finally { - TracingContext.ListenerManager.remove(tracingContextListener); - IgnoredTracerContext.ListenerManager.remove(ignoreTracerContextListener); - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java new file mode 100644 index 000000000000..3fe1b800c150 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.log4j.v1.x; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * Created by wusheng on 2016/12/7. + */ +public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return "TID:" + ContextManager.getGlobalTraceId(); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java new file mode 100644 index 000000000000..6e6e0a0f0f7c --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.log4j.v1.x; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * Active the toolkit class "TraceIdPatternConverter". + * Should not dependency or import any class in "skywalking-toolkit-log4j-1.x" module. + * Activation's classloader is diff from "TraceIdPatternConverter", + * using direct will trigger classloader issue. + * + * @author wusheng + */ +public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { + /** + * @return the target class, which needs active. + */ + @Override + protected ClassMatch enhanceClass() { + return byName("TraceIdPatternConverter"); + } + + /** + * @return null, no need to intercept constructor of enhance class. + */ + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + /** + * @return the collection of {@link InstanceMethodsInterceptPoint}, represent the intercepted methods and their + * interceptors. + */ + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("convert"); + } + + @Override + public String getMethodsInterceptor() { + return "PrintTraceIdInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java deleted file mode 100644 index 7d4e1c4ab133..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.log4j.v1.x; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -/** - * Created by wusheng on 2016/12/7. - */ -public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - return "TID:" + ContextManager.getGlobalTraceId(); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java deleted file mode 100644 index 9357f33a4bad..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.log4j.v1.x; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * Active the toolkit class "org.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternConverter". - * Should not dependency or import any class in "skywalking-toolkit-log4j-1.x" module. - * Activation's classloader is diff from "org.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternConverter", - * using direct will trigger classloader issue. - * - * @author wusheng - */ -public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * @return the target class, which needs active. - */ - @Override - protected ClassMatch enhanceClass() { - return byName("org.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternConverter"); - } - - /** - * @return null, no need to intercept constructor of enhance class. - */ - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - /** - * @return the collection of {@link InstanceMethodsInterceptPoint}, represent the intercepted methods and their - * interceptors. - */ - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("convert"); - } - - @Override - public String getMethodsInterceptor() { - return "org.skywalking.apm.toolkit.activation.log.log4j.v1.x.PrintTraceIdInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/resources/skywalking-plugin.def index 7ae9703df93f..776b3a2cc196 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -toolkit-log4j=org.skywalking.apm.toolkit.activation.log.log4j.v1.x.TraceIdPatternConverterActivation +toolkit-log4j=TraceIdPatternConverterActivation diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java new file mode 100644 index 000000000000..93166bdeb4ab --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.log4j.v2.x; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * Active the toolkit class "org.apache.skywalking.apm.toolkit.log.logback.v2.x.LogbackPatternConverter". + * Should not dependency or import any class in "skywalking-toolkit-logback-2.x" module. + * Activation's classloader is diff from "org.apache.skywalking.apm.toolkit.log.logback.v2.x.LogbackPatternConverter", + * using direct will trigger classloader issue. + * + * @author wusheng + */ +public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePluginDefine { + /** + * @return the target class, which needs active. + */ + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName("org.apache.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender"); + } + + /** + * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their + * interceptors. + */ + @Override + protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[] { + new StaticMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("append"); + } + + @Override + public String getMethodsInterceptor() { + return "PrintTraceIdInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java new file mode 100644 index 000000000000..d56c7fa9c25d --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.log4j.v2.x; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; + +/** + * Created by wusheng on 2016/12/7. + */ +public class PrintTraceIdInterceptor implements StaticMethodsAroundInterceptor { + /** + * Override org.apache.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender.append(), + * + * @param method + * @param result change this result, to output the traceId. The origin append() method will not invoke. + */ + @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + MethodInterceptResult result) { + ((StringBuilder)allArguments[0]).append("TID:" + ContextManager.getGlobalTraceId()); + + //make sure origin method do not invoke. + result.defineReturnValue(null); + } + + @Override + public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Object ret) { + return null; + } + + @Override + public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java deleted file mode 100644 index 864b5af56142..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.log4j.v2.x; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * Active the toolkit class "org.skywalking.apm.toolkit.log.logback.v2.x.LogbackPatternConverter". - * Should not dependency or import any class in "skywalking-toolkit-logback-2.x" module. - * Activation's classloader is diff from "org.skywalking.apm.toolkit.log.logback.v2.x.LogbackPatternConverter", - * using direct will trigger classloader issue. - * - * @author wusheng - */ -public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePluginDefine { - /** - * @return the target class, which needs active. - */ - @Override - protected ClassMatch enhanceClass() { - return byName("org.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender"); - } - - /** - * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their - * interceptors. - */ - @Override - protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return new StaticMethodsInterceptPoint[] { - new StaticMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("append"); - } - - @Override - public String getMethodsInterceptor() { - return "org.skywalking.apm.toolkit.activation.log.log4j.v2.x.PrintTraceIdInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java deleted file mode 100644 index e507874f6ffb..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.log4j.v2.x; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; - -/** - * Created by wusheng on 2016/12/7. - */ -public class PrintTraceIdInterceptor implements StaticMethodsAroundInterceptor { - /** - * Override org.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender.append(), - * - * @param method - * @param result change this result, to output the traceId. The origin append() method will not invoke. - */ - @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - MethodInterceptResult result) { - ((StringBuilder)allArguments[0]).append("TID:" + ContextManager.getGlobalTraceId()); - - //make sure origin method do not invoke. - result.defineReturnValue(null); - } - - @Override - public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Object ret) { - return null; - } - - @Override - public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def index 6613c6d2a8d1..4ff7088658d9 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -toolkit-log4j2=org.skywalking.apm.toolkit.activation.log.log4j.v2.x.Log4j2OutputAppenderActivation +toolkit-log4j2=Log4j2OutputAppenderActivation diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java new file mode 100644 index 000000000000..37bcd42012a5 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * Active the toolkit class "org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter". + * Should not dependency or import any class in "skywalking-toolkit-logback-1.x" module. + * Activation's classloader is diff from "org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter", + * using direct will trigger classloader issue. + *

+ * Created by wusheng on 2016/12/7. + */ +public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { + /** + * @return the target class, which needs active. + */ + @Override + protected ClassMatch enhanceClass() { + return byName("org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter"); + } + + /** + * @return null, no need to intercept constructor of enhance class. + */ + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + /** + * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their + * interceptors. + */ + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("convert"); + } + + @Override + public String getMethodsInterceptor() { + return "PrintTraceIdInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java new file mode 100644 index 000000000000..339808664e64 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * Created by wusheng on 2016/12/7. + */ +public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor { + + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return "TID:" + ContextManager.getGlobalTraceId(); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java new file mode 100644 index 000000000000..429a806a1a03 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * Support MDC https://logback.qos.ch/manual/mdc.html + * @author: zhangkewei + */ +public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("convertTID"); + } + + @Override + public String getMethodsInterceptor() { + return "PrintMDCTraceIdInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName("org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.LogbackMDCPatternConverter"); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java new file mode 100644 index 000000000000..1f36adc39b45 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +import java.lang.reflect.Method; + +/** + * @author zhangkewei + */ +public class PrintMDCTraceIdInterceptor implements InstanceMethodsAroundInterceptor { + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return "TID:" + ContextManager.getGlobalTraceId(); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java deleted file mode 100644 index eba3c2a075b5..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.logback.v1.x; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * Active the toolkit class "org.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter". - * Should not dependency or import any class in "skywalking-toolkit-logback-1.x" module. - * Activation's classloader is diff from "org.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter", - * using direct will trigger classloader issue. - *

- * Created by wusheng on 2016/12/7. - */ -public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * @return the target class, which needs active. - */ - @Override - protected ClassMatch enhanceClass() { - return byName("org.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter"); - } - - /** - * @return null, no need to intercept constructor of enhance class. - */ - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - /** - * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their - * interceptors. - */ - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("convert"); - } - - @Override - public String getMethodsInterceptor() { - return "org.skywalking.apm.toolkit.activation.log.logback.v1.x.PrintTraceIdInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java deleted file mode 100644 index 9cd3c754b3b3..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.logback.v1.x; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -/** - * Created by wusheng on 2016/12/7. - */ -public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor { - - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - return "TID:" + ContextManager.getGlobalTraceId(); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java deleted file mode 100644 index e782c4e0794e..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * Support MDC https://logback.qos.ch/manual/mdc.html - * @author: zhangkewei - */ -public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("convertTID"); - } - - @Override - public String getMethodsInterceptor() { - return "org.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc.PrintMDCTraceIdInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return byName("org.skywalking.apm.toolkit.log.logback.v1.x.mdc.LogbackMDCPatternConverter"); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java deleted file mode 100644 index 5e6ced3d2cb0..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/PrintMDCTraceIdInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc; - -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -import java.lang.reflect.Method; - -/** - * @author zhangkewei - */ -public class PrintMDCTraceIdInterceptor implements InstanceMethodsAroundInterceptor { - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - return "TID:" + ContextManager.getGlobalTraceId(); - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/resources/skywalking-plugin.def index e910f4542067..2161c0dc155c 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -toolkit-logback=org.skywalking.apm.toolkit.activation.log.logback.v1.x.LogbackPatternConverterActivation -toolkit-logback=org.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc.MDCConverterActivation \ No newline at end of file +toolkit-logback=LogbackPatternConverterActivation +toolkit-logback=MDCConverterActivation diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java new file mode 100644 index 000000000000..c4dc144f1d14 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.continuation; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class ActivateInterceptor implements InstanceMethodsAroundInterceptor { + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Object contextSnapshot = objInst.getSkyWalkingDynamicField(); + if (contextSnapshot != null) { + ContextManager.continued((ContextSnapshot)contextSnapshot); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java new file mode 100644 index 000000000000..640500d89d11 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.continuation; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class ConstructorInterceptor implements InstanceConstructorInterceptor { + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + objInst.setSkyWalkingDynamicField(ContextManager.capture()); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java new file mode 100644 index 000000000000..5cbafdc8cb78 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.continuation; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link SkywalkingContinuationActivation} defines two interceptors to enhance the methods and constructor in class + * SkywalkingContinuation. + * + * 1. The ConstructorInterceptor + * interceptor enhance the constructor. + * + * 2. The ActivateInterceptor + * interceptor enhance the activate. + */ +public class SkywalkingContinuationActivation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "SkywalkingContinuation"; + private static final String CONSTRUCTOR_INTERCEPTOR = "ConstructorInterceptor"; + private static final String ACTIVATE_METHOD_INTERCEPTOR = "ActivateInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPTOR; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("activate"); + } + + @Override public String getMethodsInterceptor() { + return ACTIVATE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java new file mode 100644 index 000000000000..6cdf9810526a --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder; +import org.apache.skywalking.apm.toolkit.opentracing.Tag; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.util.StringUtil; + +public class ConstructorWithSpanBuilderInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + SkywalkingSpanBuilder spanBuilder = (SkywalkingSpanBuilder)allArguments[0]; + + AbstractSpan span; + if (spanBuilder.isEntry()) { + span = ContextManager.createEntrySpan(spanBuilder.getOperationName(), null); + } else if (spanBuilder.isExit() && (!StringUtil.isEmpty(spanBuilder.getPeer()))) { + span = ContextManager.createExitSpan(spanBuilder.getOperationName(), buildRemotePeer(spanBuilder)); + } else { + span = ContextManager.createLocalSpan(spanBuilder.getOperationName()); + } + + for (Tag tag : spanBuilder.getTags()) { + span.tag(tag.getKey(), tag.getValue()); + } + span.setComponent(spanBuilder.getComponentName()); + if (spanBuilder.isError()) { + span.errorOccurred(); + } + + objInst.setSkyWalkingDynamicField(span); + } + + private String buildRemotePeer(SkywalkingSpanBuilder spanBuilder) { + return spanBuilder.getPeer() + (spanBuilder.getPort() == 0 ? "" : ":" + spanBuilder.getPort()); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java new file mode 100644 index 000000000000..d639d0351e45 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class ConstructorWithTracerInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + objInst.setSkyWalkingDynamicField(ContextManager.activeSpan()); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java new file mode 100644 index 000000000000..b9b7f91ab4c5 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import java.util.Map; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; + +/** + * {@link SkywalkingSpanActivation} defines five interceptors to enhance the methods and constructor in class + * SkywalkingSpan. + * + * 1. The ConstructorWithSpanBuilderInterceptor + * interceptor enhance the constructor with SkywalkingSpanBuilder + * argument. + * + * 2. The ConstructorWithTracerInterceptor + * interceptor enhance the constructor with SkywalkingTracer + * argument. + * + * 3. The SpanFinishInterceptor + * interceptor enhance the finish method that the first argument type is {@link Long} + * + * 4. The SpanLogInterceptor + * interceptor enhance the log method that the first argument type is {@link Long} and the second + * argument type is {@link Map} + * + * 5. The SpanSetOperationNameInterceptor + * interceptor enhance the setOperationName method + **/ +public class SkywalkingSpanActivation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "SkywalkingSpan"; + + private static final String SPAN_BUILDER_CLASS_NAME = "SkywalkingSpanBuilder"; + private static final String CONSTRUCTOR_WITH_SPAN_BUILDER_INTERCEPTOR = "ConstructorWithSpanBuilderInterceptor"; + + private static final String SKYWALKING_TRACER_CLASS_NAME = "SkywalkingTracer"; + private static final String CONSTRUCTOR_WITH_TRACER_INTERCEPTOR = "ConstructorWithTracerInterceptor"; + + private static final String FINISH_METHOD_INTERCEPTOR = "SpanFinishInterceptor"; + private static final String LOG_INTERCEPTOR = "SpanLogInterceptor"; + private static final String SET_OPERATION_NAME_INTERCEPTOR = "SpanSetOperationNameInterceptor"; + private static final String SET_TAG_INTERCEPTOR = "SpanSetTagInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, SPAN_BUILDER_CLASS_NAME); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_SPAN_BUILDER_INTERCEPTOR; + } + }, + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, SKYWALKING_TRACER_CLASS_NAME); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_TRACER_INTERCEPTOR; + } + } + }; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("finish").and(takesArgument(0, long.class)); + } + + @Override + public String getMethodsInterceptor() { + return FINISH_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("log").and(takesArgument(0, long.class).and(takesArgument(1, Map.class))); + } + + @Override + public String getMethodsInterceptor() { + return LOG_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("setOperationName"); + } + + @Override + public String getMethodsInterceptor() { + return SET_OPERATION_NAME_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("setTag").and(takesArgument(0, String.class)).and(takesArgument(1, String.class)); + } + + @Override public String getMethodsInterceptor() { + return SET_TAG_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java new file mode 100644 index 000000000000..a043669ed4a3 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SpanFinishInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + AbstractSpan abstractSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField(); + if (abstractSpan != null) { + ContextManager.stopSpan(abstractSpan); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java new file mode 100644 index 000000000000..197cdd8ed500 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import java.lang.reflect.Method; +import java.util.Map; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * Created by xin on 2017/7/10. + */ +public class SpanLogInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + AbstractSpan abstractSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField(); + if (abstractSpan != null) { + abstractSpan.log(Long.parseLong(allArguments[0].toString()), (Map)allArguments[1]); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java new file mode 100644 index 000000000000..ed8c06a40489 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SpanSetOperationNameInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + AbstractSpan tracingSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField(); + if (tracingSpan != null) { + tracingSpan.setOperationName(allArguments[0].toString()); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java new file mode 100644 index 000000000000..3060b11b70bb --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.span; + +import io.opentracing.tag.Tags; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + AbstractSpan activeSpan = ContextManager.activeSpan(); + String tagKey = String.valueOf(allArguments[0]); + String tagValue = String.valueOf(allArguments[1]); + if (Tags.COMPONENT.getKey().equals(tagKey)) { + activeSpan.setComponent(tagValue); + } else if (Tags.PEER_SERVICE.getKey().equals(tagKey)) { + activeSpan.setOperationName(tagValue); + } else { + activeSpan.tag(tagKey, tagValue); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java new file mode 100644 index 000000000000..abbece53d5d2 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.tracer; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link SkywalkingTracerActivation} defines two interceptors to enhance the methods in + * class SkywalkingTracer. + * + * 1. The SkywalkingTracerInjectInterceptor + * interceptor enhance the extract method + * + * 2. The SkywalkingTracerExtractInterceptor + * interceptor enhance the inject method + **/ +public class SkywalkingTracerActivation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "SkywalkingTracer"; + private static final String INJECT_INTERCEPTOR = "SkywalkingTracerInjectInterceptor"; + private static final String EXTRACT_INTERCEPTOR = "SkywalkingTracerExtractInterceptor"; + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("inject"); + } + + @Override public String getMethodsInterceptor() { + return INJECT_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("extract"); + } + + @Override public String getMethodsInterceptor() { + return EXTRACT_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java new file mode 100644 index 000000000000..144efb39735c --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.tracer; + +import io.opentracing.propagation.Format; +import io.opentracing.propagation.TextMap; +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.Map; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.toolkit.opentracing.TextMapContext; + +public class SkywalkingTracerExtractInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Format format = (Format)allArguments[0]; + if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) { + TextMap textMapCarrier = (TextMap)allArguments[1]; + + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + Iterator> iterator = textMapCarrier.iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + if (next.getHeadKey().equals(entry.getKey())) { + next.setHeadValue(entry.getValue()); + break; + } + } + } + ContextManager.extract(contextCarrier); + } + return new TextMapContext(); + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java new file mode 100644 index 000000000000..a6303c791aa8 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing.tracer; + +import io.opentracing.propagation.Format; +import io.opentracing.propagation.TextMap; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SkywalkingTracerInjectInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + Format format = (Format)allArguments[1]; + if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) { + TextMap carrier = (TextMap)allArguments[2]; + ContextCarrier contextCarrier = new ContextCarrier(); + ContextManager.inject(contextCarrier); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + carrier.put(next.getHeadKey(), next.getHeadValue()); + } + } else { + //Don't support other format yet. + } + + return null; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java deleted file mode 100644 index 4a91ca104f9a..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.continuation; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class ActivateInterceptor implements InstanceMethodsAroundInterceptor { - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Object contextSnapshot = objInst.getSkyWalkingDynamicField(); - if (contextSnapshot != null) { - ContextManager.continued((ContextSnapshot)contextSnapshot); - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java deleted file mode 100644 index 4d8dab6efa31..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.continuation; - -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class ConstructorInterceptor implements InstanceConstructorInterceptor { - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - objInst.setSkyWalkingDynamicField(ContextManager.capture()); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java deleted file mode 100644 index fe44e7f9cd4d..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.continuation; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link SkywalkingContinuationActivation} defines two interceptors to enhance the methods and constructor in class - * org.skywalking.apm.toolkit.opentracing.SkywalkingContinuation. - * - * 1. The org.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor - * interceptor enhance the constructor. - * - * 2. The org.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor - * interceptor enhance the activate. - */ -public class SkywalkingContinuationActivation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.skywalking.apm.toolkit.opentracing.SkywalkingContinuation"; - private static final String CONSTRUCTOR_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor"; - private static final String ACTIVATE_METHOD_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override public String getConstructorInterceptor() { - return CONSTRUCTOR_INTERCEPTOR; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("activate"); - } - - @Override public String getMethodsInterceptor() { - return ACTIVATE_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java deleted file mode 100644 index 094c05a73e6d..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder; -import org.skywalking.apm.toolkit.opentracing.Tag; -import org.skywalking.apm.util.StringUtil; - -public class ConstructorWithSpanBuilderInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - SkywalkingSpanBuilder spanBuilder = (SkywalkingSpanBuilder)allArguments[0]; - - AbstractSpan span; - if (spanBuilder.isEntry()) { - span = ContextManager.createEntrySpan(spanBuilder.getOperationName(), null); - } else if (spanBuilder.isExit() && (!StringUtil.isEmpty(spanBuilder.getPeer()))) { - span = ContextManager.createExitSpan(spanBuilder.getOperationName(), buildRemotePeer(spanBuilder)); - } else { - span = ContextManager.createLocalSpan(spanBuilder.getOperationName()); - } - - for (Tag tag : spanBuilder.getTags()) { - span.tag(tag.getKey(), tag.getValue()); - } - span.setComponent(spanBuilder.getComponentName()); - if (spanBuilder.isError()) { - span.errorOccurred(); - } - - objInst.setSkyWalkingDynamicField(span); - } - - private String buildRemotePeer(SkywalkingSpanBuilder spanBuilder) { - return spanBuilder.getPeer() + (spanBuilder.getPort() == 0 ? "" : ":" + spanBuilder.getPort()); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java deleted file mode 100644 index 49799ff06000..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class ConstructorWithTracerInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - objInst.setSkyWalkingDynamicField(ContextManager.activeSpan()); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java deleted file mode 100644 index 3549a92b5a07..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import java.util.Map; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link SkywalkingSpanActivation} defines five interceptors to enhance the methods and constructor in class - * org.skywalking.apm.toolkit.opentracing.SkywalkingSpan. - * - * 1. The org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor - * interceptor enhance the constructor with org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder - * argument. - * - * 2. The org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithTracerInterceptor - * interceptor enhance the constructor with org.skywalking.apm.toolkit.opentracing.SkywalkingTracer - * argument. - * - * 3. The org.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor - * interceptor enhance the finish method that the first argument type is {@link Long} - * - * 4. The org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor - * interceptor enhance the log method that the first argument type is {@link Long} and the second - * argument type is {@link Map} - * - * 5. The org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor - * interceptor enhance the setOperationName method - **/ -public class SkywalkingSpanActivation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.skywalking.apm.toolkit.opentracing.SkywalkingSpan"; - - private static final String SPAN_BUILDER_CLASS_NAME = "org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder"; - private static final String CONSTRUCTOR_WITH_SPAN_BUILDER_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor"; - - private static final String SKYWALKING_TRACER_CLASS_NAME = "org.skywalking.apm.toolkit.opentracing.SkywalkingTracer"; - private static final String CONSTRUCTOR_WITH_TRACER_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithTracerInterceptor"; - - private static final String FINISH_METHOD_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor"; - private static final String LOG_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor"; - private static final String SET_OPERATION_NAME_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor"; - private static final String SET_TAG_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetTagInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] { - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, SPAN_BUILDER_CLASS_NAME); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_SPAN_BUILDER_INTERCEPTOR; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, SKYWALKING_TRACER_CLASS_NAME); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_TRACER_INTERCEPTOR; - } - } - }; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("finish").and(takesArgument(0, long.class)); - } - - @Override - public String getMethodsInterceptor() { - return FINISH_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("log").and(takesArgument(0, long.class).and(takesArgument(1, Map.class))); - } - - @Override - public String getMethodsInterceptor() { - return LOG_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("setOperationName"); - } - - @Override - public String getMethodsInterceptor() { - return SET_OPERATION_NAME_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("setTag").and(takesArgument(0, String.class)).and(takesArgument(1, String.class)); - } - - @Override public String getMethodsInterceptor() { - return SET_TAG_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java deleted file mode 100644 index ad7fcb735d74..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class SpanFinishInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - AbstractSpan abstractSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField(); - if (abstractSpan != null) { - ContextManager.stopSpan(abstractSpan); - } - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java deleted file mode 100644 index 665f6cbe8314..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import java.lang.reflect.Method; -import java.util.Map; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -/** - * Created by xin on 2017/7/10. - */ -public class SpanLogInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - AbstractSpan abstractSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField(); - if (abstractSpan != null) { - abstractSpan.log(Long.parseLong(allArguments[0].toString()), (Map)allArguments[1]); - } - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java deleted file mode 100644 index fe94d648a0f4..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class SpanSetOperationNameInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - AbstractSpan tracingSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField(); - if (tracingSpan != null) { - tracingSpan.setOperationName(allArguments[0].toString()); - } - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java deleted file mode 100644 index 2e88f7d21816..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.span; - -import io.opentracing.tag.Tags; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - AbstractSpan activeSpan = ContextManager.activeSpan(); - String tagKey = String.valueOf(allArguments[0]); - String tagValue = String.valueOf(allArguments[1]); - if (Tags.COMPONENT.getKey().equals(tagKey)) { - activeSpan.setComponent(tagValue); - } else if (Tags.PEER_SERVICE.getKey().equals(tagKey)) { - activeSpan.setOperationName(tagValue); - } else { - activeSpan.tag(tagKey, tagValue); - } - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java deleted file mode 100644 index 589e899adcdf..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.tracer; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link SkywalkingTracerActivation} defines two interceptors to enhance the methods in - * class org.skywalking.apm.toolkit.opentracing.SkywalkingTracer. - * - * 1. The org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor - * interceptor enhance the extract method - * - * 2. The org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor - * interceptor enhance the inject method - **/ -public class SkywalkingTracerActivation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.skywalking.apm.toolkit.opentracing.SkywalkingTracer"; - private static final String INJECT_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor"; - private static final String EXTRACT_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor"; - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("inject"); - } - - @Override public String getMethodsInterceptor() { - return INJECT_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("extract"); - } - - @Override public String getMethodsInterceptor() { - return EXTRACT_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java deleted file mode 100644 index f722e77cb790..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.tracer; - -import io.opentracing.propagation.Format; -import io.opentracing.propagation.TextMap; -import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.Map; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.toolkit.opentracing.TextMapContext; - -public class SkywalkingTracerExtractInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Format format = (Format)allArguments[0]; - if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) { - TextMap textMapCarrier = (TextMap)allArguments[1]; - - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - Iterator> iterator = textMapCarrier.iterator(); - while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - if (next.getHeadKey().equals(entry.getKey())) { - next.setHeadValue(entry.getValue()); - break; - } - } - } - ContextManager.extract(contextCarrier); - } - return new TextMapContext(); - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java deleted file mode 100644 index bfd0e0b8e929..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.opentracing.tracer; - -import io.opentracing.propagation.Format; -import io.opentracing.propagation.TextMap; -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.CarrierItem; -import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; - -public class SkywalkingTracerInjectInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - Format format = (Format)allArguments[1]; - if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) { - TextMap carrier = (TextMap)allArguments[2]; - ContextCarrier contextCarrier = new ContextCarrier(); - ContextManager.inject(contextCarrier); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - carrier.put(next.getHeadKey(), next.getHeadValue()); - } - } else { - //Don't support other format yet. - } - - return null; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/resources/skywalking-plugin.def index 2d0d689d21ec..fba03e047785 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/resources/skywalking-plugin.def @@ -1,3 +1,3 @@ -toolkit-opentracing=org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerActivation -toolkit-opentracing=org.skywalking.apm.toolkit.activation.opentracing.span.SkywalkingSpanActivation -toolkit-opentracing=org.skywalking.apm.toolkit.activation.opentracing.continuation.SkywalkingContinuationActivation +toolkit-opentracing=SkywalkingTracerActivation +toolkit-opentracing=SkywalkingSpanActivation +toolkit-opentracing=SkywalkingContinuationActivation diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java similarity index 79% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java index 19b4a88a3bb3..29d51e04c2d6 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java @@ -16,7 +16,25 @@ * */ -package org.skywalking.apm.toolkit.activation.opentracing; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.opentracing; import io.opentracing.Tracer; import io.opentracing.propagation.Format; @@ -26,6 +44,11 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.SegmentRefAssert; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -33,41 +56,33 @@ import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.ContextSnapshot; -import org.skywalking.apm.agent.core.context.SW3CarrierItem; -import org.skywalking.apm.agent.core.context.ids.ID; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor; -import org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor; -import org.skywalking.apm.toolkit.opentracing.SkywalkingContinuation; -import org.skywalking.apm.toolkit.opentracing.SkywalkingSpan; -import org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder; -import org.skywalking.apm.toolkit.opentracing.TextMapContext; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor; +import org.apache.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor; +import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingContinuation; +import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingSpan; +import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder; +import org.apache.skywalking.apm.toolkit.opentracing.TextMapContext; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertEntryApplicationInstanceId; -import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertPeerHost; -import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertSegmentId; -import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertSpanId; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLogSize; +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(TracingSegmentRunner.class) @@ -241,10 +256,10 @@ public void testExtractWithValidateContext() throws Throwable { List spans = SegmentHelper.getSpans(tracingSegment); assertThat(tracingSegment.getRefs().size(), is(1)); TraceSegmentRef ref = tracingSegment.getRefs().get(0); - assertSegmentId(ref, "1.343.222"); - assertSpanId(ref, 3); - assertEntryApplicationInstanceId(ref, 1); - assertPeerHost(ref, "127.0.0.1:8080"); + SegmentRefAssert.assertSegmentId(ref, "1.343.222"); + SegmentRefAssert.assertSpanId(ref, 3); + SegmentRefAssert.assertEntryApplicationInstanceId(ref, 1); + SegmentRefAssert.assertPeerHost(ref, "127.0.0.1:8080"); assertThat(spans.size(), is(1)); assertSpanCommonsAttribute(spans.get(0)); } @@ -317,7 +332,7 @@ public void testContinuation() throws Throwable { private void assertSpanCommonsAttribute(AbstractTracingSpan span) { assertThat(span.getOperationName(), is("testOperationName")); assertComponent(span, "test"); - assertLogSize(span, 1); + SpanAssert.assertLogSize(span, 1); } private void stopSpan() throws Throwable { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java new file mode 100644 index 000000000000..9d76663b9408 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link TraceAnnotationActivation} enhance the tag method of ActiveSpan + * by ActiveSpanTagInterceptor. + * + * @author zhangxin + */ +public class ActiveSpanTagActivation extends ClassStaticMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "ActiveSpan"; + public static final String INTERCEPTOR_CLASS = "ActiveSpanTagInterceptor"; + public static final String INTERCEPTOR_METHOD_NAME = "tag"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[] { + new StaticMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(INTERCEPTOR_METHOD_NAME); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java new file mode 100644 index 000000000000..5c0477d8dfec --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class ActiveSpanTagInterceptor implements StaticMethodsAroundInterceptor { + @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + MethodInterceptResult result) { + AbstractSpan activeSpan = null; + try { + activeSpan = ContextManager.activeSpan(); + activeSpan.tag(String.valueOf(allArguments[0]), String.valueOf(allArguments[1])); + } catch (NullPointerException e) { + } + } + + @Override public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Object ret) { + return ret; + } + + @Override + public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Throwable t) { + + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java new file mode 100644 index 000000000000..bc4ad3b56138 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.MethodAnnotationMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link TraceAnnotationActivation} enhance all method that annotated with org.apache.skywalking.apm.toolkit.trace.annotation.Trace + * by TraceAnnotationMethodInterceptor. + * + * @author zhangxin + */ +public class TraceAnnotationActivation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String TRACE_ANNOTATION_METHOD_INTERCEPTOR = "TraceAnnotationMethodInterceptor"; + public static final String TRACE_ANNOTATION = "Trace"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return isAnnotatedWith(named(TRACE_ANNOTATION)); + } + + @Override public String getMethodsInterceptor() { + return TRACE_ANNOTATION_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return MethodAnnotationMatch.byMethodAnnotationMatch(new String[] {TRACE_ANNOTATION}); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java new file mode 100644 index 000000000000..b33c4de8d38c --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.toolkit.trace.Trace; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * {@link TraceAnnotationMethodInterceptor} create a local span and set the operation name which fetch from + * org.apache.skywalking.apm.toolkit.trace.annotation.Trace.operationName. if the fetch value is blank string, and + * the operation name will be the method name. + * + * @author zhangxin + */ +public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Trace trace = method.getAnnotation(Trace.class); + String operationName = trace.operationName(); + if (operationName.length() == 0) { + operationName = generateOperationName(method); + } + + ContextManager.createLocalSpan(operationName); + } + + private String generateOperationName(Method method) { + StringBuilder operationName = new StringBuilder(method.getDeclaringClass().getName() + "." + method.getName() + "("); + Class[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + operationName.append(parameterTypes[i].getName()); + if (i < (parameterTypes.length - 1)) { + operationName.append(","); + } + } + operationName.append(")"); + return operationName.toString(); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java new file mode 100644 index 000000000000..05ba00b22e0f --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * Active the toolkit class "TraceContext". + * Should not dependency or import any class in "skywalking-toolkit-trace-context" module. + * Activation's classloader is diff from "TraceContext", + * using direct will trigger classloader issue. + *

+ * Created by xin on 2016/12/15. + */ +public class TraceContextActivation extends ClassStaticMethodsEnhancePluginDefine { + /** + * @return the target class, which needs active. + */ + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName("TraceContext"); + } + + /** + * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their + * interceptors. + */ + @Override + protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[] { + new StaticMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("traceId"); + } + + @Override + public String getMethodsInterceptor() { + return "TraceContextInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java new file mode 100644 index 000000000000..e94e9cf1a9c6 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class TraceContextInterceptor implements StaticMethodsAroundInterceptor { + + private ILog logger = LogManager.getLogger(TraceContextInterceptor.class); + + @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + MethodInterceptResult result) { + + } + + @Override + public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Object ret) { + return ContextManager.getGlobalTraceId(); + } + + @Override + public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, + Throwable t) { + logger.error("Failed to getDefault trace Id.", t); + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java deleted file mode 100644 index be4e3f75ec68..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagActivation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link TraceAnnotationActivation} enhance the tag method of org.skywalking.apm.toolkit.trace.ActiveSpan - * by org.skywalking.apm.toolkit.activation.trace.ActiveSpanTagInterceptor. - * - * @author zhangxin - */ -public class ActiveSpanTagActivation extends ClassStaticMethodsEnhancePluginDefine { - - public static final String ENHANCE_CLASS = "org.skywalking.apm.toolkit.trace.ActiveSpan"; - public static final String INTERCEPTOR_CLASS = "org.skywalking.apm.toolkit.activation.trace.ActiveSpanTagInterceptor"; - public static final String INTERCEPTOR_METHOD_NAME = "tag"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return new StaticMethodsInterceptPoint[] { - new StaticMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(INTERCEPTOR_METHOD_NAME); - } - - @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java deleted file mode 100644 index 55ada9b4eb9e..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/ActiveSpanTagInterceptor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; - -public class ActiveSpanTagInterceptor implements StaticMethodsAroundInterceptor { - @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - MethodInterceptResult result) { - AbstractSpan activeSpan = null; - try { - activeSpan = ContextManager.activeSpan(); - activeSpan.tag(String.valueOf(allArguments[0]), String.valueOf(allArguments[1])); - } catch (NullPointerException e) { - } - } - - @Override public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Object ret) { - return ret; - } - - @Override - public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Throwable t) { - - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java deleted file mode 100644 index 39d56f4504c6..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.MethodAnnotationMatch.byMethodAnnotationMatch; - -/** - * {@link TraceAnnotationActivation} enhance all method that annotated with org.skywalking.apm.toolkit.trace.annotation.Trace - * by org.skywalking.apm.toolkit.activation.trace.TraceAnnotationMethodInterceptor. - * - * @author zhangxin - */ -public class TraceAnnotationActivation extends ClassInstanceMethodsEnhancePluginDefine { - - public static final String TRACE_ANNOTATION_METHOD_INTERCEPTOR = "org.skywalking.apm.toolkit.activation.trace.TraceAnnotationMethodInterceptor"; - public static final String TRACE_ANNOTATION = "org.skywalking.apm.toolkit.trace.Trace"; - - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return isAnnotatedWith(named(TRACE_ANNOTATION)); - } - - @Override public String getMethodsInterceptor() { - return TRACE_ANNOTATION_METHOD_INTERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override protected ClassMatch enhanceClass() { - return byMethodAnnotationMatch(new String[] {TRACE_ANNOTATION}); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java deleted file mode 100644 index d58729859db6..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.toolkit.trace.Trace; - -/** - * {@link TraceAnnotationMethodInterceptor} create a local span and set the operation name which fetch from - * org.skywalking.apm.toolkit.trace.annotation.Trace.operationName. if the fetch value is blank string, and - * the operation name will be the method name. - * - * @author zhangxin - */ -public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Trace trace = method.getAnnotation(Trace.class); - String operationName = trace.operationName(); - if (operationName.length() == 0) { - operationName = generateOperationName(method); - } - - ContextManager.createLocalSpan(operationName); - } - - private String generateOperationName(Method method) { - StringBuilder operationName = new StringBuilder(method.getDeclaringClass().getName() + "." + method.getName() + "("); - Class[] parameterTypes = method.getParameterTypes(); - for (int i = 0; i < parameterTypes.length; i++) { - operationName.append(parameterTypes[i].getName()); - if (i < (parameterTypes.length - 1)) { - operationName.append(","); - } - } - operationName.append(")"); - return operationName.toString(); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java deleted file mode 100644 index 8abc422042d7..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine; -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * Active the toolkit class "org.skywalking.apm.toolkit.trace.TraceContext". - * Should not dependency or import any class in "skywalking-toolkit-trace-context" module. - * Activation's classloader is diff from "org.skywalking.apm.toolkit.trace.TraceContext", - * using direct will trigger classloader issue. - *

- * Created by xin on 2016/12/15. - */ -public class TraceContextActivation extends ClassStaticMethodsEnhancePluginDefine { - /** - * @return the target class, which needs active. - */ - @Override - protected ClassMatch enhanceClass() { - return byName("org.skywalking.apm.toolkit.trace.TraceContext"); - } - - /** - * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their - * interceptors. - */ - @Override - protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { - return new StaticMethodsInterceptPoint[] { - new StaticMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("traceId"); - } - - @Override - public String getMethodsInterceptor() { - return "org.skywalking.apm.toolkit.activation.trace.TraceContextInterceptor"; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } - }; - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java deleted file mode 100644 index 4566189407a9..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import java.lang.reflect.Method; -import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor; -import org.skywalking.apm.agent.core.logging.api.ILog; -import org.skywalking.apm.agent.core.logging.api.LogManager; - -public class TraceContextInterceptor implements StaticMethodsAroundInterceptor { - - private ILog logger = LogManager.getLogger(TraceContextInterceptor.class); - - @Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - MethodInterceptResult result) { - - } - - @Override - public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Object ret) { - return ContextManager.getGlobalTraceId(); - } - - @Override - public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class[] parameterTypes, - Throwable t) { - logger.error("Failed to getDefault trace Id.", t); - } -} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def index 26a9243a2093..72bfc0db0d7e 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def @@ -1,3 +1,3 @@ -toolkit-trace=org.skywalking.apm.toolkit.activation.trace.ActiveSpanTagActivation -toolkit-trace=org.skywalking.apm.toolkit.activation.trace.TraceAnnotationActivation -toolkit-trace=org.skywalking.apm.toolkit.activation.trace.TraceContextActivation +toolkit-trace=ActiveSpanTagActivation +toolkit-trace=TraceAnnotationActivation +toolkit-trace=TraceContextActivation diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java new file mode 100644 index 000000000000..43255e4195e4 --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.activation.trace; + +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.toolkit.trace.Trace; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class TraceAnnotationTest { + + @SegmentStoragePoint + private SegmentStorage storage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private EnhancedInstance enhancedInstance; + + private TraceAnnotationMethodInterceptor methodInterceptor; + private ActiveSpanTagInterceptor tagInterceptor; + private Object[] tagParameters; + private Class[] tagParameterTypes; + + @Before + public void setUp() throws Exception { + methodInterceptor = new TraceAnnotationMethodInterceptor(); + tagInterceptor = new ActiveSpanTagInterceptor(); + tagParameters = new Object[] {"testTagKey", "testTagValue"}; + tagParameterTypes = new Class[] {String.class, String.class}; + } + + @Test + public void testTraceWithOperationName() throws Throwable { + Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithOperationName"); + methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null); + tagInterceptor.beforeMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null); + tagInterceptor.afterMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null); + methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null); + + assertThat(storage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = storage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan tracingSpan = spans.get(0); + assertThat(tracingSpan.getOperationName(), is("testMethod")); + SpanAssert.assertLogSize(tracingSpan, 0); + SpanAssert.assertTagSize(tracingSpan, 1); + List tags = SpanHelper.getTags(tracingSpan); + assertThat(tags.get(0).getKey(), is("testTagKey")); + assertThat(tags.get(0).getValue(), is("testTagValue")); + } + + @Test + public void testTrace() throws Throwable { + Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithDefaultValue"); + methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null); + methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null); + + assertThat(storage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = storage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + + AbstractTracingSpan tracingSpan = spans.get(0); + assertThat(tracingSpan.getOperationName(), is(TestAnnotationMethodClass.class.getName() + "." + withOperationNameMethod.getName() + "()")); + SpanAssert.assertLogSize(tracingSpan, 0); + SpanAssert.assertTagSize(tracingSpan, 0); + } + + private class TestAnnotationMethodClass { + @Trace(operationName = "testMethod") + public void testMethodWithOperationName() { + } + + @Trace + public void testMethodWithDefaultValue() { + } + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java deleted file mode 100644 index 341ba1e125d0..000000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.skywalking.apm.toolkit.activation.trace; - -import java.lang.reflect.Method; -import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.skywalking.apm.agent.test.helper.SegmentHelper; -import org.skywalking.apm.agent.test.helper.SpanHelper; -import org.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.skywalking.apm.agent.test.tools.SegmentStorage; -import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.skywalking.apm.toolkit.trace.Trace; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLogSize; -import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTagSize; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class TraceAnnotationTest { - - @SegmentStoragePoint - private SegmentStorage storage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - private EnhancedInstance enhancedInstance; - - private TraceAnnotationMethodInterceptor methodInterceptor; - private ActiveSpanTagInterceptor tagInterceptor; - private Object[] tagParameters; - private Class[] tagParameterTypes; - - @Before - public void setUp() throws Exception { - methodInterceptor = new TraceAnnotationMethodInterceptor(); - tagInterceptor = new ActiveSpanTagInterceptor(); - tagParameters = new Object[] {"testTagKey", "testTagValue"}; - tagParameterTypes = new Class[] {String.class, String.class}; - } - - @Test - public void testTraceWithOperationName() throws Throwable { - Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithOperationName"); - methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null); - tagInterceptor.beforeMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null); - tagInterceptor.afterMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null); - methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null); - - assertThat(storage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = storage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan tracingSpan = spans.get(0); - assertThat(tracingSpan.getOperationName(), is("testMethod")); - assertLogSize(tracingSpan, 0); - assertTagSize(tracingSpan, 1); - List tags = SpanHelper.getTags(tracingSpan); - assertThat(tags.get(0).getKey(), is("testTagKey")); - assertThat(tags.get(0).getValue(), is("testTagValue")); - } - - @Test - public void testTrace() throws Throwable { - Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithDefaultValue"); - methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null); - methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null); - - assertThat(storage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = storage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); - - AbstractTracingSpan tracingSpan = spans.get(0); - assertThat(tracingSpan.getOperationName(), is(TestAnnotationMethodClass.class.getName() + "." + withOperationNameMethod.getName() + "()")); - assertLogSize(tracingSpan, 0); - assertTagSize(tracingSpan, 0); - } - - private class TestAnnotationMethodClass { - @Trace(operationName = "testMethod") - public void testMethodWithOperationName() { - } - - @Trace - public void testMethodWithDefaultValue() { - } - } -} diff --git a/apm-sniffer/pom.xml b/apm-sniffer/pom.xml index c8f04d2282b9..e78f71996bdc 100644 --- a/apm-sniffer/pom.xml +++ b/apm-sniffer/pom.xml @@ -40,6 +40,6 @@ 1.6 - org.skywalking.apm.dependencies + org.apache.skywalking.apm.dependencies diff --git a/docs/cn/Application-toolkit-log4j-1.x-CN.md b/docs/cn/Application-toolkit-log4j-1.x-CN.md index bb62cc839e15..a1dcef0058ec 100644 --- a/docs/cn/Application-toolkit-log4j-1.x-CN.md +++ b/docs/cn/Application-toolkit-log4j-1.x-CN.md @@ -6,11 +6,11 @@ {project.release.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-1.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-1.x/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-1.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-1.x/_latestVersion) * 配置layout ```properties -log4j.appender.CONSOLE.layout=org.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout +log4j.appender.CONSOLE.layout=TraceIdPatternLayout ``` * 在`layout.ConversionPattern`中设置 `%T`来展示traceid ( 在 2.0-2016版本中, 你应该设置为 %x, [为什么改变配置,请参考相关issue?](https://github.com/wu-sheng/sky-walking/issues/77) ) diff --git a/docs/cn/Application-toolkit-log4j-2.x-CN.md b/docs/cn/Application-toolkit-log4j-2.x-CN.md index 6a1d5199a951..33790310bef5 100644 --- a/docs/cn/Application-toolkit-log4j-2.x-CN.md +++ b/docs/cn/Application-toolkit-log4j-2.x-CN.md @@ -6,7 +6,7 @@ {project.release.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/_latestVersion) * 在log4j2.xml中的pattern 配置节,配置`[%traceId]` ```xml diff --git a/docs/cn/Application-toolkit-logback-1.x-CN.md b/docs/cn/Application-toolkit-logback-1.x-CN.md index 647842fefa46..0182c28ee691 100644 --- a/docs/cn/Application-toolkit-logback-1.x-CN.md +++ b/docs/cn/Application-toolkit-logback-1.x-CN.md @@ -6,13 +6,13 @@ {project.release.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/_latestVersion) * 在logback.xml中的`Pattern`配制节中,设置`%tid` ```xml - + %d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%n diff --git a/docs/cn/Application-toolkit-trace-CN.md b/docs/cn/Application-toolkit-trace-CN.md index 9c478f10d6bc..840690909c96 100644 --- a/docs/cn/Application-toolkit-trace-CN.md +++ b/docs/cn/Application-toolkit-trace-CN.md @@ -6,11 +6,11 @@ ${skywalking.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-trace/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-trace/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-trace/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-trace/_latestVersion) * 随时使用 `TraceContext.traceId()` API,在应用程序的任何地方获取traceId. ```java -import org.skywalking.apm.toolkit.trace.TraceContext; +import TraceContext; ... modelAndView.addObject("traceId", TraceContext.traceId()); diff --git a/docs/cn/FAQ/Too-many-gRPC-logs-CN.md b/docs/cn/FAQ/Too-many-gRPC-logs-CN.md index 8a192cdaee16..cb5adf7dfe54 100644 --- a/docs/cn/FAQ/Too-many-gRPC-logs-CN.md +++ b/docs/cn/FAQ/Too-many-gRPC-logs-CN.md @@ -4,4 +4,4 @@ **原因**:Skywalking采用了GRPC框架发送数据,GRPC框架读取log的配置文件进行日志输出。 -**解决方法**: 在log的配置文件中添加对`org.skywalking.apm.dependencies`包的过滤 +**解决方法**: 在log的配置文件中添加对`org.apache.skywalking.apm.dependencies`包的过滤 diff --git a/docs/cn/How-to-build-CN.md b/docs/cn/How-to-build-CN.md index baeeae5cbe7d..df5fbb0203f1 100644 --- a/docs/cn/How-to-build-CN.md +++ b/docs/cn/How-to-build-CN.md @@ -13,6 +13,6 @@ 1. 在IntelliJ Terminal中,执行`mvn compile -Dmaven.test.skip=true`进行编译 1. 设置gRPC的自动生成代码目录,为源码目录 - **apm-network/target/generated--sources/protobuf**目录下的`grpc-java`和`java`目录 - - **apm-collector/apm-collector-stream/target/protobuf**目录下的`grpc-java`和`java`目录 + - **apm-collector/apm-collector-remote/apm-remote-grpc-provider/target/protobuf**目录下的`grpc-java`和`java`目录 注:从3.2开始,网络通讯协议引入GRPC,所以增加上述的步骤 diff --git a/docs/cn/How-to-communicate-with-the-collector-CN.md b/docs/cn/How-to-communicate-with-the-collector-CN.md index be60332c3b09..8ca3b5b81089 100644 --- a/docs/cn/How-to-communicate-with-the-collector-CN.md +++ b/docs/cn/How-to-communicate-with-the-collector-CN.md @@ -38,7 +38,7 @@ https://github.com/OpenSkywalking/skywalking/blob/master/apm-network/src/main/pr syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "KeyWithIntegerValue.proto"; @@ -184,7 +184,7 @@ https://github.com/OpenSkywalking/skywalking/blob/master/apm-network/src/main/pr syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "Downstream.proto"; @@ -260,7 +260,7 @@ gRPC服务 syntax = "proto3"; option java_multiple_files = true; -option java_package = "org.skywalking.apm.network.proto"; +option java_package = "org.apache.skywalking.apm.network.proto"; import "Downstream.proto"; import "KeyWithStringValue.proto"; @@ -349,4 +349,4 @@ message LogMessage { - entryServiceName/entryServiceId - parentServiceName/parentServiceId - peerId/peer -- componentId为默认支持的插件id,非官方支持,需传输名称或修改服务端源代码。[官方组件列表](https://github.com/OpenSkywalking/skywalking/blob/master/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java) +- componentId为默认支持的插件id,非官方支持,需传输名称或修改服务端源代码。[官方组件列表](https://github.com/OpenSkywalking/skywalking/blob/master/apm-network/src/main/java/org.apache.skywalking.apm/network/trace/component/ComponentsDefine.java) diff --git a/docs/cn/Plugin-Development-Guide-CN.md b/docs/cn/Plugin-Development-Guide-CN.md index faba4c536346..b0e306e688d0 100644 --- a/docs/cn/Plugin-Development-Guide-CN.md +++ b/docs/cn/Plugin-Development-Guide-CN.md @@ -86,7 +86,7 @@ AbstractSpan提供了Span内部,进行操作的各项API ```java /** - * Set the component id, which defines in {@link org.skywalking.apm.network.trace.component.ComponentsDefine} + * Set the component id, which defines in {@link ComponentsDefine} * * @param component * @return the span for chaining. @@ -215,14 +215,14 @@ public interface InstanceMethodsInterceptPoint { 3. 定义skywalking-plugin.def文件 ```properties -tomcat-7.x/8.x=org.skywalking.apm.plugin.tomcat78x.define.TomcatInstrumentation +tomcat-7.x/8.x=TomcatInstrumentation ``` * 插件名称,要求全局唯一,命名规范:目标组件+版本号 * 插件定义类全名 #### 四. 实现拦截器逻辑 -我们继续以实现实例方法拦截为例,拦截器需要实现org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor。 +我们继续以实现实例方法拦截为例,拦截器需要实现org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor。 ```java /** * A interceptor, which intercept method's invocation. The target methods will be defined in {@link diff --git a/docs/cn/skywalking-opentracing-CN.md b/docs/cn/skywalking-opentracing-CN.md index 6f446526806b..ff8287f94b52 100644 --- a/docs/cn/skywalking-opentracing-CN.md +++ b/docs/cn/skywalking-opentracing-CN.md @@ -7,11 +7,11 @@ ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-opentracing/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-opentracing/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-opentracing/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-opentracing/_latestVersion) * 使用OpenTracing的标准API和桥接器,使用手动埋点 ```java -Tracer tracer = new org.skywalking.apm.toolkit.opentracing.SkyWalkingTracer(); +Tracer tracer = new org.apache.skywalking.apm.toolkit.opentracing.SkyWalkingTracer(); Tracer.SpanBuilder spanBuilder = tracer.buildSpan("/yourApplication/yourService"); ``` diff --git a/docs/en/Application-toolkit-log4j-1.x.md b/docs/en/Application-toolkit-log4j-1.x.md index 45ab8574b6b3..80a37d6904a0 100644 --- a/docs/en/Application-toolkit-log4j-1.x.md +++ b/docs/en/Application-toolkit-log4j-1.x.md @@ -6,11 +6,11 @@ {project.release.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-1.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apmg-toolkit-log4j-1.x/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-1.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apmg-toolkit-log4j-1.x/_latestVersion) * Config a layout ```properties -log4j.appender.CONSOLE.layout=org.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout +log4j.appender.CONSOLE.layout=TraceIdPatternLayout ``` * set `%T` in `layout.ConversionPattern` ( In 2.0-2016, you should use %x, [Why change?](https://github.com/wu-sheng/sky-walking/issues/77) ) diff --git a/docs/en/Application-toolkit-log4j-2.x.md b/docs/en/Application-toolkit-log4j-2.x.md index d44437e8c8cb..13fb77e259e1 100644 --- a/docs/en/Application-toolkit-log4j-2.x.md +++ b/docs/en/Application-toolkit-log4j-2.x.md @@ -6,7 +6,7 @@ {project.release.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-log4j-2.x/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-log4j-2.x/_latestVersion) * Config the `[%traceId]` pattern in your log4j2.xml ```xml diff --git a/docs/en/Application-toolkit-logback-1.x.md b/docs/en/Application-toolkit-logback-1.x.md index 69397e0eac36..6a52091a2d5f 100644 --- a/docs/en/Application-toolkit-logback-1.x.md +++ b/docs/en/Application-toolkit-logback-1.x.md @@ -6,7 +6,7 @@ {project.release.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-logback-1.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-logback-1.x/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-logback-1.x/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-logback-1.x/_latestVersion) * set `%tid` in `Pattern` section of logback.xml ```xml diff --git a/docs/en/Application-toolkit-trace.md b/docs/en/Application-toolkit-trace.md index 4997c6e1dd2f..e6dfdae17810 100644 --- a/docs/en/Application-toolkit-trace.md +++ b/docs/en/Application-toolkit-trace.md @@ -6,11 +6,11 @@ ${skywalking.version} ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-trace/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-trace/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-trace/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-trace/_latestVersion) * Use `TraceContext.traceId()` API to obtain traceId. ```java -import org.skywalking.apm.toolkit.trace.TraceContext; +import TraceContext; ... modelAndView.addObject("traceId", TraceContext.traceId()); diff --git a/docs/en/Opentracing.md b/docs/en/Opentracing.md index 6d2c6fb244d9..ce270c6e8a8d 100644 --- a/docs/en/Opentracing.md +++ b/docs/en/Opentracing.md @@ -7,11 +7,11 @@ ``` -   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.skywalking.apm-toolkit-opentracing/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.skywalking.apm-toolkit-opentracing/_latestVersion) +   [ ![Download](https://api.bintray.com/packages/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-opentracing/images/download.svg) ](https://bintray.com/wu-sheng/skywalking/org.apache.skywalking.apm-toolkit-opentracing/_latestVersion) * Use our OpenTracing tracer implementation ```java -Tracer tracer = new org.skywalking.apm.toolkit.opentracing.SkywalkingTracer(); +Tracer tracer = new SkywalkingTracer(); Tracer.SpanBuilder spanBuilder = tracer.buildSpan("/yourApplication/yourService"); ``` diff --git a/pom.xml b/pom.xml index 3a78460d1746..8ec4b55077e3 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ 2.11.7 1.6.4 0.4.13 - java.header + CHECKSTYLE_HEAD @@ -311,9 +311,9 @@ true true true - org/skywalking/apm/network/**/*.java, - org/skywalking/apm/collector/remote/grpc/**/*.java, - org/skywalking/apm/agent/core/context/ids/base64/*.java + org.apache.skywalking.apm/network/**/*.java, + org.apache.skywalking.apm/collector/remote/grpc/**/*.java, + org.apache.skywalking.apm/agent/core/context/ids/base64/*.java