From bd7912106aede5f79dbcfcdafe5c13c4378d8629 Mon Sep 17 00:00:00 2001 From: hutaishi Date: Sat, 7 May 2022 10:23:23 +0800 Subject: [PATCH] Apache ShenYu (incubating) plugin support grpc,sofarpc,motan,tars (#170) --- .github/workflows/plugins-test.3.yaml | 2 + CHANGES.md | 1 + .../shenyu/v24x/GrpcPluginInterceptor.java | 50 ++++ .../v24x/MotanRpcPluginInterceptor.java | 50 ++++ .../shenyu/v24x/SofaRpcPluginInterceptor.java | 50 ++++ .../shenyu/v24x/TarsRpcPluginInterceptor.java | 50 ++++ .../define/GrpcPluginInstrumentation.java | 72 +++++ .../define/MotanRpcPluginInstrumentation.java | 72 +++++ .../define/SofaRpcPluginInstrumentation.java | 72 +++++ .../define/TarsRpcPluginInstrumentation.java | 72 +++++ .../plugin/shenyu/v24x/util/CommonUtil.java | 8 + .../src/main/resources/skywalking-plugin.def | 4 + .../java-agent/Supported-list.md | 2 +- .../config/expectedData.yaml | 166 ++++++++++++ .../configuration.yml | 24 ++ .../shenyu-2.4.x-grpc-scenario/pom.xml | 111 ++++++++ .../shenyu-grpc-dist/bin/startup.sh | 29 ++ .../shenyu-grpc-dist/pom.xml | 59 ++++ .../src/main/assembly/assembly.xml | 51 ++++ .../shenyu-grpc-entry/pom.xml | 67 +++++ .../shenyu/entry/EntryApplication.java | 29 ++ .../entry/controller/HttpEntryController.java | 67 +++++ .../src/main/resources/application.yml | 18 ++ .../shenyu-grpc-gateway/pom.xml | 85 ++++++ .../shenyu/gateway/GatewayApplication.java | 33 +++ .../shenyu/gateway/init/InitRouterRunner.java | 102 +++++++ .../src/main/resources/application.yml | 23 ++ .../src/main/resources/shenyu-plugin.json | 252 ++++++++++++++++++ .../src/main/resources/shenyu-rule.json | 41 +++ .../src/main/resources/shenyu-selector.json | 43 +++ .../shenyu-grpc-service/pom.xml | 100 +++++++ .../apm/testcase/shenyu/http/Application.java | 29 ++ .../shenyu/http/service/EchoServiceImpl.java | 38 +++ .../http/service/ServiceConfiguration.java | 50 ++++ .../http/support/constant/Constants.java | 29 ++ .../support/dynamic/DynamicJsonMessage.java | 130 +++++++++ .../DynamicMessageServiceTranslator.java | 125 +++++++++ .../DynamicToProtoServerCallListener.java | 81 ++++++ .../dynamic/ProtoToDynamicServerCall.java | 52 ++++ .../src/main/resources/application.yml | 20 ++ .../src/main/resources/proto/echo.proto | 35 +++ .../support-version.list | 18 ++ .../config/expectedData.yaml | 135 ++++++++++ .../configuration.yml | 24 ++ .../shenyu-2.4.x-sofarpc-scenario/pom.xml | 116 ++++++++ .../shenyu-sofarpc-dist/bin/startup.sh | 29 ++ .../shenyu-sofarpc-dist/pom.xml | 59 ++++ .../src/main/assembly/assembly.xml | 51 ++++ .../shenyu-sofarpc-entry/pom.xml | 67 +++++ .../shenyu/entry/EntryApplication.java | 29 ++ .../entry/controller/HttpEntryController.java | 58 ++++ .../src/main/resources/application.yml | 18 ++ .../shenyu-sofarpc-gateway/pom.xml | 85 ++++++ .../shenyu/gateway/GatewayApplication.java | 33 +++ .../shenyu/gateway/init/InitRouterRunner.java | 124 +++++++++ .../src/main/resources/application.yml | 23 ++ .../src/main/resources/shenyu-plugin.json | 252 ++++++++++++++++++ .../src/main/resources/shenyu-rule.json | 41 +++ .../src/main/resources/shenyu-selector.json | 43 +++ .../shenyu-sofarpc-service/pom.xml | 69 +++++ .../shenyu/sofarpc/SofaRpcApplication.java | 31 +++ .../shenyu/sofarpc/SofaRpcConfiguration.java | 49 ++++ .../shenyu/sofarpc/interfaces/SofaBean.java | 31 +++ .../interfaces/SofaRpcDemoService.java | 24 ++ .../service/SofaRpcDemoServiceImpl.java | 31 +++ .../src/main/resources/application.yml | 20 ++ .../support-version.list | 18 ++ 67 files changed, 3871 insertions(+), 1 deletion(-) create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GrpcPluginInterceptor.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/MotanRpcPluginInterceptor.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/SofaRpcPluginInterceptor.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/TarsRpcPluginInterceptor.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/GrpcPluginInstrumentation.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/MotanRpcPluginInstrumentation.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/SofaRpcPluginInstrumentation.java create mode 100644 apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/TarsRpcPluginInstrumentation.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/configuration.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/bin/startup.sh create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-plugin.json create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-rule.json create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-selector.json create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/Application.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/EchoServiceImpl.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/ServiceConfiguration.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/constant/Constants.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicJsonMessage.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicMessageServiceTranslator.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicToProtoServerCallListener.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/ProtoToDynamicServerCall.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/proto/echo.proto create mode 100644 test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/support-version.list create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/configuration.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/bin/startup.sh create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-plugin.json create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-rule.json create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-selector.json create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/pom.xml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcApplication.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcConfiguration.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaBean.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaRpcDemoService.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/service/SofaRpcDemoServiceImpl.java create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/support-version.list diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml index 3e9f4ffd0..fb82d78be 100644 --- a/.github/workflows/plugins-test.3.yaml +++ b/.github/workflows/plugins-test.3.yaml @@ -101,6 +101,8 @@ jobs: - jdk-threadpool-scenario - shenyu-2.4.x-dubbo-scenario - grpc-generic-call-scenario + - shenyu-2.4.x-grpc-scenario + - shenyu-2.4.x-sofarpc-scenario steps: - uses: actions/checkout@v2 with: diff --git a/CHANGES.md b/CHANGES.md index 3605abad9..47a99d733 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Release Notes. * Change the dateformat of logs to `yyyy-MM-dd HH:mm:ss.SSS`(was `yyyy-MM-dd HH:mm:ss:SSS`). * Fix NPE in elasticsearch plugin. * Grpc plugin support trace client async generic call(without grpc stubs), support Method type: `UNARY`、`SERVER_STREAMING`. +* Enhance Apache ShenYu (incubating) plugin: support trace `grpc`,`sofarpc`,`motan`,`tars` rpc proxy. #### Documentation diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GrpcPluginInterceptor.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GrpcPluginInterceptor.java new file mode 100644 index 000000000..e8b1a287d --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GrpcPluginInterceptor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x; + +import java.lang.reflect.Method; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.shenyu.v24x.util.CommonUtil; + +/** + * shenyu GrpcPlugin Interceptor. + */ +public class GrpcPluginInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + CommonUtil.createLocalSpan(allArguments, "gRPCPlugin"); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return CommonUtil.stopLocalSpan(allArguments, ret); + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + CommonUtil.logErrorLocalSpan(allArguments, t); + } +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/MotanRpcPluginInterceptor.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/MotanRpcPluginInterceptor.java new file mode 100644 index 000000000..ad5713abc --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/MotanRpcPluginInterceptor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x; + +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.shenyu.v24x.util.CommonUtil; + +import java.lang.reflect.Method; + +/** + * shenyu MotanRpcPlugin Interceptor. + */ +public class MotanRpcPluginInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + CommonUtil.createLocalSpan(allArguments, "MotanRpcPlugin"); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return CommonUtil.stopLocalSpan(allArguments, ret); + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + CommonUtil.logErrorLocalSpan(allArguments, t); + } +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/SofaRpcPluginInterceptor.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/SofaRpcPluginInterceptor.java new file mode 100644 index 000000000..77e8c1173 --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/SofaRpcPluginInterceptor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x; + +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.shenyu.v24x.util.CommonUtil; + +import java.lang.reflect.Method; + +/** + * shenyu SofaRpcPlugin Interceptor. + */ +public class SofaRpcPluginInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + CommonUtil.createLocalSpan(allArguments, "SofaRpcPlugin"); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return CommonUtil.stopLocalSpan(allArguments, ret); + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + CommonUtil.logErrorLocalSpan(allArguments, t); + } +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/TarsRpcPluginInterceptor.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/TarsRpcPluginInterceptor.java new file mode 100644 index 000000000..3e47ea446 --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/TarsRpcPluginInterceptor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x; + +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.shenyu.v24x.util.CommonUtil; + +import java.lang.reflect.Method; + +/** + * shenyu TarsRpcPlugin Interceptor. + */ +public class TarsRpcPluginInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + CommonUtil.createLocalSpan(allArguments, "TarsRpcPlugin"); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + return CommonUtil.stopLocalSpan(allArguments, ret); + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + CommonUtil.logErrorLocalSpan(allArguments, t); + } +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/GrpcPluginInstrumentation.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/GrpcPluginInstrumentation.java new file mode 100644 index 000000000..2d8e1dd38 --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/GrpcPluginInstrumentation.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x.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 GrpcPluginInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.shenyu.plugin.grpc.GrpcPlugin"; + + private static final String INTERCEPT_CLASS = + "org.apache.skywalking.apm.plugin.shenyu.v24x.GrpcPluginInterceptor"; + + private static final String INTERCEPT_METHOD = "doExecute"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/MotanRpcPluginInstrumentation.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/MotanRpcPluginInstrumentation.java new file mode 100644 index 000000000..bd30e7fbb --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/MotanRpcPluginInstrumentation.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x.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 MotanRpcPluginInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.shenyu.plugin.motan.MotanPlugin"; + + private static final String INTERCEPT_CLASS = + "org.apache.skywalking.apm.plugin.shenyu.v24x.MotanRpcPluginInterceptor"; + + private static final String INTERCEPT_METHOD = "doExecute"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/SofaRpcPluginInstrumentation.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/SofaRpcPluginInstrumentation.java new file mode 100644 index 000000000..a45a30555 --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/SofaRpcPluginInstrumentation.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x.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 SofaRpcPluginInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.shenyu.plugin.sofa.SofaPlugin"; + + private static final String INTERCEPT_CLASS = + "org.apache.skywalking.apm.plugin.shenyu.v24x.SofaRpcPluginInterceptor"; + + private static final String INTERCEPT_METHOD = "doExecute"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/TarsRpcPluginInstrumentation.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/TarsRpcPluginInstrumentation.java new file mode 100644 index 000000000..f6e2c9af0 --- /dev/null +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/TarsRpcPluginInstrumentation.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.shenyu.v24x.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 TarsRpcPluginInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.shenyu.plugin.tars.TarsPlugin"; + + private static final String INTERCEPT_CLASS = + "org.apache.skywalking.apm.plugin.shenyu.v24x.TarsRpcPluginInterceptor"; + + private static final String INTERCEPT_METHOD = "doExecute"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/util/CommonUtil.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/util/CommonUtil.java index be15215bc..b8e005479 100644 --- a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/util/CommonUtil.java +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/util/CommonUtil.java @@ -21,9 +21,11 @@ package org.apache.skywalking.apm.plugin.shenyu.v24x.util; import static org.apache.skywalking.apm.plugin.shenyu.v24x.Constant.PROXY_RPC_SPAN; import java.util.Objects; +import java.util.Optional; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; @@ -63,6 +65,12 @@ public class CommonUtil { if (Objects.isNull(span)) { return ret; } + Optional.ofNullable(exchange.getResponse().getStatusCode()).ifPresent(httpStatus -> { + if (httpStatus.isError()) { + Tags.HTTP_RESPONSE_STATUS_CODE.set(span, httpStatus.value()); + span.errorOccurred(); + } + }); ContextManager.stopSpan(span); return ret; } diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/resources/skywalking-plugin.def index a2fb65952..2c628a3e9 100644 --- a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/resources/skywalking-plugin.def @@ -17,4 +17,8 @@ shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.GlobalPluginInstrumentation shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.ServerWebExchangeInstrumentation shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.ApacheDubboPluginInstrumentation +shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.GrpcPluginInstrumentation +shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.SofaRpcPluginInstrumentation +shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.MotanRpcPluginInstrumentation +shenyu-2.4.x=org.apache.skywalking.apm.plugin.shenyu.v24x.define.TarsRpcPluginInstrumentation diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 730b5fd38..8179e3e63 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -31,7 +31,7 @@ metrics based on the tracing data. * JRE HttpURLConnection (Optional²) * HTTP Gateway * [Spring Cloud Gateway](https://spring.io/projects/spring-cloud-gateway) 2.0.2.RELEASE -> 3.x (Optional²) - * [Apache ShenYu](https://shenyu.apache.org) 2.4.x (Optional²) + * [Apache ShenYu](https://shenyu.apache.org) (Rich protocol support: `HTTP`,`Spring Cloud`,`gRPC`,`Dubbo`,`SOFARPC`,`Motan`,`Tars`) 2.4.x (Optional²) * JDBC * Mysql Driver 5.x, 6.x, 8.x * Oracle Driver (Optional¹) diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/config/expectedData.yaml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/config/expectedData.yaml new file mode 100644 index 000000000..675ec1a21 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/config/expectedData.yaml @@ -0,0 +1,166 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +segmentItems: + - serviceName: entry-service + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: /grpc/echo + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 13 + isError: false + spanType: Exit + peer: localhost:9196 + skipAnalysis: false + tags: + - { key: url, value: 'http://localhost:9196/grpc/echo' } + - { key: http.method, value: POST } + - operationName: GET:/entry/rpc-service + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 14 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + tags: + - { key: url, value: 'http://localhost:8888/entry/rpc-service' } + - { key: http.method, value: GET } + + + - serviceName: shenyu-gateway + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: echo.EchoServiceJSON.echo + parentSpanId: 0 + spanId: 1 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + isError: false + spanType: Exit + peer: localhost/127.0.0.1:38081 + skipAnalysis: false + tags: + - {key: GENERIC_CALL_METHOD, value: asyncUnaryCall} + - {key: rpc.status_code, value: OK} + - operationName: gRPCPlugin + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 127 + isError: false + spanType: Local + peer: '' + skipAnalysis: false + refs: + - { parentEndpoint: /grpc/echo, networkAddress: '', refType: CrossThread, + parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstance: not null, parentService: shenyu-gateway, + traceId: not null } + - segmentId: not null + spans: + - operationName: /grpc/echo + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 127 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + tags: + - {key: url, value: 'http://localhost:9196/grpc/echo'} + - {key: http.method, value: POST} + - {key: http.status_code, value: '200'} + refs: + - { parentEndpoint: 'GET:/entry/rpc-service', networkAddress: 'localhost:9196', + refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstance: not null, parentService: entry-service, + traceId: not null } + + - serviceName: grpc-service + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: echo.EchoServiceJSON.echo/server/Response/onClose + parentSpanId: 0 + spanId: 1 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + isError: false + spanType: Local + peer: '' + skipAnalysis: false + tags: + - { key: rpc.status_code, value: OK } + - operationName: echo.EchoServiceJSON.echo/server/Request/onComplete + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + isError: false + spanType: Local + peer: '' + skipAnalysis: false + refs: + - { parentEndpoint: echo.EchoServiceJSON.echo, networkAddress: '', refType: CrossThread, + parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstance: not null , parentService: grpc-service, + traceId: not null } + - segmentId: not null + spans: + - operationName: echo.EchoServiceJSON.echo + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 23 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + refs: + - { parentEndpoint: gRPCPlugin, networkAddress: not null, refType: CrossProcess, + parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstance: not null , parentService: shenyu-gateway, + traceId: not null } + + + +meterItems: [] \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/configuration.yml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/configuration.yml new file mode 100644 index 000000000..c42ac1613 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/configuration.yml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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:8888/entry/rpc-service +healthCheck: http://localhost:8888/entry/check +startScript: ./bin/startup.sh +runningMode: with_optional +withPlugins: apm-shenyu-2.4.x-plugin-*.jar +environment: +dependencies: diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/pom.xml new file mode 100644 index 000000000..b6595968e --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/pom.xml @@ -0,0 +1,111 @@ + + + + + + org.apache.skywalking + shenyu-2.4.x-grpc-scenario + 1.0.0 + pom + + 4.0.0 + + + shenyu-grpc-entry + shenyu-grpc-gateway + shenyu-grpc-service + shenyu-grpc-dist + + + + UTF-8 + 1.8 + 2.4.3 + 2.2.2.RELEASE + 2.4.3 + 1.18.20 + + 1.33.1 + 3.13.0 + 1.6.2 + + + 1.2.79 + + + skywalking-shenyu-2.4.x-grpc-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + org.apache.shenyu + shenyu-spring-boot-starter-gateway + ${test.framework.version} + + + + io.grpc + grpc-all + ${grpc.version} + + + + org.apache.shenyu + shenyu-spring-boot-starter-plugin-grpc + ${test.framework.version} + + + + + com.alibaba + fastjson + ${fastjson.version} + + + + + + + shenyu-2.4.x-grpc-scenario + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + + + + + diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/bin/startup.sh b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/bin/startup.sh new file mode 100644 index 000000000..396de60b2 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/bin/startup.sh @@ -0,0 +1,29 @@ +#!/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} "-Dskywalking.agent.service_name=shenyu-gateway" ${home}/../libs/shenyu-grpc-gateway.jar & +sleep 2 + +java -jar ${agent_opts} "-Dskywalking.agent.service_name=grpc-service" ${home}/../libs/shenyu-grpc-service.jar & +sleep 2 + +java -jar ${agent_opts} "-Dskywalking.agent.service_name=entry-service" ${home}/../libs/shenyu-grpc-entry.jar & +sleep 1 + diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/pom.xml new file mode 100644 index 000000000..cb08ad2a6 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/pom.xml @@ -0,0 +1,59 @@ + + + + + shenyu-2.4.x-grpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-grpc-dist + + + 8 + 8 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ../target/ + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/src/main/assembly/assembly.xml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/src/main/assembly/assembly.xml new file mode 100644 index 000000000..558323bd1 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-dist/src/main/assembly/assembly.xml @@ -0,0 +1,51 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ../shenyu-grpc-entry/target/shenyu-grpc-entry.jar + ./libs + 0775 + + + ../shenyu-grpc-gateway/target/shenyu-grpc-gateway.jar + ./libs + 0775 + + + ../shenyu-grpc-service/target/shenyu-grpc-service.jar + ./libs + 0775 + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/pom.xml new file mode 100644 index 000000000..59d56dbff --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/pom.xml @@ -0,0 +1,67 @@ + + + + + + shenyu-2.4.x-grpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-grpc-entry + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-logging + + + + + shenyu-grpc-entry + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java new file mode 100644 index 000000000..7b7a477de --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.entry; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class EntryApplication { + + public static void main(final String[] args) { + SpringApplication.run(EntryApplication.class, args); + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java new file mode 100644 index 000000000..423ae50fc --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.entry.controller; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * http entry service. + */ +@RestController +@RequestMapping("/entry") +public class HttpEntryController { + + private static final String GATEWAY_SERVICE_URL = "http://localhost:9196/grpc/echo"; + + private final RestTemplate restTemplate = new RestTemplate(); + + @RequestMapping("/check") + public String healthCheck() { + return "ok"; + } + + @GetMapping(value = "/rpc-service", produces = {APPLICATION_JSON_VALUE}) + public ResponseEntity httpService() throws Exception { + TimeUnit.MILLISECONDS.sleep(100); + Map data = new HashMap<>(); + data.put("message", "hello world"); + Map body = new HashMap<>(); + body.put("data", Collections.singletonList(data)); + + ResponseEntity entity = restTemplate.postForEntity(GATEWAY_SERVICE_URL, body, String.class); + + if (entity.getStatusCode().is2xxSuccessful()) { + return ResponseEntity.ok(Optional.ofNullable(entity.getBody()).orElse("")); + } + return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body("failed"); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/resources/application.yml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/resources/application.yml new file mode 100644 index 000000000..516dbbeca --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-entry/src/main/resources/application.yml @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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: 8888 + diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/pom.xml new file mode 100644 index 000000000..2ec6461d9 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/pom.xml @@ -0,0 +1,85 @@ + + + + + + shenyu-2.4.x-grpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-grpc-gateway + + + 8 + 8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.apache.shenyu + shenyu-spring-boot-starter-gateway + + + + org.apache.shenyu + shenyu-spring-boot-starter-plugin-grpc + + + + io.grpc + grpc-all + + + + org.projectlombok + lombok + + + com.alibaba + fastjson + + + + + shenyu-grpc-gateway + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java new file mode 100644 index 000000000..a9b9d8917 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * shenyu gateway application. + */ +@SpringBootApplication +public class GatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java new file mode 100644 index 000000000..488cb6d2c --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.gateway.init; + +import java.io.InputStream; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.shenyu.common.dto.MetaData; +import org.apache.shenyu.common.dto.PluginData; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.dto.SelectorData; +import org.apache.shenyu.plugin.global.cache.MetaDataCache; +import org.apache.shenyu.plugin.grpc.client.GrpcClientBuilder; +import org.apache.shenyu.sync.data.api.PluginDataSubscriber; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.parser.Feature; +import com.fasterxml.jackson.core.type.TypeReference; + +import lombok.extern.slf4j.Slf4j; + +/** + * init gateway router runner. + */ +@Slf4j +@Component +public class InitRouterRunner implements CommandLineRunner { + + @Autowired + private PluginDataSubscriber subscriber; + + @Override + public void run(String... args) throws Exception { + String pluginPath = "/shenyu-plugin.json"; + String selectorPath = "/shenyu-selector.json"; + String rulePath = "/shenyu-rule.json"; + + try ( + InputStream pluginStream = getClass().getResourceAsStream(pluginPath); + InputStream selectorStream = getClass().getResourceAsStream(selectorPath); + InputStream ruleStream = getClass().getResourceAsStream(rulePath)) { + + Map pluginDataMap = JSON.parseObject(pluginStream, + new TypeReference>() { + }.getType(), Feature.AllowComment); + Map> selectorDataMap = JSON.parseObject(selectorStream, + new TypeReference>>() { + }.getType(), Feature.AllowComment); + Map> ruleDataMap = JSON.parseObject(ruleStream, + new TypeReference>>() { + }.getType(), Feature.AllowComment); + + pluginDataMap.values().forEach(subscriber::onSubscribe); + selectorDataMap.values().stream().flatMap(Collection::stream) + .forEach(data -> subscriber.onSelectorSubscribe(data)); + ruleDataMap.values().stream().flatMap(Collection::stream).forEach(subscriber::onRuleSubscribe); + + initGrpc(); + log.info("init router data finish."); + } catch (Exception e) { + log.error("init router failed", e); + } + } + + private void initGrpc() { + MetaData metaData = new MetaData(); + metaData.setId("1"); + metaData.setAppName("localhost:38081"); + metaData.setContextPath("/grpc"); + metaData.setPath("/grpc/echo"); + metaData.setRpcType("grpc"); + metaData.setServiceName("echo.EchoService"); + metaData.setMethodName("echo"); + metaData.setParameterTypes("echo.EchoRequest,io.grpc.stub.StreamObserver"); + metaData.setRpcExt("{\"timeout\":5000,\"methodType\":\"UNARY\"}"); + metaData.setEnabled(true); + MetaDataCache.getInstance().cache(metaData); + + GrpcClientBuilder.buildClient("/grpc"); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/application.yml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/application.yml new file mode 100644 index 000000000..cf59ab432 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/application.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. +# + +server: + port: 9196 + +spring: + main: + allow-bean-definition-overriding: true diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-plugin.json b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-plugin.json new file mode 100644 index 000000000..b7c0031f5 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-plugin.json @@ -0,0 +1,252 @@ +/** +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +*/ +{ + "request": { + "id": "20", + "name": "request", + "config": null, + "role": "HttpProcess", + "enabled": false, + "sort": 120 + }, + "jwt": { + "id": "19", + "name": "jwt", + "config": "{\"secretKey\":\"key\"}", + "role": "Authentication", + "enabled": false, + "sort": 30 + }, + "paramMapping": { + "id": "22", + "name": "paramMapping", + "config": "{\"ruleHandlePageType\":\"custom\"}", + "role": "HttpProcess", + "enabled": false, + "sort": 70 + }, + "modifyResponse": { + "id": "23", + "name": "modifyResponse", + "config": "{\"ruleHandlePageType\":\"custom\"}", + "role": "HttpProcess", + "enabled": false, + "sort": 220 + }, + "sign": { + "id": "1", + "name": "sign", + "config": null, + "role": "Authentication", + "enabled": false, + "sort": 20 + }, + "dubbo": { + "id": "6", + "name": "dubbo", + "config": "{\"register\":\"N/A\",\"multiSelectorHandle\":\"1\",\"threadpool\":\"cached\",\"corethreads\":0,\"threads\":2147483647,\"queues\":0}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "motan": { + "id": "17", + "name": "motan", + "config": "{\"register\":\"127.0.0.1:2181\"}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "oauth2": { + "id": "21", + "name": "oauth2", + "config": null, + "role": "Authentication", + "enabled": false, + "sort": 40 + }, + "rateLimiter": { + "id": "4", + "name": "rateLimiter", + "config": "{\"master\":\"mymaster\",\"mode\":\"standalone\",\"url\":\"192.168.1.1:6379\",\"password\":\"abc\"}", + "role": "FaultTolerance", + "enabled": false, + "sort": 60 + }, + "websocket": { + "id": "26", + "name": "websocket", + "config": "{\"multiSelectorHandle\":\"1\"}", + "role": "Proxy", + "enabled": false, + "sort": 200 + }, + "mqtt": { + "id": "28", + "name": "mqtt", + "config": "{\"port\": 9500,\"bossGroupThreadCount\": 1,\"maxPayloadSize\": 65536,\"workerGroupThreadCount\": 12,\"userName\": \"shenyu\",\"password\": \"shenyu\",\"isEncryptPassword\": false,\"encryptMode\": \"\",\"leakDetectorLevel\": \"DISABLED\"}", + "role": "Proxy", + "enabled": false, + "sort": 125 + }, + "tars": { + "id": "13", + "name": "tars tested", + "config": "{\"multiSelectorHandle\":\"1\",\"multiRuleHandle\":\"0\"}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "cryptorRequest": { + "id": "24", + "name": "cryptorRequest", + "config": null, + "role": "Cryptor", + "enabled": false, + "sort": 100 + }, + "divide": { + "id": "5", + "name": "divide", + "config": "{\"multiSelectorHandle\":\"1\",\"multiRuleHandle\":\"0\"}", + "role": "Proxy", + "enabled": false, + "sort": 200 + }, + "waf": { + "id": "2", + "name": "waf", + "config": "{\"model\":\"black\"}", + "role": "Authentication", + "enabled": false, + "sort": 50 + }, + "redirect": { + "id": "16", + "name": "redirect", + "config": null, + "role": "HttpProcess", + "enabled": false, + "sort": 110 + }, + "sentinel": { + "id": "10", + "name": "sentinel", + "config": null, + "role": "FaultTolerance", + "enabled": false, + "sort": 140 + }, + "hystrix": { + "id": "9", + "name": "hystrix", + "config": null, + "role": "FaultTolerance", + "enabled": false, + "sort": 130 + }, + "sofa": { + "id": "11", + "name": "sofa", + "config": "{\"protocol\":\"zookeeper\",\"register\":\"127.0.0.1:2181\"}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "cache": { + "id": "30", + "name": "cache", + "config": "{\"cacheType\":\"memory\"}", + "role": "Cache", + "enabled": false, + "sort": 10 + }, + "contextPath": { + "id": "14", + "name": "contextPath", + "config": null, + "role": "HttpProcess", + "enabled": true, + "sort": 80 + }, + "generalContext": { + "id": "27", + "name": "generalContext", + "config": null, + "role": "Common", + "enabled": true, + "sort": 125 + }, + "rewrite": { + "id": "3", + "name": "rewrite", + "config": null, + "role": "HttpProcess", + "enabled": false, + "sort": 90 + }, + "springCloud": { + "id": "8", + "name": "springCloud", + "config": null, + "role": "Proxy", + "enabled": false, + "sort": 200 + }, + "grpc": { + "id": "15", + "name": "grpc", + "config": "{\"multiSelectorHandle\":\"1\",\"multiRuleHandle\":\"0\",\"threadpool\":\"cached\"}", + "role": "Proxy", + "enabled": true, + "sort": 310 + }, + "resilience4j": { + "id": "12", + "name": "resilience4j", + "config": null, + "role": "FaultTolerance", + "enabled": false, + "sort": 310 + }, + "logging": { + "id": "18", + "name": "logging", + "config": null, + "role": "Logging", + "enabled": false, + "sort": 160 + }, + "cryptorResponse": { + "id": "25", + "name": "cryptorResponse", + "config": null, + "role": "Cryptor", + "enabled": false, + "sort": 410 + }, + "loggingRocketMQ": { + "id": "29", + "name": "loggingRocketMQ", + "config": "{\"topic\":\"shenyu-access-logging\", \"namesrvAddr\": \"localhost:9876\",\"producerGroup\":\"shenyu-plugin-logging-rocketmq\"}", + "role": "Logging", + "enabled": false, + "sort": 170 + } +} \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-rule.json b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-rule.json new file mode 100644 index 000000000..124b73ddf --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-rule.json @@ -0,0 +1,41 @@ +/** +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +*/ +{ + "1": [ + { + "id": "1", + "name": "/grpc/echo", + "pluginName": "grpc", + "selectorId": "1", + "matchMode": 0, + "sort": 1, + "enabled": true, + "loged": true, + "handle": null, + "conditionDataList": [ + { + "paramType": "uri", + "operator": "=", + "paramName": "/", + "paramValue": "/grpc/echo" + } + ] + } + ] +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-selector.json b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-selector.json new file mode 100644 index 000000000..4ebe74d6f --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-gateway/src/main/resources/shenyu-selector.json @@ -0,0 +1,43 @@ +/** +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +*/ +{ + "grpc": [ + { + "id": "1", + "pluginId": "15", + "pluginName": "grpc", + "name": "/grpc", + "matchMode": 0, + "type": 1, + "sort": 1, + "enabled": true, + "logged": true, + "continued": true, + "handle": "[{\"weight\":50,\"upstreamUrl\":\"localhost:38081\",\"status\":true,\"timestamp\":1651802160611}]", + "conditionList": [ + { + "paramType": "uri", + "operator": "contains", + "paramName": "/", + "paramValue": "/grpc/" + } + ] + } + ] +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/pom.xml new file mode 100644 index 000000000..be173980d --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/pom.xml @@ -0,0 +1,100 @@ + + + + + + shenyu-2.4.x-grpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-grpc-service + + + 8 + 8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + io.grpc + grpc-all + + + + + shenyu-grpc-service + + + + kr.motd.maven + os-maven-plugin + ${os-maven-plugin.version} + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} + grpc-java + io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} + src/main/resources/proto + + + + + compile + compile-custom + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/Application.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/Application.java new file mode 100644 index 000000000..7a0265c73 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/Application.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.http; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(final String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/EchoServiceImpl.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/EchoServiceImpl.java new file mode 100644 index 000000000..6c1b41d52 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/EchoServiceImpl.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.http.service; + +import org.springframework.stereotype.Service; + +import echo.EchoRequest; +import echo.EchoResponse; +import echo.EchoServiceGrpc; +import io.grpc.stub.StreamObserver; + +@Service +public class EchoServiceImpl extends EchoServiceGrpc.EchoServiceImplBase { + + @Override + public void echo(final EchoRequest request, final StreamObserver responseObserver) { + EchoResponse.Builder response = EchoResponse.newBuilder() + .setMessage("received client message:" + request.getMessage()); + responseObserver.onNext(response.build()); + responseObserver.onCompleted(); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/ServiceConfiguration.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/ServiceConfiguration.java new file mode 100644 index 000000000..d627a3c2a --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/service/ServiceConfiguration.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.http.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.grpc.Server; +import io.grpc.ServerBuilder; +import io.grpc.ServerServiceDefinition; +import test.apache.skywalking.apm.testcase.shenyu.http.support.dynamic.DynamicMessageServiceTranslator; + +@Configuration +public class ServiceConfiguration { + + @Value("${grpc.port}") + private int grpcPort; + + @Bean(initMethod = "start", destroyMethod = "shutdown") + public Server server(EchoServiceImpl testService) throws Exception { + ServerServiceDefinition serviceDefinition = testService.bindService(); + // For testing purposes, the `GRPC Server Reflection Protocol` is not used here. + // GRPC Server Reflection Protocol: https://github.com/grpc/grpc/blob/master/doc/server-reflection.md + // No dependency: io.grpc:grpc-services:${grpcVersion} + ServerServiceDefinition jsonDefinition = + DynamicMessageServiceTranslator.buildDynamicServerServiceDefinition(serviceDefinition); + return ServerBuilder.forPort(grpcPort) + .addService(serviceDefinition) + .addService(jsonDefinition) + .build(); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/constant/Constants.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/constant/Constants.java new file mode 100644 index 000000000..aa779311c --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/constant/Constants.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.http.support.constant; + +public class Constants { + + public static final String DYNAMIC_SERVICE_SUFFIX = "JSON"; + + public static final String DYNAMIC_MESSAGE_NAME = "JsonMessage"; + + public static final String DYNAMIC_MESSAGE_DATA_FILED = "data"; + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicJsonMessage.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicJsonMessage.java new file mode 100644 index 000000000..407c86534 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicJsonMessage.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.http.support.dynamic; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.protobuf.DescriptorProtos; +import com.google.protobuf.Descriptors; +import com.google.protobuf.DynamicMessage; +import com.google.protobuf.ExtensionRegistryLite; + +import io.grpc.MethodDescriptor; +import test.apache.skywalking.apm.testcase.shenyu.http.support.constant.Constants; + +public class DynamicJsonMessage { + + private static final Logger LOG = LoggerFactory.getLogger(DynamicJsonMessage.class); + + private static Descriptors.Descriptor buildJsonMarshallerDescriptor() { + + DescriptorProtos.DescriptorProto.Builder jsonMarshaller = DescriptorProtos.DescriptorProto.newBuilder(); + jsonMarshaller.setName(Constants.DYNAMIC_MESSAGE_NAME); + jsonMarshaller.addFieldBuilder() + .setName(Constants.DYNAMIC_MESSAGE_DATA_FILED) + .setNumber(1) + .setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_STRING); + + DescriptorProtos.FileDescriptorProto.Builder fileDescriptorProtoBuilder = + DescriptorProtos.FileDescriptorProto.newBuilder(); + fileDescriptorProtoBuilder.addMessageType(jsonMarshaller); + + DescriptorProtos.FileDescriptorProto fileDescriptorProto = fileDescriptorProtoBuilder.build(); + try { + Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor + .buildFrom(fileDescriptorProto, new Descriptors.FileDescriptor[0]); + return fileDescriptor.findMessageTypeByName(Constants.DYNAMIC_MESSAGE_NAME); + } catch (Exception e) { + LOG.error("buildJsonMarshallerDescriptor error: {}", e.getMessage()); + throw new RuntimeException("buildJsonMarshallerDescriptor error", e); + } + } + + public static DynamicMessage buildJsonDynamicMessage(String jsonParam) { + // build Descriptor and set request param + Descriptors.Descriptor jsonDescriptor = buildJsonMarshallerDescriptor(); + DynamicMessage.Builder jsonDynamicMessage = DynamicMessage.newBuilder(jsonDescriptor); + jsonDynamicMessage.setField(jsonDescriptor.findFieldByName(Constants.DYNAMIC_MESSAGE_DATA_FILED), + jsonParam); + return jsonDynamicMessage.build(); + } + + public static DynamicMessage buildJsonDynamicMessage() { + Descriptors.Descriptor jsonDescriptor = buildJsonMarshallerDescriptor(); + DynamicMessage.Builder jsonDynamicMessage = DynamicMessage.newBuilder(jsonDescriptor); + return jsonDynamicMessage.build(); + } + + public static String getDataFromDynamicMessage(DynamicMessage message) { + for (Map.Entry entry : message.getAllFields().entrySet()) { + Descriptors.FieldDescriptor key = entry.getKey(); + Object value = entry.getValue(); + String fullName = key.getFullName(); + String jsonMessageFullName = Constants.DYNAMIC_MESSAGE_NAME + "." + Constants.DYNAMIC_MESSAGE_DATA_FILED; + if (jsonMessageFullName.equals(fullName)) { + return (String) value; + } + } + return ""; + } + + public static MethodDescriptor createJsonMarshallerMethodDescriptor( + String serviceName, String methodName, MethodDescriptor.MethodType methodType, + DynamicMessage request, DynamicMessage response) { + + return MethodDescriptor.newBuilder() + .setType(methodType) + .setFullMethodName( + MethodDescriptor.generateFullMethodName(serviceName + Constants.DYNAMIC_SERVICE_SUFFIX, + methodName)) + .setRequestMarshaller(new DynamicMessageMarshaller(request.getDescriptorForType())) + .setResponseMarshaller(new DynamicMessageMarshaller(response.getDescriptorForType())) + .build(); + } + + private static class DynamicMessageMarshaller implements MethodDescriptor.Marshaller { + + private Descriptors.Descriptor messageDescriptor; + + private DynamicMessageMarshaller(Descriptors.Descriptor messageDescriptor) { + this.messageDescriptor = messageDescriptor; + } + + @Override + public DynamicMessage parse(InputStream inputStream) { + try { + return DynamicMessage.newBuilder(messageDescriptor) + .mergeFrom(inputStream, ExtensionRegistryLite.getEmptyRegistry()) + .build(); + } catch (IOException e) { + throw new RuntimeException("parse inputStream error", e); + } + } + + @Override + public InputStream stream(DynamicMessage abstractMessage) { + return abstractMessage.toByteString().newInput(); + } + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicMessageServiceTranslator.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicMessageServiceTranslator.java new file mode 100644 index 000000000..52a1c5e1b --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicMessageServiceTranslator.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.http.support.dynamic; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import com.google.protobuf.DynamicMessage; + +import io.grpc.MethodDescriptor; +import io.grpc.MethodDescriptor.PrototypeMarshaller; +import io.grpc.ServerCall; +import io.grpc.ServerCallHandler; +import io.grpc.ServerMethodDefinition; +import io.grpc.ServerServiceDefinition; +import io.grpc.ServiceDescriptor; +import test.apache.skywalking.apm.testcase.shenyu.http.support.constant.Constants; + +public class DynamicMessageServiceTranslator { + + private static final Map> REQUEST_PARAMS_CLASS_MAP = new HashMap<>(); + + public static ServerServiceDefinition buildDynamicServerServiceDefinition(ServerServiceDefinition serviceDef) + throws Exception { + MethodDescriptor.Marshaller marshaller = + io.grpc.protobuf.ProtoUtils.marshaller(DynamicJsonMessage.buildJsonDynamicMessage()); + List> wrappedMethods = new ArrayList<>(); + List> wrappedDescriptors = new ArrayList<>(); + + for (ServerMethodDefinition definition : serviceDef.getMethods()) { + MethodDescriptor.Marshaller requestMarshaller = definition.getMethodDescriptor().getRequestMarshaller(); + + String fullMethodName = definition.getMethodDescriptor().getFullMethodName(); + + String[] splitMethodName = fullMethodName.split("/"); + fullMethodName = splitMethodName[0] + Constants.DYNAMIC_SERVICE_SUFFIX + "/" + splitMethodName[1]; + if (requestMarshaller instanceof MethodDescriptor.PrototypeMarshaller) { + PrototypeMarshaller prototypeMarshaller = + (PrototypeMarshaller) requestMarshaller; + REQUEST_PARAMS_CLASS_MAP.put(fullMethodName, prototypeMarshaller.getMessagePrototype().getClass()); + } + MethodDescriptor originalMethodDescriptor = definition.getMethodDescriptor(); + MethodDescriptor wrappedMethodDescriptor = originalMethodDescriptor + .toBuilder(marshaller, marshaller).build(); + wrappedDescriptors.add(wrappedMethodDescriptor); + wrappedMethods.add(wrapMethod(definition, wrappedMethodDescriptor)); + } + + ServiceDescriptor.Builder build = ServiceDescriptor.newBuilder( + serviceDef.getServiceDescriptor().getName() + Constants.DYNAMIC_SERVICE_SUFFIX); + for (MethodDescriptor md : wrappedDescriptors) { + Field fullMethodNameField = getField(md.getClass(), "fullMethodName"); + fullMethodNameField.setAccessible(true); + String fullMethodName = (String) fullMethodNameField.get(md); + String[] splitMethodName = fullMethodName.split("/"); + fullMethodName = splitMethodName[0] + Constants.DYNAMIC_SERVICE_SUFFIX + "/" + splitMethodName[1]; + fullMethodNameField.set(md, fullMethodName); + + String serviceName; + Field serviceNameField = getField(md.getClass(), "serviceName"); + if (Objects.nonNull(serviceNameField)) { + serviceNameField.setAccessible(true); + serviceName = (String) serviceNameField.get(md); + serviceName = serviceName + Constants.DYNAMIC_SERVICE_SUFFIX; + serviceNameField.set(md, serviceName); + } + build.addMethod(md); + } + ServerServiceDefinition.Builder serviceBuilder = ServerServiceDefinition.builder(build.build()); + + for (ServerMethodDefinition definition : wrappedMethods) { + serviceBuilder.addMethod(definition); + } + return serviceBuilder.build(); + } + + private static Field getField(final Class beanClass, final String name) throws SecurityException { + final Field[] fields = beanClass.getDeclaredFields(); + return Arrays.stream(fields).filter(field -> Objects.equals(name, field.getName())) + .findFirst().orElse(null); + } + + private static ServerMethodDefinition wrapMethod( + ServerMethodDefinition definition, + MethodDescriptor wrappedMethod) { + ServerCallHandler wrappedHandler = wrapHandler(definition.getServerCallHandler()); + return ServerMethodDefinition.create(wrappedMethod, wrappedHandler); + } + + @SuppressWarnings("unchecked") + private static ServerCallHandler wrapHandler( + ServerCallHandler originalHandler) { + return (call, headers) -> { + ServerCall unwrappedCall = new ProtoToDynamicServerCall<>((ServerCall) call); + ServerCall.Listener originalListener = originalHandler.startCall(unwrappedCall, headers); + return new DynamicToProtoServerCallListener(originalListener, unwrappedCall); + }; + } + + public static Map> getRequestParamsClassMap() { + return REQUEST_PARAMS_CLASS_MAP; + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicToProtoServerCallListener.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicToProtoServerCallListener.java new file mode 100644 index 000000000..626feaa12 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/DynamicToProtoServerCallListener.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.http.support.dynamic; + +import java.lang.reflect.InvocationTargetException; +import java.util.Objects; + +import org.apache.commons.lang3.reflect.MethodUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.protobuf.DynamicMessage; +import com.google.protobuf.Message; +import com.google.protobuf.util.JsonFormat; + +import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener; +import io.grpc.ServerCall; +import io.grpc.ServerCall.Listener; +import io.grpc.Status; + +public class DynamicToProtoServerCallListener extends SimpleForwardingServerCallListener { + + private static final Logger LOG = LoggerFactory.getLogger(DynamicToProtoServerCallListener.class); + + private final ServerCall call; + + public DynamicToProtoServerCallListener(final Listener delegate, final ServerCall call) { + super(delegate); + this.call = call; + } + + /** + * dynamicMessage to proto message + */ + @SuppressWarnings("unchecked") + @Override + public void onMessage(final R message) { + Message.Builder builder; + Class t = + DynamicMessageServiceTranslator.getRequestParamsClassMap().get(call.getMethodDescriptor().getFullMethodName()); + try { + builder = (Message.Builder) invokeStaticMethod(t, "newBuilder"); + // dynamicMessage to proto message + String reqData = DynamicJsonMessage.getDataFromDynamicMessage((DynamicMessage) message); + JsonFormat.parser().ignoringUnknownFields().merge(reqData, builder); + if (Objects.isNull(builder)) { + throw new RuntimeException("build json response message is error, newBuilder method is null"); + } + + delegate().onMessage((R) builder.build()); + } catch (Exception e) { + LOG.error("handle json generic request is error", e); + throw Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException(); + } + } + + public static Object invokeStaticMethod(final Class clazz, final String method) { + try { + return MethodUtils.invokeStaticMethod(clazz, method); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/ProtoToDynamicServerCall.java b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/ProtoToDynamicServerCall.java new file mode 100644 index 000000000..8dedc772b --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/http/support/dynamic/ProtoToDynamicServerCall.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 test.apache.skywalking.apm.testcase.shenyu.http.support.dynamic; + +import com.google.protobuf.DynamicMessage; +import com.google.protobuf.MessageOrBuilder; +import com.google.protobuf.util.JsonFormat; + +import io.grpc.ForwardingServerCall.SimpleForwardingServerCall; +import io.grpc.ServerCall; +import io.grpc.Status; + +public class ProtoToDynamicServerCall extends SimpleForwardingServerCall { + + protected ProtoToDynamicServerCall(ServerCall delegate) { + super(delegate); + } + + @SuppressWarnings("unchecked") + @Override + public void sendMessage(final P message) { + try { + if (message == null) { + delegate().sendMessage(null); + return; + } + // proto message to dynamicMessage + String jsonFormat = JsonFormat.printer().includingDefaultValueFields().preservingProtoFieldNames() + .print((MessageOrBuilder) message); + DynamicMessage respMessage = DynamicJsonMessage.buildJsonDynamicMessage(jsonFormat); + delegate().sendMessage((P) respMessage); + } catch (Exception e) { + throw Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException(); + } + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/application.yml b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/application.yml new file mode 100644 index 000000000..6976dd953 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/application.yml @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +server: + port: 7777 +grpc: + port: 38081 + diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/proto/echo.proto b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/proto/echo.proto new file mode 100644 index 000000000..5cb60b7c3 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/shenyu-grpc-service/src/main/resources/proto/echo.proto @@ -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. + */ + +syntax = "proto3"; + +package echo; + +option java_multiple_files = true; + + +service EchoService { + rpc echo (EchoRequest) returns (EchoResponse) {} +} + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/support-version.list b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/support-version.list new file mode 100644 index 000000000..0b3c87e12 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-grpc-scenario/support-version.list @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# lists your version here (Contains only the last version number of each minor version.) +2.4.3 diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/config/expectedData.yaml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/config/expectedData.yaml new file mode 100644 index 000000000..b154a090c --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/config/expectedData.yaml @@ -0,0 +1,135 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +segmentItems: + - serviceName: entry-service + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: /sofa/hello + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 13 + isError: false + spanType: Exit + peer: localhost:9196 + skipAnalysis: false + tags: + - { key: url, value: 'http://localhost:9196/sofa/hello' } + - { key: http.method, value: GET } + - operationName: GET:/entry/rpc-service + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 14 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + tags: + - { key: url, value: 'http://localhost:8888/entry/rpc-service' } + - { key: http.method, value: GET } + + + + - serviceName: shenyu-gateway + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: com.alipay.sofa.rpc.api.GenericService.hello() + parentSpanId: 0 + spanId: 1 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 43 + isError: false + spanType: Exit + peer: 127.0.0.1:12200 + skipAnalysis: false + tags: + - { key: url, value: 'bolt://127.0.0.1:12200/com.alipay.sofa.rpc.api.GenericService.hello()' } + - operationName: SofaRpcPlugin + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 127 + isError: false + spanType: Local + peer: '' + skipAnalysis: false + refs: + - { parentEndpoint: /sofa/hello, networkAddress: '', refType: CrossThread, + parentSpanId: 0, parentTraceSegmentId: not null, + parentServiceInstance: not null, parentService: shenyu-gateway, + traceId: not null } + - segmentId: not null + spans: + - operationName: /sofa/hello + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 127 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + tags: + - {key: url, value: 'http://localhost:9196/sofa/hello'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + refs: + - { parentEndpoint: 'GET:/entry/rpc-service', networkAddress: 'localhost:9196', + refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstance: not null, parentService: entry-service, + traceId: not null } + + - serviceName: sofarpc-service + segmentSize: nq 0 + segments: + - segmentId: not null + spans: + - operationName: test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces.SofaRpcDemoService.hello() + parentSpanId: -1 + spanId: 0 + spanLayer: RPCFramework + startTime: nq 0 + endTime: nq 0 + componentId: 43 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + refs: + - {parentEndpoint: SofaRpcPlugin, networkAddress: '127.0.0.1:12200', refType: CrossProcess, + parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstance: not null , parentService: shenyu-gateway, + traceId: not null } + + + +meterItems: [] \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/configuration.yml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/configuration.yml new file mode 100644 index 000000000..c42ac1613 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/configuration.yml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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:8888/entry/rpc-service +healthCheck: http://localhost:8888/entry/check +startScript: ./bin/startup.sh +runningMode: with_optional +withPlugins: apm-shenyu-2.4.x-plugin-*.jar +environment: +dependencies: diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml new file mode 100644 index 000000000..e2fa7bc9d --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml @@ -0,0 +1,116 @@ + + + + + + org.apache.skywalking + shenyu-2.4.x-sofarpc-scenario + 1.0.0 + pom + + 4.0.0 + + + shenyu-sofarpc-entry + shenyu-sofarpc-gateway + shenyu-sofarpc-service + shenyu-sofarpc-dist + + + + UTF-8 + 1.8 + 2.4.3 + 2.2.2.RELEASE + 2.4.3 + 1.18.20 + + 6.0.4 + 5.7.6 + 4.0.1 + 1.6.2 + + + 1.2.79 + + + skywalking-2.4.x-sofarpc-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + org.apache.shenyu + shenyu-spring-boot-starter-gateway + ${test.framework.version} + + + + com.alipay.sofa + rpc-sofa-boot-starter + ${rpc-sofa-boot-starter.version} + + + + org.apache.shenyu + shenyu-spring-boot-starter-plugin-sofa + ${test.framework.version} + + + + com.alipay.sofa + sofa-rpc-all + ${sofa-rpc-all.version} + + + + + com.alibaba + fastjson + ${fastjson.version} + + + + + + + shenyu-2.4.x-sofarpc-scenario + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + + + diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/bin/startup.sh b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/bin/startup.sh new file mode 100644 index 000000000..c4b8d9887 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/bin/startup.sh @@ -0,0 +1,29 @@ +#!/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} "-Dskywalking.agent.service_name=shenyu-gateway" ${home}/../libs/shenyu-sofarpc-gateway.jar & +sleep 2 + +java -jar ${agent_opts} "-Dskywalking.agent.service_name=sofarpc-service" ${home}/../libs/shenyu-sofarpc-service.jar & +sleep 1 + +java -jar ${agent_opts} "-Dskywalking.agent.service_name=entry-service" ${home}/../libs/shenyu-sofarpc-entry.jar & +sleep 1 + diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/pom.xml new file mode 100644 index 000000000..85781ed8e --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/pom.xml @@ -0,0 +1,59 @@ + + + + + shenyu-2.4.x-sofarpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-sofarpc-dist + + + 8 + 8 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ../target/ + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/src/main/assembly/assembly.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/src/main/assembly/assembly.xml new file mode 100644 index 000000000..f44504380 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-dist/src/main/assembly/assembly.xml @@ -0,0 +1,51 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ../shenyu-sofarpc-entry/target/shenyu-sofarpc-entry.jar + ./libs + 0775 + + + ../shenyu-sofarpc-gateway/target/shenyu-sofarpc-gateway.jar + ./libs + 0775 + + + ../shenyu-sofarpc-service/target/shenyu-sofarpc-service.jar + ./libs + 0775 + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/pom.xml new file mode 100644 index 000000000..e0b37cff9 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/pom.xml @@ -0,0 +1,67 @@ + + + + + + shenyu-2.4.x-sofarpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-sofarpc-entry + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-logging + + + + + shenyu-sofarpc-entry + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java new file mode 100644 index 000000000..7b7a477de --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/EntryApplication.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.entry; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class EntryApplication { + + public static void main(final String[] args) { + SpringApplication.run(EntryApplication.class, args); + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java new file mode 100644 index 000000000..83ca4470b --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/java/test/apache/skywalking/apm/testcase/shenyu/entry/controller/HttpEntryController.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.entry.controller; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * http entry service. + */ +@RestController +@RequestMapping("/entry") +public class HttpEntryController { + + private static final String GATEWAY_SERVICE_URL = "http://localhost:9196/sofa/hello"; + + private final RestTemplate restTemplate = new RestTemplate(); + + @RequestMapping("/check") + public String healthCheck() { + return "ok"; + } + + @GetMapping(value = "/rpc-service", produces = {APPLICATION_JSON_VALUE}) + public ResponseEntity httpService() throws Exception { + TimeUnit.MILLISECONDS.sleep(100); + ResponseEntity entity = restTemplate.getForEntity(GATEWAY_SERVICE_URL, String.class); + if (entity.getStatusCode().is2xxSuccessful()) { + return ResponseEntity.ok(Optional.ofNullable(entity.getBody()).orElse("")); + } + return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body("failed"); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/resources/application.yml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/resources/application.yml new file mode 100644 index 000000000..516dbbeca --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-entry/src/main/resources/application.yml @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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: 8888 + diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/pom.xml new file mode 100644 index 000000000..23823c1b3 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/pom.xml @@ -0,0 +1,85 @@ + + + + + + shenyu-2.4.x-sofarpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-sofarpc-gateway + + + 8 + 8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.apache.shenyu + shenyu-spring-boot-starter-gateway + + + + com.alipay.sofa + sofa-rpc-all + + + org.apache.shenyu + shenyu-spring-boot-starter-plugin-sofa + + + + org.projectlombok + lombok + + + com.alibaba + fastjson + + + + + + shenyu-sofarpc-gateway + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java new file mode 100644 index 000000000..a9b9d8917 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/GatewayApplication.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * shenyu gateway application. + */ +@SpringBootApplication +public class GatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java new file mode 100644 index 000000000..933ddfe79 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/java/test/apache/skywalking/apm/testcase/shenyu/gateway/init/InitRouterRunner.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.shenyu.gateway.init; + +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.shenyu.common.dto.MetaData; +import org.apache.shenyu.common.dto.PluginData; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.dto.SelectorData; +import org.apache.shenyu.plugin.global.cache.MetaDataCache; +import org.apache.shenyu.plugin.sofa.cache.ApplicationConfigCache; +import org.apache.shenyu.sync.data.api.PluginDataSubscriber; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.parser.Feature; +import com.alipay.sofa.rpc.api.GenericService; +import com.alipay.sofa.rpc.common.RpcConstants; +import com.alipay.sofa.rpc.config.ConsumerConfig; +import com.fasterxml.jackson.core.type.TypeReference; + +import lombok.extern.slf4j.Slf4j; + +/** + * init gateway router runner. + */ +@Slf4j +@Component +public class InitRouterRunner implements CommandLineRunner { + + @Autowired + private PluginDataSubscriber subscriber; + + @Override + public void run(String... args) throws Exception { + String pluginPath = "/shenyu-plugin.json"; + String selectorPath = "/shenyu-selector.json"; + String rulePath = "/shenyu-rule.json"; + + try ( + InputStream pluginStream = getClass().getResourceAsStream(pluginPath); + InputStream selectorStream = getClass().getResourceAsStream(selectorPath); + InputStream ruleStream = getClass().getResourceAsStream(rulePath)) { + + Map pluginDataMap = JSON.parseObject(pluginStream, + new TypeReference>() { + }.getType(), Feature.AllowComment); + Map> selectorDataMap = JSON.parseObject(selectorStream, + new TypeReference>>() { + }.getType(), Feature.AllowComment); + Map> ruleDataMap = JSON.parseObject(ruleStream, + new TypeReference>>() { + }.getType(), Feature.AllowComment); + + pluginDataMap.values().forEach(subscriber::onSubscribe); + selectorDataMap.values().stream().flatMap(Collection::stream) + .forEach(data -> subscriber.onSelectorSubscribe(data)); + ruleDataMap.values().stream().flatMap(Collection::stream).forEach(subscriber::onRuleSubscribe); + + initGrpc(); + log.info("init router data finish."); + } catch (Exception e) { + log.error("init router failed", e); + } + } + + private void initGrpc() throws Exception { + MetaData metaData = new MetaData(); + metaData.setId("1"); + metaData.setAppName("sofa"); + metaData.setContextPath("/sofa"); + metaData.setPath("/sofa/hello"); + metaData.setRpcType("sofa"); + metaData.setServiceName("test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces.SofaRpcDemoService"); + metaData.setMethodName("hello"); + metaData.setParameterTypes(null); + metaData.setRpcExt("{\"loadbalance\":\"hash\",\"retries\":3,\"timeout\":-1}"); + metaData.setEnabled(true); + MetaDataCache.getInstance().cache(metaData); + + Field cacheField = Arrays.stream(ApplicationConfigCache.class.getDeclaredFields()) + .filter(field -> field.getName().equals("cache")) + .findFirst().get(); + + cacheField.setAccessible(true); + com.google.common.cache.Cache cache = + (com.google.common.cache.Cache) cacheField.get(ApplicationConfigCache.getInstance()); + + ConsumerConfig reference = new ConsumerConfig<>(); + reference.setGeneric(true); + reference.setInterfaceId("test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces.SofaRpcDemoService"); + reference.setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT); + reference.setInvokeType(RpcConstants.INVOKER_TYPE_CALLBACK); + reference.setRepeatedReferLimit(-1); + reference.setTimeout(5000); + reference.setDirectUrl("bolt://127.0.0.1:12200"); + cache.put(metaData.getPath(), reference); + + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/application.yml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/application.yml new file mode 100644 index 000000000..cf59ab432 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/application.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. +# + +server: + port: 9196 + +spring: + main: + allow-bean-definition-overriding: true diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-plugin.json b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-plugin.json new file mode 100644 index 000000000..9c7c9b9d9 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-plugin.json @@ -0,0 +1,252 @@ +/** +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +*/ +{ + "request": { + "id": "20", + "name": "request", + "config": null, + "role": "HttpProcess", + "enabled": false, + "sort": 120 + }, + "jwt": { + "id": "19", + "name": "jwt", + "config": "{\"secretKey\":\"key\"}", + "role": "Authentication", + "enabled": false, + "sort": 30 + }, + "paramMapping": { + "id": "22", + "name": "paramMapping", + "config": "{\"ruleHandlePageType\":\"custom\"}", + "role": "HttpProcess", + "enabled": false, + "sort": 70 + }, + "modifyResponse": { + "id": "23", + "name": "modifyResponse", + "config": "{\"ruleHandlePageType\":\"custom\"}", + "role": "HttpProcess", + "enabled": false, + "sort": 220 + }, + "sign": { + "id": "1", + "name": "sign", + "config": null, + "role": "Authentication", + "enabled": false, + "sort": 20 + }, + "dubbo": { + "id": "6", + "name": "dubbo", + "config": "{\"register\":\"N/A\",\"multiSelectorHandle\":\"1\",\"threadpool\":\"cached\",\"corethreads\":0,\"threads\":2147483647,\"queues\":0}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "motan": { + "id": "17", + "name": "motan", + "config": "{\"register\":\"127.0.0.1:2181\"}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "oauth2": { + "id": "21", + "name": "oauth2", + "config": null, + "role": "Authentication", + "enabled": false, + "sort": 40 + }, + "rateLimiter": { + "id": "4", + "name": "rateLimiter", + "config": "{\"master\":\"mymaster\",\"mode\":\"standalone\",\"url\":\"192.168.1.1:6379\",\"password\":\"abc\"}", + "role": "FaultTolerance", + "enabled": false, + "sort": 60 + }, + "websocket": { + "id": "26", + "name": "websocket", + "config": "{\"multiSelectorHandle\":\"1\"}", + "role": "Proxy", + "enabled": false, + "sort": 200 + }, + "mqtt": { + "id": "28", + "name": "mqtt", + "config": "{\"port\": 9500,\"bossGroupThreadCount\": 1,\"maxPayloadSize\": 65536,\"workerGroupThreadCount\": 12,\"userName\": \"shenyu\",\"password\": \"shenyu\",\"isEncryptPassword\": false,\"encryptMode\": \"\",\"leakDetectorLevel\": \"DISABLED\"}", + "role": "Proxy", + "enabled": false, + "sort": 125 + }, + "tars": { + "id": "13", + "name": "tars tested", + "config": "{\"multiSelectorHandle\":\"1\",\"multiRuleHandle\":\"0\"}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "cryptorRequest": { + "id": "24", + "name": "cryptorRequest", + "config": null, + "role": "Cryptor", + "enabled": false, + "sort": 100 + }, + "divide": { + "id": "5", + "name": "divide", + "config": "{\"multiSelectorHandle\":\"1\",\"multiRuleHandle\":\"0\"}", + "role": "Proxy", + "enabled": false, + "sort": 200 + }, + "waf": { + "id": "2", + "name": "waf", + "config": "{\"model\":\"black\"}", + "role": "Authentication", + "enabled": false, + "sort": 50 + }, + "redirect": { + "id": "16", + "name": "redirect", + "config": null, + "role": "HttpProcess", + "enabled": false, + "sort": 110 + }, + "sentinel": { + "id": "10", + "name": "sentinel", + "config": null, + "role": "FaultTolerance", + "enabled": false, + "sort": 140 + }, + "hystrix": { + "id": "9", + "name": "hystrix", + "config": null, + "role": "FaultTolerance", + "enabled": false, + "sort": 130 + }, + "sofa": { + "id": "11", + "name": "sofa", + "config": "{\"protocol\":\"zookeeper\",\"register\":\"127.0.0.1:2181\"}", + "role": "Proxy", + "enabled": true, + "sort": 310 + }, + "cache": { + "id": "30", + "name": "cache", + "config": "{\"cacheType\":\"memory\"}", + "role": "Cache", + "enabled": false, + "sort": 10 + }, + "contextPath": { + "id": "14", + "name": "contextPath", + "config": null, + "role": "HttpProcess", + "enabled": true, + "sort": 80 + }, + "generalContext": { + "id": "27", + "name": "generalContext", + "config": null, + "role": "Common", + "enabled": true, + "sort": 125 + }, + "rewrite": { + "id": "3", + "name": "rewrite", + "config": null, + "role": "HttpProcess", + "enabled": false, + "sort": 90 + }, + "springCloud": { + "id": "8", + "name": "springCloud", + "config": null, + "role": "Proxy", + "enabled": false, + "sort": 200 + }, + "grpc": { + "id": "15", + "name": "grpc", + "config": "{\"multiSelectorHandle\":\"1\",\"multiRuleHandle\":\"0\",\"threadpool\":\"cached\"}", + "role": "Proxy", + "enabled": false, + "sort": 310 + }, + "resilience4j": { + "id": "12", + "name": "resilience4j", + "config": null, + "role": "FaultTolerance", + "enabled": false, + "sort": 310 + }, + "logging": { + "id": "18", + "name": "logging", + "config": null, + "role": "Logging", + "enabled": false, + "sort": 160 + }, + "cryptorResponse": { + "id": "25", + "name": "cryptorResponse", + "config": null, + "role": "Cryptor", + "enabled": false, + "sort": 410 + }, + "loggingRocketMQ": { + "id": "29", + "name": "loggingRocketMQ", + "config": "{\"topic\":\"shenyu-access-logging\", \"namesrvAddr\": \"localhost:9876\",\"producerGroup\":\"shenyu-plugin-logging-rocketmq\"}", + "role": "Logging", + "enabled": false, + "sort": 170 + } +} \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-rule.json b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-rule.json new file mode 100644 index 000000000..eaf86cc58 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-rule.json @@ -0,0 +1,41 @@ +/** +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +*/ +{ + "1": [ + { + "id": "1", + "name": "/sofa/hello", + "pluginName": "sofa", + "selectorId": "1", + "matchMode": 0, + "sort": 1, + "enabled": true, + "loged": true, + "handle": "{\"retries\":0,\"loadBalance\":\"random\",\"timeout\":3000}", + "conditionDataList": [ + { + "paramType": "uri", + "operator": "=", + "paramName": "/", + "paramValue": "/sofa/hello" + } + ] + } + ] +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-selector.json b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-selector.json new file mode 100644 index 000000000..16fc010ab --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-gateway/src/main/resources/shenyu-selector.json @@ -0,0 +1,43 @@ +/** +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +*/ +{ + "grpc": [ + { + "id": "1", + "pluginId": "11", + "pluginName": "sofa", + "name": "/sofa", + "matchMode": 0, + "type": 1, + "sort": 1, + "enabled": true, + "logged": true, + "continued": true, + "handle": null, + "conditionList": [ + { + "paramType": "uri", + "operator": "contains", + "paramName": "/", + "paramValue": "/sofa/" + } + ] + } + ] +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/pom.xml new file mode 100644 index 000000000..c7935b02e --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/pom.xml @@ -0,0 +1,69 @@ + + + + + + shenyu-2.4.x-sofarpc-scenario + org.apache.skywalking + 1.0.0 + + 4.0.0 + + shenyu-sofarpc-service + + + 8 + 8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alipay.sofa + sofa-rpc-all + + + + + + shenyu-sofarpc-service + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcApplication.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcApplication.java new file mode 100644 index 000000000..189c141c1 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcApplication.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 test.apache.skywalking.apm.testcase.shenyu.sofarpc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SofaRpcApplication { + + public static void main(String[] args) { + SpringApplication.run(SofaRpcApplication.class, args); + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcConfiguration.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcConfiguration.java new file mode 100644 index 000000000..0b7e26d97 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/SofaRpcConfiguration.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.sofarpc; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.alipay.sofa.rpc.config.ProviderConfig; +import com.alipay.sofa.rpc.config.ServerConfig; + +import test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces.SofaRpcDemoService; +import test.apache.skywalking.apm.testcase.shenyu.sofarpc.service.SofaRpcDemoServiceImpl; + +@Configuration +public class SofaRpcConfiguration { + + @Value("${sofa.port}") + private int sofaPort; + + @Bean(destroyMethod = "unExport") + public ProviderConfig provider() { + ServerConfig config = new ServerConfig().setProtocol("bolt").setPort(sofaPort).setDaemon(true); + + ProviderConfig providerConfig = + new ProviderConfig().setInterfaceId(SofaRpcDemoService.class + .getName()).setRef(new SofaRpcDemoServiceImpl()).setServer(config); + + providerConfig.export(); + return providerConfig; + } + +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaBean.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaBean.java new file mode 100644 index 000000000..4ba9e1221 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaBean.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 test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces; + +public class SofaBean { + String data; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaRpcDemoService.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaRpcDemoService.java new file mode 100644 index 000000000..345e2a97e --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/interfaces/SofaRpcDemoService.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces; + +public interface SofaRpcDemoService { + + SofaBean hello(); +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/service/SofaRpcDemoServiceImpl.java b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/service/SofaRpcDemoServiceImpl.java new file mode 100644 index 000000000..4c06fd686 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/java/test/apache/skywalking/apm/testcase/shenyu/sofarpc/service/SofaRpcDemoServiceImpl.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 test.apache.skywalking.apm.testcase.shenyu.sofarpc.service; + +import test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces.SofaBean; +import test.apache.skywalking.apm.testcase.shenyu.sofarpc.interfaces.SofaRpcDemoService; + +public class SofaRpcDemoServiceImpl implements SofaRpcDemoService { + @Override + public SofaBean hello() { + SofaBean sofaBean = new SofaBean(); + sofaBean.setData("hello world"); + return sofaBean; + } +} diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/resources/application.yml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/resources/application.yml new file mode 100644 index 000000000..057afa43d --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/shenyu-sofarpc-service/src/main/resources/application.yml @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +server: + port: 7777 +sofa: + port: 12200 + diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/support-version.list b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/support-version.list new file mode 100644 index 000000000..0b3c87e12 --- /dev/null +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/support-version.list @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# lists your version here (Contains only the last version number of each minor version.) +2.4.3