From 79ed3bff4854de6a1e3ad85586d7dcda199ac96c Mon Sep 17 00:00:00 2001 From: wu-sheng Date: Thu, 4 Jan 2018 14:25:26 +0800 Subject: [PATCH 1/9] Add incoming attr for application node. --- .../src/main/resources/ui-graphql/application-layer.graphqls | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls index ef9fc7007..f8ccf0eb9 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls @@ -19,6 +19,9 @@ type ApplicationNode implements Node { numOfServerAlarm: Int! # The number of services alerting numOfServiceAlarm: Int! + # Incoming request node, means User or outside system access the cluster from this. + # Recommend the UI generate a User node for each incoming node + isIncomingNode: Boolean } # The conjectural node generated by exit span From e7b72eb2f94b4979900df65ddb87e87b68808dc3 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 4 Jan 2018 21:50:43 +0800 Subject: [PATCH 2/9] catch up the TODO list. --- .../ApplicationRegisterServiceHandler.java | 19 ++++++++----------- .../InstanceDiscoveryServiceHandler.java | 2 +- .../proto/ApplicationRegisterService.proto | 7 +++---- .../src/main/proto/DiscoveryService.proto | 3 +-- .../remote/AppAndServiceRegisterClient.java | 9 ++++----- pom.xml | 5 ----- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java index 8fa4070b3..e04aa2255 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java @@ -18,15 +18,14 @@ package org.apache.skywalking.apm.collector.agent.grpc.provider.handler; -import com.google.protobuf.ProtocolStringList; import io.grpc.stub.StreamObserver; import org.apache.skywalking.apm.collector.analysis.register.define.AnalysisRegisterModule; import org.apache.skywalking.apm.collector.analysis.register.define.service.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.ApplicationMappings; import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.apache.skywalking.apm.network.proto.Applications; import org.apache.skywalking.apm.network.proto.KeyWithIntegerValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,19 +43,17 @@ public class ApplicationRegisterServiceHandler extends ApplicationRegisterServic applicationIDService = moduleManager.find(AnalysisRegisterModule.NAME).getService(IApplicationIDService.class); } - @Override public void batchRegister(Applications request, StreamObserver responseObserver) { + @Override + public void applicationCodeRegister(Application request, StreamObserver responseObserver) { logger.debug("register application"); - ProtocolStringList applicationCodes = request.getApplicationCodesList(); ApplicationMappings.Builder builder = ApplicationMappings.newBuilder(); - for (int i = 0; i < applicationCodes.size(); i++) { - String applicationCode = applicationCodes.get(i); - int applicationId = applicationIDService.getOrCreateForApplicationCode(applicationCode); + String applicationCode = request.getApplicationCode(); + int applicationId = applicationIDService.getOrCreateForApplicationCode(applicationCode); - if (applicationId != 0) { - KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId).build(); - builder.addApplications(value); - } + if (applicationId != 0) { + KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId).build(); + builder.addApplications(value); } responseObserver.onNext(builder.build()); responseObserver.onCompleted(); diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java index 87a8ceca4..b8d271b51 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java @@ -47,7 +47,7 @@ public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrp } @Override - public void register(ApplicationInstance request, StreamObserver responseObserver) { + public void registerInstance(ApplicationInstance request, StreamObserver responseObserver) { long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(request.getRegisterTime()); int instanceId = instanceIDService.getOrCreateByAgentUUID(request.getApplicationId(), request.getAgentUUID(), timeBucket, buildOsInfo(request.getOsinfo())); ApplicationInstanceMapping.Builder builder = ApplicationInstanceMapping.newBuilder(); diff --git a/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto b/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto index c612eb395..c47875e2e 100644 --- a/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto +++ b/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto @@ -7,13 +7,12 @@ import "KeyWithIntegerValue.proto"; //register service for ApplicationCode, this service is called when service starts. service ApplicationRegisterService { - //TODO: TODO: `batchRegister` should be replaces by applicationCodeRegister - rpc batchRegister (Applications) returns (ApplicationMappings) { + rpc applicationCodeRegister (Application) returns (ApplicationMappings) { } } -message Applications { - repeated string applicationCodes = 1; +message Application { + string applicationCode = 1; } message ApplicationMappings { diff --git a/apm-protocol/apm-network/src/main/proto/DiscoveryService.proto b/apm-protocol/apm-network/src/main/proto/DiscoveryService.proto index 640b6d2d5..f2068f027 100644 --- a/apm-protocol/apm-network/src/main/proto/DiscoveryService.proto +++ b/apm-protocol/apm-network/src/main/proto/DiscoveryService.proto @@ -6,8 +6,7 @@ option java_package = "org.apache.skywalking.apm.network.proto"; import "Downstream.proto"; service InstanceDiscoveryService { - //TODO: need rename, `register` is a key word. - rpc register (ApplicationInstance) returns (ApplicationInstanceMapping) { + rpc registerInstance (ApplicationInstance) returns (ApplicationInstanceMapping) { } rpc heartbeat (ApplicationInstanceHeartbeat) returns (Downstream) { 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 index 3ebe836ac..800f3d4d3 100644 --- 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 @@ -37,12 +37,12 @@ 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.agent.core.os.OSUtil; +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.ApplicationMappings; import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.apache.skywalking.apm.network.proto.Applications; import org.apache.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc; import org.apache.skywalking.apm.network.proto.NetworkAddressRegisterServiceGrpc; import org.apache.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; @@ -109,9 +109,8 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList try { if (RemoteDownstreamConfig.Agent.APPLICATION_ID == DictionaryUtil.nullValue()) { if (applicationRegisterServiceBlockingStub != null) { - //TODO: `batchRegister` should be replaces by applicationCodeRegister - ApplicationMappings applicationMapping = applicationRegisterServiceBlockingStub.batchRegister( - Applications.newBuilder().addApplicationCodes(Config.Agent.APPLICATION_CODE).build()); + ApplicationMappings applicationMapping = applicationRegisterServiceBlockingStub.applicationCodeRegister( + Application.newBuilder().setApplicationCode(Config.Agent.APPLICATION_CODE).build()); if (applicationMapping.getApplicationsCount() > 0) { RemoteDownstreamConfig.Agent.APPLICATION_ID = applicationMapping.getApplications(0).getValue(); shouldTry = true; @@ -121,7 +120,7 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList if (instanceDiscoveryServiceBlockingStub != null) { if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID == DictionaryUtil.nullValue()) { - ApplicationInstanceMapping instanceMapping = instanceDiscoveryServiceBlockingStub.register(ApplicationInstance.newBuilder() + ApplicationInstanceMapping instanceMapping = instanceDiscoveryServiceBlockingStub.registerInstance(ApplicationInstance.newBuilder() .setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID) .setAgentUUID(PROCESS_UUID) .setRegisterTime(System.currentTimeMillis()) diff --git a/pom.xml b/pom.xml index 0473ff504..371a47c6b 100644 --- a/pom.xml +++ b/pom.xml @@ -68,11 +68,6 @@ https://github.com/apache/incubator-skywalking/issues - - travis - https://travis-ci.org/wu-sheng/sky-walking - - UTF-8 1.8 From fd08a731a46ca588b8ba85e350dd568dcc2f3a35 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 4 Jan 2018 22:29:52 +0800 Subject: [PATCH 3/9] Fix compile --- .../handler/ApplicationRegisterServiceHandlerTestCase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java index 84cd1775b..b8920e633 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java @@ -20,9 +20,9 @@ package org.apache.skywalking.apm.collector.agent.grpc.provider.handler; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import org.apache.skywalking.apm.network.proto.Application; import org.apache.skywalking.apm.network.proto.ApplicationMappings; import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; -import org.apache.skywalking.apm.network.proto.Applications; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,8 +39,8 @@ public class ApplicationRegisterServiceHandlerTestCase { ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build(); stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel); - Applications application = Applications.newBuilder().addApplicationCodes("test141").build(); - ApplicationMappings mapping = stub.batchRegister(application); + Application application = Application.newBuilder().setApplicationCode("test141").build(); + ApplicationMappings mapping = stub.applicationCodeRegister(application); logger.debug(mapping.getApplications(0).getKey() + ", " + mapping.getApplications(0).getValue()); } } From a108e8feeb536d6d4d913fc03102227b44476d39 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Thu, 4 Jan 2018 22:47:09 +0800 Subject: [PATCH 4/9] [Agent] fix import incorrector class in httpclient plugin --- .../apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 index bc62c5532..f3892eb52 100644 --- 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 @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.httpClient.v4; -import io.netty.handler.codec.http.HttpScheme; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; @@ -50,7 +49,7 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc AbstractSpan span = null; String remotePeer = httpHost.getHostName() + ":" + (httpHost.getPort() > 0 ? httpHost.getPort() : - HttpScheme.HTTPS.name().equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80); + "https".equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80); try { URL url = new URL(httpRequest.getRequestLine().getUri()); From ef284dc6d504c2f5246ebd18588476cab97274c1 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 4 Jan 2018 23:07:49 +0800 Subject: [PATCH 5/9] Make the applicationCodeRegister only for single code. --- .../handler/ApplicationRegisterServiceHandler.java | 8 ++++---- .../src/main/proto/ApplicationRegisterService.proto | 6 +++--- .../agent/core/remote/AppAndServiceRegisterClient.java | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java index e04aa2255..2a063b297 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandler.java @@ -24,7 +24,7 @@ import org.apache.skywalking.apm.collector.analysis.register.define.service.IApp 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.ApplicationMappings; +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; @@ -44,16 +44,16 @@ public class ApplicationRegisterServiceHandler extends ApplicationRegisterServic } @Override - public void applicationCodeRegister(Application request, StreamObserver responseObserver) { + public void applicationCodeRegister(Application request, StreamObserver responseObserver) { logger.debug("register application"); - ApplicationMappings.Builder builder = ApplicationMappings.newBuilder(); + ApplicationMapping.Builder builder = ApplicationMapping.newBuilder(); String applicationCode = request.getApplicationCode(); int applicationId = applicationIDService.getOrCreateForApplicationCode(applicationCode); if (applicationId != 0) { KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId).build(); - builder.addApplications(value); + builder.setApplication(value); } responseObserver.onNext(builder.build()); responseObserver.onCompleted(); diff --git a/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto b/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto index c47875e2e..e5b4deee1 100644 --- a/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto +++ b/apm-protocol/apm-network/src/main/proto/ApplicationRegisterService.proto @@ -7,7 +7,7 @@ import "KeyWithIntegerValue.proto"; //register service for ApplicationCode, this service is called when service starts. service ApplicationRegisterService { - rpc applicationCodeRegister (Application) returns (ApplicationMappings) { + rpc applicationCodeRegister (Application) returns (ApplicationMapping) { } } @@ -15,6 +15,6 @@ message Application { string applicationCode = 1; } -message ApplicationMappings { - repeated KeyWithIntegerValue applications = 1; +message ApplicationMapping { + KeyWithIntegerValue application = 1; } 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 index 800f3d4d3..db5b3d992 100644 --- 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 @@ -41,7 +41,7 @@ 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.ApplicationMappings; +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.NetworkAddressRegisterServiceGrpc; @@ -109,10 +109,10 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList try { if (RemoteDownstreamConfig.Agent.APPLICATION_ID == DictionaryUtil.nullValue()) { if (applicationRegisterServiceBlockingStub != null) { - ApplicationMappings applicationMapping = applicationRegisterServiceBlockingStub.applicationCodeRegister( + ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.applicationCodeRegister( Application.newBuilder().setApplicationCode(Config.Agent.APPLICATION_CODE).build()); - if (applicationMapping.getApplicationsCount() > 0) { - RemoteDownstreamConfig.Agent.APPLICATION_ID = applicationMapping.getApplications(0).getValue(); + if (applicationMapping != null) { + RemoteDownstreamConfig.Agent.APPLICATION_ID = applicationMapping.getApplication().getValue(); shouldTry = true; } } From d934ec53f2025262e98a20ae2e62c3f00f181261 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 4 Jan 2018 23:19:17 +0800 Subject: [PATCH 6/9] Fix test cases --- .../handler/ApplicationRegisterServiceHandlerTestCase.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java index b8920e633..aa29ffb03 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java @@ -21,6 +21,7 @@ package org.apache.skywalking.apm.collector.agent.grpc.provider.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.ApplicationMappings; import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; import org.slf4j.Logger; @@ -40,7 +41,7 @@ public class ApplicationRegisterServiceHandlerTestCase { stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel); Application application = Application.newBuilder().setApplicationCode("test141").build(); - ApplicationMappings mapping = stub.applicationCodeRegister(application); - logger.debug(mapping.getApplications(0).getKey() + ", " + mapping.getApplications(0).getValue()); + ApplicationMapping mapping = stub.applicationCodeRegister(application); + logger.debug(mapping.getApplication().getKey() + ", " + mapping.getApplication().getValue()); } } From c11f37ab9f358ed7c854f30ab58e18a40a9d39eb Mon Sep 17 00:00:00 2001 From: wusheng Date: Fri, 5 Jan 2018 07:54:32 +0800 Subject: [PATCH 7/9] Remove an unused import. --- .../handler/ApplicationRegisterServiceHandlerTestCase.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java index aa29ffb03..50d9e82dc 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/test/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/ApplicationRegisterServiceHandlerTestCase.java @@ -22,7 +22,6 @@ 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.ApplicationMappings; import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 4e643621737e7bee7157c5c161f60d4c26365e17 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Fri, 5 Jan 2018 11:03:03 +0800 Subject: [PATCH 8/9] [Agent] fix the spring plugin doesn't work --- .../commons/EnhanceRequireObjectCache.java | 12 +++- ...onMethodHandlerAdapterInstrumentation.java | 57 +++++++++++++++++++ .../InvokeHandlerMethodInterceptor.java | 47 +++++++++++++++ .../src/main/resources/skywalking-plugin.def | 1 + 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/define/AnnotationMethodHandlerAdapterInstrumentation.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/InvokeHandlerMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/resources/skywalking-plugin.def 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 index 4b80c011a..914882eed 100644 --- 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 @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.plugin.spring.mvc.commons; import java.lang.reflect.Method; @@ -26,13 +25,14 @@ import org.springframework.web.context.request.NativeWebRequest; public class EnhanceRequireObjectCache { private PathMappingCache pathMappingCache; private NativeWebRequest nativeWebRequest; + private HttpServletResponse httpResponse; public void setPathMappingCache(PathMappingCache pathMappingCache) { this.pathMappingCache = pathMappingCache; } public HttpServletResponse getHttpServletResponse() { - return (HttpServletResponse)nativeWebRequest.getNativeResponse(); + return httpResponse == null ? (HttpServletResponse)nativeWebRequest.getNativeResponse() : httpResponse; } public void setNativeWebRequest(NativeWebRequest nativeWebRequest) { @@ -50,4 +50,12 @@ public class EnhanceRequireObjectCache { public PathMappingCache getPathMappingCache() { return pathMappingCache; } + + public void setHttpResponse(HttpServletResponse httpResponse) { + this.httpResponse = httpResponse; + } + + public HttpServletResponse getHttpResponse() { + return httpResponse; + } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/define/AnnotationMethodHandlerAdapterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/define/AnnotationMethodHandlerAdapterInstrumentation.java new file mode 100644 index 000000000..cfaba1b92 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/define/AnnotationMethodHandlerAdapterInstrumentation.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. + * + */ + +package org.apache.skywalking.apm.plugin.spring.mvc.commons.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; + +public class AnnotationMethodHandlerAdapterInstrumentation 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("invokeHandlerMethod"); + } + + @Override public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.InvokeHandlerMethodInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName("org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"); + } +} 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/InvokeHandlerMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeHandlerMethodInterceptor.java new file mode 100644 index 000000000..7a502d21f --- /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/InvokeHandlerMethodInterceptor.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. + * + */ + +package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletResponse; +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; + +public class InvokeHandlerMethodInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + if (allArguments[2] instanceof EnhancedInstance) { + ((EnhanceRequireObjectCache)((EnhancedInstance)allArguments[2]).getSkyWalkingDynamicField()).setHttpResponse((HttpServletResponse)allArguments[1]); + } + } + + @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/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..6d6268840 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/resources/skywalking-plugin.def @@ -0,0 +1 @@ +spring-mvc-annotation=org.apache.skywalking.apm.plugin.spring.mvc.commons.define.AnnotationMethodHandlerAdapterInstrumentation From bfcb37269fc2ab6361796983563a2c0ffad26b5a Mon Sep 17 00:00:00 2001 From: ascrutae Date: Fri, 5 Jan 2018 14:17:15 +0800 Subject: [PATCH 9/9] [Agent] fix jetty client doesn't work in after version 9.1 --- .../jetty-client-9.0-plugin/pom.xml | 42 ++++++ .../SyncHttpRequestSendInterceptor.java | 85 +++++++++++ .../define/HttpRequestInstrumentation.java | 76 ++++++++++ .../src/main/resources/skywalking-plugin.def | 1 + .../SyncHttpRequestSendInterceptorTest.java | 141 ++++++++++++++++++ .../jetty-client-9.x-plugin/pom.xml | 2 +- .../SyncHttpRequestSendInterceptor.java | 24 ++- .../define/HttpRequestInstrumentation.java | 4 + .../SyncHttpRequestSendInterceptorTest.java | 8 +- .../apm-sdk-plugin/jetty-plugin/pom.xml | 1 + 10 files changed, 365 insertions(+), 19 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/define/HttpRequestInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/resources/skywalking-plugin.def create mode 100644 apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/pom.xml new file mode 100644 index 000000000..bc51af148 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/pom.xml @@ -0,0 +1,42 @@ + + + + + jetty-plugins + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + apm-jetty-client-9.0-plugin + jar + + jetty-client-9.0-plugin + http://maven.apache.org + + + + org.eclipse.jetty + jetty-client + 9.0.0.v20130308 + provided + + + diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptor.java new file mode 100644 index 000000000..0313bf401 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/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. + * + */ + +package org.apache.skywalking.apm.plugin.jetty.v90.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.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.client.HttpRequest; +import org.eclipse.jetty.http.HttpFields; +import org.eclipse.jetty.http.HttpMethod; + +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, getHttpMethod(request)); + 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); + } + + public String getHttpMethod(HttpRequest request) { + HttpMethod httpMethod = HttpMethod.GET; + + /** + * The method is null if the client using GET method. + * + * @see org.eclipse.jetty.client.HttpRequest#GET(String uri) + * @see org.eclipse.jetty.client.HttpRequest( org.eclipse.jetty.client.HttpClient client, long conversation, java.net.URI uri) + */ + if (request.getMethod() != null) { + httpMethod = request.getMethod(); + } + + return httpMethod.name(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/define/HttpRequestInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/define/HttpRequestInstrumentation.java new file mode 100644 index 000000000..62d5b87b5 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v90/client/define/HttpRequestInstrumentation.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. + * + */ + +package org.apache.skywalking.apm.plugin.jetty.v90.client.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; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * {@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 SYNC_SEND_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jetty.v90.client.SyncHttpRequestSendV90Interceptor"; + + @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; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override protected String[] witnessClasses() { + return new String[] {"org.eclipse.jetty.client.api.ProxyConfiguration"}; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..05bc01091 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1 @@ +jetty-client-9.0=org.apache.skywalking.apm.plugin.jetty.v90.client.define.HttpRequestInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptorTest.java new file mode 100644 index 000000000..f666301cd --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.0-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v90/client/SyncHttpRequestSendInterceptorTest.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 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.v90.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 SyncHttpRequestSendInterceptor 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 SyncHttpRequestSendInterceptor(); + 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/pom.xml b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/pom.xml index 9730602da..3c13eddc6 100644 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/pom.xml @@ -35,7 +35,7 @@ org.eclipse.jetty jetty-client - 9.0.0.v20130308 + 9.1.0.v20131115 provided 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 index 63fc9c58e..49ac74e9e 100644 --- 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 @@ -31,7 +31,6 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.eclipse.jetty.client.HttpRequest; import org.eclipse.jetty.http.HttpFields; -import org.eclipse.jetty.http.HttpMethod; public class SyncHttpRequestSendInterceptor implements InstanceMethodsAroundInterceptor { @@ -42,19 +41,8 @@ public class SyncHttpRequestSendInterceptor implements InstanceMethodsAroundInte ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, request.getHost() + ":" + request.getPort()); span.setComponent(ComponentsDefine.JETTY_CLIENT); - HttpMethod httpMethod = HttpMethod.GET; - /** - * The method is null if the client using GET method. - * - * @see org.eclipse.jetty.client.HttpRequest#GET(String uri) - * @see org.eclipse.jetty.client.HttpRequest( org.eclipse.jetty.client.HttpClient client, long conversation, java.net.URI uri) - */ - if (request.getMethod() != null) { - httpMethod = request.getMethod(); - } - - Tags.HTTP.METHOD.set(span, httpMethod.asString()); + Tags.HTTP.METHOD.set(span, getHttpMethod(request)); Tags.URL.set(span, request.getURI().toString()); SpanLayer.asHttp(span); @@ -77,4 +65,14 @@ public class SyncHttpRequestSendInterceptor implements InstanceMethodsAroundInte Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } + + public String getHttpMethod(HttpRequest request) { + String method = request.getMethod(); + + if (method == null || method.length() == 0) { + method = "GET"; + } + + return method; + } } 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 index 147006dee..53d454e8d 100644 --- 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 @@ -70,4 +70,8 @@ public class HttpRequestInstrumentation extends ClassInstanceMethodsEnhancePlugi @Override protected ClassMatch enhanceClass() { return NameMatch.byName(ENHANCE_CLASS); } + + @Override protected String[] witnessClasses() { + return new String[] {"org.eclipse.jetty.client.AbstractHttpClientTransport"}; + } } 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 index 625e2d059..a084bb04f 100644 --- 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 @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.plugin.jetty.v9.client; import java.net.URI; @@ -31,9 +30,9 @@ 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.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; @@ -42,7 +41,6 @@ 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; @@ -130,8 +128,8 @@ public class SyncHttpRequestSendInterceptorTest { } - @Override public HttpMethod getMethod() { - return HttpMethod.GET; + @Override public String getMethod() { + return "GET"; } @Override public URI getURI() { diff --git a/apm-sniffer/apm-sdk-plugin/jetty-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/jetty-plugin/pom.xml index ec6914976..c80d1c488 100644 --- a/apm-sniffer/apm-sdk-plugin/jetty-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/jetty-plugin/pom.xml @@ -31,6 +31,7 @@ jetty-client-9.x-plugin jetty-server-9.x-plugin + jetty-client-9.0-plugin pom