Apache ShenYu (incubating) plugin support grpc,sofarpc,motan,tars (#170)

This commit is contained in:
hutaishi 2022-05-07 10:23:23 +08:00 committed by GitHub
parent d45818911d
commit bd7912106a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 3871 additions and 1 deletions

View File

@ -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:

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named(INTERCEPT_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named(INTERCEPT_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named(INTERCEPT_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -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<MethodDescription> getMethodsMatcher() {
return named(INTERCEPT_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -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;
}

View File

@ -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

View File

@ -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¹)

View File

@ -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: []

View File

@ -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:

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.skywalking</groupId>
<artifactId>shenyu-2.4.x-grpc-scenario</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
<modules>
<module>shenyu-grpc-entry</module>
<module>shenyu-grpc-gateway</module>
<module>shenyu-grpc-service</module>
<module>shenyu-grpc-dist</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework.version>2.4.3</test.framework.version>
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
<shenyu.gateway.version>2.4.3</shenyu.gateway.version>
<lombok.version>1.18.20</lombok.version>
<grpc.version>1.33.1</grpc.version>
<protobuf.version>3.13.0</protobuf.version>
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
<!--just for test-->
<fastjson.version>1.2.79</fastjson.version>
</properties>
<name>skywalking-shenyu-2.4.x-grpc-scenario</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-gateway</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-grpc</artifactId>
<version>${test.framework.version}</version>
</dependency>
<!--just for test-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>shenyu-2.4.x-grpc-scenario</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-grpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-grpc-dist</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<outputDirectory>../target/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>./bin</directory>
<fileMode>0775</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>../shenyu-grpc-entry/target/shenyu-grpc-entry.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
<file>
<source>../shenyu-grpc-gateway/target/shenyu-grpc-gateway.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
<file>
<source>../shenyu-grpc-service/target/shenyu-grpc-service.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-grpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-grpc-entry</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>
<finalName>shenyu-grpc-entry</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<String> httpService() throws Exception {
TimeUnit.MILLISECONDS.sleep(100);
Map<String, Object> data = new HashMap<>();
data.put("message", "hello world");
Map<String, Object> body = new HashMap<>();
body.put("data", Collections.singletonList(data));
ResponseEntity<String> 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");
}
}

View File

@ -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

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-grpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-grpc-gateway</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
<build>
<finalName>shenyu-grpc-gateway</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<String, PluginData> pluginDataMap = JSON.parseObject(pluginStream,
new TypeReference<Map<String, PluginData>>() {
}.getType(), Feature.AllowComment);
Map<String, List<SelectorData>> selectorDataMap = JSON.parseObject(selectorStream,
new TypeReference<Map<String, List<SelectorData>>>() {
}.getType(), Feature.AllowComment);
Map<String, List<RuleData>> ruleDataMap = JSON.parseObject(ruleStream,
new TypeReference<Map<String, List<RuleData>>>() {
}.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");
}
}

View File

@ -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

View File

@ -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
}
}

View File

@ -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"
}
]
}
]
}

View File

@ -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/"
}
]
}
]
}

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-grpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-grpc-service</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
</dependency>
</dependencies>
<build>
<finalName>shenyu-grpc-service</finalName>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${os-maven-plugin.version}</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
<protoSourceRoot>src/main/resources/proto</protoSourceRoot>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<EchoResponse> responseObserver) {
EchoResponse.Builder response = EchoResponse.newBuilder()
.setMessage("received client message:" + request.getMessage());
responseObserver.onNext(response.build());
responseObserver.onCompleted();
}
}

View File

@ -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();
}
}

View File

@ -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";
}

View File

@ -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<Descriptors.FieldDescriptor, Object> 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<DynamicMessage, DynamicMessage> createJsonMarshallerMethodDescriptor(
String serviceName, String methodName, MethodDescriptor.MethodType methodType,
DynamicMessage request, DynamicMessage response) {
return MethodDescriptor.<DynamicMessage, DynamicMessage>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<DynamicMessage> {
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();
}
}
}

View File

