From 89923d6a93aaebc530404b4d64d255cbf83145e9 Mon Sep 17 00:00:00 2001 From: zhang-wei Date: Sun, 17 Nov 2019 17:29:42 +0800 Subject: [PATCH] [test/plugin] immigrate grpc scenario (#3840) * grpc scenario * update support-version.list --- Jenkinsfile-Agent-Test-3 | 8 +- Jenkinsfile-Agent-Test-4 | 4 +- .../plugin/grpc/v1/CallServerInterceptor.java | 2 + .../resources/archetype-resources/pom.xml | 1 - .../scenarios/grpc-scenario/bin/startup.sh | 21 ++ .../grpc-scenario/config/expectedData.yaml | 253 ++++++++++++++++++ .../scenarios/grpc-scenario/configuration.yml | 23 ++ test/plugin/scenarios/grpc-scenario/pom.xml | 152 +++++++++++ .../src/main/assembly/assembly.xml | 41 +++ .../apm/testcase/grpc/Application.java | 35 +++ .../grpc/consumr/ConsumerInterceptor.java | 104 +++++++ .../grpc/controller/CaseController.java | 132 +++++++++ .../grpc/provider/ProviderConfiguration.java | 45 ++++ .../interceptor/ProviderInterceptor.java | 89 ++++++ .../service/GreeterBlockingServiceImpl.java | 31 +++ .../provider/service/GreeterServiceImpl.java | 52 ++++ .../src/main/proto/GreetService.proto | 39 +++ .../src/main/resources/application.yaml | 23 ++ .../src/main/resources/log4j2.xml | 30 +++ .../grpc-scenario/support-version.list | 42 +++ 20 files changed, 1123 insertions(+), 4 deletions(-) create mode 100644 test/plugin/scenarios/grpc-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/grpc-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/grpc-scenario/configuration.yml create mode 100644 test/plugin/scenarios/grpc-scenario/pom.xml create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/Application.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/consumr/ConsumerInterceptor.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/controller/CaseController.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/ProviderConfiguration.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/interceptor/ProviderInterceptor.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterBlockingServiceImpl.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterServiceImpl.java create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/proto/GreetService.proto create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/resources/application.yaml create mode 100644 test/plugin/scenarios/grpc-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/grpc-scenario/support-version.list diff --git a/Jenkinsfile-Agent-Test-3 b/Jenkinsfile-Agent-Test-3 index 1edfb2642..dfa346541 100755 --- a/Jenkinsfile-Agent-Test-3 +++ b/Jenkinsfile-Agent-Test-3 @@ -67,7 +67,7 @@ pipeline { sh './mvnw -f test/plugin/pom.xml clean package -DskipTests docker:build' } } - stage('Test Cases Report (119)') { + stage('Test Cases Report (140)') { steps { echo "Test Cases Report" } @@ -115,6 +115,12 @@ pipeline { sh 'bash test/plugin/run.sh mongodb-3.x-scenario' } } + + stage('grpc 1.0.0-1.9.0 (21)') { + steps { + sh 'bash test/plugin/run.sh grpc-scenario' + } + } } } } diff --git a/Jenkinsfile-Agent-Test-4 b/Jenkinsfile-Agent-Test-4 index d3b74e5b0..26fa0d264 100755 --- a/Jenkinsfile-Agent-Test-4 +++ b/Jenkinsfile-Agent-Test-4 @@ -115,7 +115,7 @@ pipeline { } } } - + stage('Group2') { stages { stage('elasticsearch-7.x-scenario 7.0.0-7.4.2 (11)') { @@ -165,4 +165,4 @@ pipeline { deleteDir() } } -} +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/CallServerInterceptor.java b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/CallServerInterceptor.java index 395ed7fc0..f8045c4a3 100644 --- a/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/CallServerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/CallServerInterceptor.java @@ -32,6 +32,7 @@ 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.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.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.util.StringUtil; @@ -66,6 +67,7 @@ public class CallServerInterceptor implements ServerInterceptor { final AbstractSpan span = ContextManager.createEntrySpan(OperationNameFormatUtil.formatOperationName(call.getMethodDescriptor()), contextCarrier); span.setComponent(ComponentsDefine.GRPC); + SpanLayer.asRPCFramework(span); try { return new ServerCallListener(handler.startCall(new ForwardingServerCall.SimpleForwardingServerCall(call) { @Override diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml index 68ae78b41..072ed8552 100644 --- a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml @@ -73,7 +73,6 @@ org.springframework.boot spring-boot-maven-plugin - 1.5.9.RELEASE diff --git a/test/plugin/scenarios/grpc-scenario/bin/startup.sh b/test/plugin/scenarios/grpc-scenario/bin/startup.sh new file mode 100644 index 000000000..b5a412aa0 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/bin/startup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +home="$(cd "$(dirname $0)"; pwd)" + +java -jar ${agent_opts} ${home}/../libs/grpc-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/grpc-scenario/config/expectedData.yaml b/test/plugin/scenarios/grpc-scenario/config/expectedData.yaml new file mode 100644 index 000000000..51a02e1c9 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/config/expectedData.yaml @@ -0,0 +1,253 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +registryItems: + applications: + - {grpc-scenario: 2} + instances: + - {grpc-scenario: 1} + operationNames: + - grpc-scenario: [Greeter.sayHello, GreeterBlocking.sayHello, + /grpc-scenario/case/grpc-scenario] + heartbeat: [] +segmentItems: + - applicationCode: grpc-scenario + segmentSize: gt 10 + segments: + - segmentId: not null + spans: + - operationName: GreeterBlocking.sayHello + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: /grpc-scenario/case/grpc-scenario, networkAddressId: 0, + entryEndpointId: 0, refType: CrossProcess, parentSpanId: 2, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '127.0.0.1:18080', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: /grpc-scenario/case/grpc-scenario, networkAddressId: 0, + entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '127.0.0.1:18080', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: GreeterBlocking.sayHello/server/RequestObserver/onNext + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: GreeterBlocking.sayHello, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello/server/RequestObserver/onNext + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: Greeter.sayHello, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello/client/ResponseObserver/onNext + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: /grpc-scenario/case/grpc-scenario, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello/client/ResponseObserver/onComplete + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: /grpc-scenario/case/grpc-scenario, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello/server/RequestObserver/onNext + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: Greeter.sayHello, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello/server/RequestObserver/onComplete + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: Greeter.sayHello, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: Greeter.sayHello + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + componentName: '' + isError: false + spanType: Exit + peer: '127.0.0.1:18080' + peerId: 0 + - operationName: GreeterBlocking.sayHello + operationId: 0 + parentSpanId: 0 + spanId: 2 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + componentName: '' + isError: false + spanType: Exit + peer: '127.0.0.1:18080' + peerId: 0 + - operationName: /grpc-scenario/case/grpc-scenario + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/grpc-scenario/case/grpc-scenario'} + - {key: http.method, value: GET} + - segmentId: not null + spans: + - operationName: Greeter.sayHello/client/ResponseObserver/onNext + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + refs: + - {parentEndpointId: 0, parentEndpoint: /grpc-scenario/case/grpc-scenario, networkAddressId: 0, + entryEndpointId: 0, refType: CrossThread, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '', entryEndpoint: /grpc-scenario/case/grpc-scenario, + entryServiceInstanceId: 1} + diff --git a/test/plugin/scenarios/grpc-scenario/configuration.yml b/test/plugin/scenarios/grpc-scenario/configuration.yml new file mode 100644 index 000000000..005282de9 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/configuration.yml @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +type: jvm +entryService: http://localhost:8080/grpc-scenario/case/grpc-scenario +healthCheck: http://localhost:8080/grpc-scenario/case/healthCheck +startScript: ./bin/startup.sh +framework: grpc-scenario +environment: +dependencies: \ No newline at end of file diff --git a/test/plugin/scenarios/grpc-scenario/pom.xml b/test/plugin/scenarios/grpc-scenario/pom.xml new file mode 100644 index 000000000..d6f8a139c --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/pom.xml @@ -0,0 +1,152 @@ + + + + + org.apache.skywalking.apm.testcase + grpc-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + + 1.6.0 + + 2.1.6.RELEASE + + + skywalking-grpc-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + + io.grpc + grpc-all + ${test.framework.version} + + + + + grpc-scenario + + + kr.motd.maven + os-maven-plugin + 1.5.0.Final + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ./target/ + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + + com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier} + + grpc-java + io.grpc:protoc-gen-grpc-java:${test.framework.version}:exe:${os.detected.classifier} + + + + + + compile + compile-custom + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/grpc-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/grpc-scenario/src/main/assembly/assembly.xml new file mode 100644 index 000000000..8707aeebd --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/grpc-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/Application.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/Application.java new file mode 100644 index 000000000..fc5ec9003 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/Application.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.grpc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/consumr/ConsumerInterceptor.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/consumr/ConsumerInterceptor.java new file mode 100644 index 000000000..68ddbb105 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/consumr/ConsumerInterceptor.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. + * + */ + +package org.apache.skywalking.apm.testcase.grpc.consumr; + +import io.grpc.CallOptions; +import io.grpc.Channel; +import io.grpc.ClientCall; +import io.grpc.ClientInterceptor; +import io.grpc.ForwardingClientCall; +import io.grpc.ForwardingClientCallListener; +import io.grpc.Metadata; +import io.grpc.MethodDescriptor; +import io.grpc.Status; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.annotation.Nullable; + +public class ConsumerInterceptor implements ClientInterceptor { + + private Logger logger = LogManager.getLogger(ConsumerInterceptor.class); + + @Override public ClientCall interceptCall(MethodDescriptor descriptor, + CallOptions options, Channel channel) { + logger.info("start interceptor!"); + logger.info("method type: {}", descriptor.getType()); + return new ForwardingClientCall.SimpleForwardingClientCall(channel.newCall(descriptor, options)) { + @Override public void start(Listener responseListener, Metadata headers) { + logger.info("Peer: {}", channel.authority()); + logger.info("Operation Name : {}", descriptor.getFullMethodName()); + Interceptor tracingResponseListener = new Interceptor(responseListener); + tracingResponseListener.contextSnapshot = "contextSnapshot"; + delegate().start(tracingResponseListener, headers); + } + + @Override public void cancel(@Nullable String message, @Nullable Throwable cause) { + logger.info("cancel"); + super.cancel(message, cause); + } + + @Override public void halfClose() { + logger.info("halfClose"); + super.halfClose(); + } + + @Override public void sendMessage(ReqT message) { + logger.info("sendMessage ...."); + super.sendMessage(message); + } + }; + } + + private static class Interceptor extends ForwardingClientCallListener.SimpleForwardingClientCallListener { + private Logger logger = LogManager.getLogger(Interceptor.class); + + private Object contextSnapshot; + + protected Interceptor(ClientCall.Listener delegate) { + super(delegate); + } + + @Override + public void onHeaders(Metadata headers) { + logger.info("on Headers"); + for (String key : headers.keys()) { + logger.info("Receive key: {}", key); + } + delegate().onHeaders(headers); + } + + @Override + public void onMessage(RespT message) { + logger.info("contextSnapshot: {}", contextSnapshot); + delegate().onMessage(message); + } + + @Override + public void onClose(Status status, Metadata trailers) { + logger.info("on close"); + delegate().onClose(status, trailers); + } + + @Override public void onReady() { + logger.info("on Ready"); + super.onReady(); + } + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/controller/CaseController.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/controller/CaseController.java new file mode 100644 index 000000000..75795829d --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/controller/CaseController.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. + * + */ + +package org.apache.skywalking.apm.testcase.grpc.controller; + +import io.grpc.ClientInterceptors; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.stub.ClientCallStreamObserver; +import io.grpc.stub.ClientResponseObserver; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.apm.testcase.grpc.consumr.ConsumerInterceptor; +import org.apache.skywalking.apm.testcase.grpc.proto.GreeterBlockingGrpc; +import org.apache.skywalking.apm.testcase.grpc.proto.GreeterGrpc; +import org.apache.skywalking.apm.testcase.grpc.proto.HelloReply; +import org.apache.skywalking.apm.testcase.grpc.proto.HelloRequest; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.PostConstruct; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +@RestController +@RequestMapping("/case") +public class CaseController { + + private static final Logger logger = LogManager.getLogger(CaseController.class); + + private static final String SUCCESS = "Success"; + + private final String gprcProviderHost = "127.0.0.1"; + private final int grpcProviderPort = 18080; + private ManagedChannel channel; + private GreeterGrpc.GreeterStub greeterStub; + private GreeterBlockingGrpc.GreeterBlockingBlockingStub greeterBlockingStub; + + @PostConstruct + public void up() { + channel = ManagedChannelBuilder.forAddress(gprcProviderHost, grpcProviderPort).usePlaintext(true).build(); + greeterStub = GreeterGrpc.newStub(ClientInterceptors.intercept(channel, new ConsumerInterceptor())); + greeterBlockingStub = GreeterBlockingGrpc.newBlockingStub(ClientInterceptors.intercept(channel, new ConsumerInterceptor())); + } + + @RequestMapping("/grpc-scenario") + @ResponseBody + public String testcase() { + greetService(); + greetBlockingService(); + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + // your codes + return SUCCESS; + } + + + private static List names() { + return Arrays.asList( + "Sophia", + "Jackson"); + } + + private void greetService() { + ClientResponseObserver helloReplyStreamObserver = new ClientResponseObserver() { + private ClientCallStreamObserver requestStream; + + @Override + public void beforeStart(ClientCallStreamObserver observer) { + this.requestStream = observer; + this.requestStream.setOnReadyHandler(new Runnable() { + Iterator iterator = names().iterator(); + + @Override + public void run() { + while (requestStream.isReady()) { + if (iterator.hasNext()) { + String name = iterator.next(); + HelloRequest request = HelloRequest.newBuilder().setName(name).build(); + requestStream.onNext(request); + } else { + requestStream.onCompleted(); + } + } + } + }); + } + + @Override + public void onNext(HelloReply reply) { + logger.info("Receive an message from provider. message: {}", reply.getMessage()); + requestStream.request(1); + } + + public void onError(Throwable throwable) { + logger.error("Failed to send data", throwable); + } + + public void onCompleted() { + logger.info("All Done"); + } + }; + + greeterStub.sayHello(helloReplyStreamObserver); + } + + private void greetBlockingService() { + HelloRequest request = HelloRequest.newBuilder().setName("Sophia").build(); + greeterBlockingStub.sayHello(request); + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/ProviderConfiguration.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/ProviderConfiguration.java new file mode 100644 index 000000000..2058f580b --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/ProviderConfiguration.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. + * + */ + +package org.apache.skywalking.apm.testcase.grpc.provider; + +import io.grpc.Server; +import io.grpc.ServerBuilder; +import io.grpc.ServerInterceptors; +import org.apache.skywalking.apm.testcase.grpc.provider.interceptor.ProviderInterceptor; +import org.apache.skywalking.apm.testcase.grpc.provider.service.GreeterBlockingServiceImpl; +import org.apache.skywalking.apm.testcase.grpc.provider.service.GreeterServiceImpl; +import org.springframework.beans.factory.annotation.Configurable; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +/** + * @author zhangwei + */ +@Configurable +@Component +public class ProviderConfiguration { + + @Bean(initMethod = "start", destroyMethod = "shutdown") + public Server server() { + return ServerBuilder.forPort(18080) + .addService(ServerInterceptors.intercept(new GreeterServiceImpl(), new ProviderInterceptor())) + .addService(ServerInterceptors.intercept(new GreeterBlockingServiceImpl(), new ProviderInterceptor())) + .build(); + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/interceptor/ProviderInterceptor.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/interceptor/ProviderInterceptor.java new file mode 100644 index 000000000..1ccd0bdba --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/interceptor/ProviderInterceptor.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. + * + */ + +package org.apache.skywalking.apm.testcase.grpc.provider.interceptor; + +import io.grpc.ForwardingServerCall; +import io.grpc.ForwardingServerCallListener; +import io.grpc.Metadata; +import io.grpc.ServerCall; +import io.grpc.ServerCallHandler; +import io.grpc.ServerInterceptor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; + +public class ProviderInterceptor implements ServerInterceptor { + private Logger logger = LogManager.getLogger(ProviderInterceptor.class); + + @Override + public ServerCall.Listener interceptCall(ServerCall call, Metadata metadata, + ServerCallHandler handler) { + Map headerMap = new HashMap(); + for (String key : metadata.keys()) { + logger.info("Receive key: {}", key); + if (!key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { + String value = metadata.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); + + headerMap.put(key, value); + } + } + logger.info("authority : {}", call.getAuthority()); + return new ForwardingServerCallListener.SimpleForwardingServerCallListener(handler.startCall(new ForwardingServerCall.SimpleForwardingServerCall(call) { + @Override + public void sendHeaders(Metadata responseHeaders) { + logger.info("sendHeaders...."); + Metadata.Key headerKey = Metadata.Key.of("test-server", Metadata.ASCII_STRING_MARSHALLER); + responseHeaders.put(headerKey, "test-server"); + delegate().sendHeaders(responseHeaders); + } + + @Override public void sendMessage(RespT message) { + delegate().sendMessage(message); + } + + }, metadata)) { + @Override public void onReady() { + logger.info("onReady...."); + delegate().onReady(); + } + + @Override public void onCancel() { + logger.info("onCancel...."); + delegate().onCancel(); + } + + @Override public void onComplete() { + logger.info("onComplete...."); + delegate().onComplete(); + } + + @Override public void onHalfClose() { + logger.info("onHalfClose...."); + delegate().onHalfClose(); + } + + @Override public void onMessage(ReqT message) { + logger.info("onMessage...."); + delegate().onMessage(message); + } + }; + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterBlockingServiceImpl.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterBlockingServiceImpl.java new file mode 100644 index 000000000..520f4011b --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterBlockingServiceImpl.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.grpc.provider.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.testcase.grpc.proto.GreeterBlockingGrpc; +import org.apache.skywalking.apm.testcase.grpc.proto.HelloReply; +import org.apache.skywalking.apm.testcase.grpc.proto.HelloRequest; + +public class GreeterBlockingServiceImpl extends GreeterBlockingGrpc.GreeterBlockingImplBase { + @Override public void sayHello(HelloRequest request, StreamObserver responseObserver) { + responseObserver.onNext(HelloReply.newBuilder().setMessage("Hi," + request.getName()).build()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterServiceImpl.java b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterServiceImpl.java new file mode 100644 index 000000000..00a77f898 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/java/org/apache/skywalking/apm/testcase/grpc/provider/service/GreeterServiceImpl.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. + * + */ + +package org.apache.skywalking.apm.testcase.grpc.provider.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.testcase.grpc.proto.GreeterGrpc; +import org.apache.skywalking.apm.testcase.grpc.proto.HelloReply; +import org.apache.skywalking.apm.testcase.grpc.proto.HelloRequest; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +public class GreeterServiceImpl extends GreeterGrpc.GreeterImplBase { + + private Logger logger = LogManager.getLogger(GreeterServiceImpl.class); + + @Override + public StreamObserver sayHello(final StreamObserver responseObserver) { + StreamObserver requestStreamObserver = new StreamObserver() { + public void onNext(HelloRequest request) { + logger.info("Receive an message from client. Message: {}", request.getName()); + responseObserver.onNext(HelloReply.newBuilder().setMessage("Hi," + request.getName()).build()); + } + + public void onError(Throwable throwable) { + responseObserver.onError(throwable); + } + + public void onCompleted() { + logger.info("End the stream."); + responseObserver.onCompleted(); + } + }; + return requestStreamObserver; + } +} diff --git a/test/plugin/scenarios/grpc-scenario/src/main/proto/GreetService.proto b/test/plugin/scenarios/grpc-scenario/src/main/proto/GreetService.proto new file mode 100644 index 000000000..f6c28f717 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/proto/GreetService.proto @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.testcase.grpc.proto"; + +service Greeter { + rpc SayHello (stream HelloRequest) returns (stream HelloReply) { + } +} + +service GreeterBlocking { + rpc SayHello (HelloRequest) returns (HelloReply) { + } +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} \ No newline at end of file diff --git a/test/plugin/scenarios/grpc-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/grpc-scenario/src/main/resources/application.yaml new file mode 100644 index 000000000..6a22b386b --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/resources/application.yaml @@ -0,0 +1,23 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +server: + port: 8080 + servlet: + context-path: /grpc-scenario +logging: + config: classpath:log4j2.xml \ No newline at end of file diff --git a/test/plugin/scenarios/grpc-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/grpc-scenario/src/main/resources/log4j2.xml new file mode 100644 index 000000000..9849ed5a8 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/grpc-scenario/support-version.list b/test/plugin/scenarios/grpc-scenario/support-version.list new file mode 100644 index 000000000..1ae34da03 --- /dev/null +++ b/test/plugin/scenarios/grpc-scenario/support-version.list @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# INTERNAL: HTTP/2 error code: INTERNAL_ERROR Received Goaway occur in test cases 1.0.0 to 1.5.0 +# So these versions were not included in support-version.list. if you know what caused it, please help us. + +# Contains only the last version number of each minor version +1.25.0 +1.24.2 +1.23.1 +1.22.3 +1.21.1 +1.20.0 +1.19.0 +1.18.0 +1.17.1 +1.16.1 +1.15.1 +1.14.0 +1.13.2 +1.12.1 +1.11.0 +1.10.1 +1.9.1 +1.8.0 +1.7.1 +1.7.0 +1.6.1 +1.6.0 \ No newline at end of file