@ -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<String, Class<?>> REQUEST_PARAMS_CLASS_MAP = new HashMap<>();
public static ServerServiceDefinition buildDynamicServerServiceDefinition(ServerServiceDefinition serviceDef)
throws Exception {
MethodDescriptor.Marshaller<DynamicMessage> marshaller =
io.grpc.protobuf.ProtoUtils.marshaller(DynamicJsonMessage.buildJsonDynamicMessage());
List<ServerMethodDefinition<?, ?>> wrappedMethods = new ArrayList<>();
List<MethodDescriptor<?, ?>> 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<DynamicMessage, DynamicMessage> 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 <R, P, W, M> ServerMethodDefinition<W, M> wrapMethod(
ServerMethodDefinition<R, P> definition,
MethodDescriptor<W, M> wrappedMethod) {
ServerCallHandler<W, M> wrappedHandler = wrapHandler(definition.getServerCallHandler());
return ServerMethodDefinition.create(wrappedMethod, wrappedHandler);
}
@SuppressWarnings("unchecked")
private static <R, P, W, M> ServerCallHandler<W, M> wrapHandler(
ServerCallHandler<R, P> originalHandler) {
return (call, headers) -> {
ServerCall<R, P> unwrappedCall = new ProtoToDynamicServerCall<>((ServerCall<R, P>) call);
ServerCall.Listener<R> originalListener = originalHandler.startCall(unwrappedCall, headers);
return new DynamicToProtoServerCallListener(originalListener, unwrappedCall);
};
}
public static Map<String, Class<?>> getRequestParamsClassMap() {
return REQUEST_PARAMS_CLASS_MAP;
}
}

View File

@ -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<R, P> extends SimpleForwardingServerCallListener<R> {
private static final Logger LOG = LoggerFactory.getLogger(DynamicToProtoServerCallListener.class);
private final ServerCall<R, P> call;
public DynamicToProtoServerCallListener(final Listener<R> delegate, final ServerCall<R, P> 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;
}
}

View File

@ -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<R, P> extends SimpleForwardingServerCall<R, P> {
protected ProtoToDynamicServerCall(ServerCall<R, P> 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();
}
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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: []

View File

@ -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:

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.skywalking</groupId>
<artifactId>shenyu-2.4.x-sofarpc-scenario</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
<modules>
<module>shenyu-sofarpc-entry</module>
<module>shenyu-sofarpc-gateway</module>
<module>shenyu-sofarpc-service</module>
<module>shenyu-sofarpc-dist</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework.version>2.4.3</test.framework.version>
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
<shenyu.gateway.version>2.4.3</shenyu.gateway.version>
<lombok.version>1.18.20</lombok.version>
<rpc-sofa-boot-starter.version>6.0.4</rpc-sofa-boot-starter.version>
<sofa-rpc-all.version>5.7.6</sofa-rpc-all.version>
<zk-client.version>4.0.1</zk-client.version>
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
<!--just for test-->
<fastjson.version>1.2.79</fastjson.version>
</properties>
<name>skywalking-2.4.x-sofarpc-scenario</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-gateway</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>rpc-sofa-boot-starter</artifactId>
<version>${rpc-sofa-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-sofa</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-all</artifactId>
<version>${sofa-rpc-all.version}</version>
</dependency>
<!--just for test-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>shenyu-2.4.x-sofarpc-scenario</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-sofarpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-sofarpc-dist</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<outputDirectory>../target/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>./bin</directory>
<fileMode>0775</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>../shenyu-sofarpc-entry/target/shenyu-sofarpc-entry.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
<file>
<source>../shenyu-sofarpc-gateway/target/shenyu-sofarpc-gateway.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
<file>
<source>../shenyu-sofarpc-service/target/shenyu-sofarpc-service.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-sofarpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-sofarpc-entry</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>
<finalName>shenyu-sofarpc-entry</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<String> httpService() throws Exception {
TimeUnit.MILLISECONDS.sleep(100);
ResponseEntity<String> 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");
}
}

View File

@ -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

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-sofarpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-sofarpc-gateway</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-all</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-sofa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
<build>
<finalName>shenyu-sofarpc-gateway</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<String, PluginData> pluginDataMap = JSON.parseObject(pluginStream,
new TypeReference<Map<String, PluginData>>() {
}.getType(), Feature.AllowComment);
Map<String, List<SelectorData>> selectorDataMap = JSON.parseObject(selectorStream,
new TypeReference<Map<String, List<SelectorData>>>() {
}.getType(), Feature.AllowComment);
Map<String, List<RuleData>> ruleDataMap = JSON.parseObject(ruleStream,
new TypeReference<Map<String, List<RuleData>>>() {
}.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<GenericService> 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);
}
}

View File

@ -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

View File

@ -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
}
}

View File

@ -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"
}
]
}
]
}

View File

@ -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/"
}
]
}
]
}

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shenyu-2.4.x-sofarpc-scenario</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-sofarpc-service</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-all</artifactId>
</dependency>
</dependencies>
<build>
<finalName>shenyu-sofarpc-service</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<SofaRpcDemoService> providerConfig =
new ProviderConfig<SofaRpcDemoService>().setInterfaceId(SofaRpcDemoService.class
.getName()).setRef(new SofaRpcDemoServiceImpl()).setServer(config);
providerConfig.export();
return providerConfig;
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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