This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push: new eea5d02 Add Armeria Java agent plugin (#4024) eea5d02 is described below commit eea5d027ccfe3aaac2778e96644dbc6eb4e0a491 Author: kezhenxu94 <kezhenx...@apache.org> AuthorDate: Wed Dec 11 15:57:45 2019 +0800 Add Armeria Java agent plugin (#4024) --- .github/workflows/plugins-test.yaml | 9 +- .../network/trace/component/ComponentsDefine.java | 2 + .../apm-sdk-plugin/armeria-0.84.x-plugin/pom.xml | 42 ++++++++ .../armeria/Armeria084ClientInterceptor.java | 108 +++++++++++++++++++++ .../armeria/Armeria084ServerInterceptor.java | 89 +++++++++++++++++ .../define/Armeria084ClientInstrumentation.java | 89 +++++++++++++++++ .../define/Armeria084ServerInstrumentation.java | 84 ++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 7 +- apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../optional-plugins/armeria-0.85.x-plugin/pom.xml | 45 +++++++++ .../armeria/Armeria085ClientInterceptor.java | 70 +++++++++++++ .../armeria/Armeria085ServerInterceptor.java | 89 +++++++++++++++++ .../armeria/Armeria086ClientInterceptor.java | 70 +++++++++++++ .../plugin/armeria/ArmeriaClientInterceptor.java | 87 +++++++++++++++++ .../define/Armeria085ClientInstrumentation.java | 88 +++++++++++++++++ .../define/Armeria085ServerInstrumentation.java | 83 ++++++++++++++++ .../define/Armeria086ClientInstrumentation.java | 89 +++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 8 +- apm-sniffer/optional-plugins/pom.xml | 1 + .../service-agent/java-agent/Supported-list.md | 1 + .../src/main/resources/component-libraries.yml | 3 + .../src/test/resources/component-libraries.yml | 3 + .../bin/startup.sh | 2 +- .../config/expectedData.yaml | 85 ++++++++++++++++ .../configuration.yml} | 12 ++- .../scenarios/armeria-0.96minus-scenario/pom.xml | 97 ++++++++++++++++++ .../src/main/assembly/assembly.xml | 41 ++++++++ .../apm/testcase/armeria/Application.java | 31 ++++++ .../apm/testcase/armeria/ClientApplication.java | 44 +++++++++ .../apm/testcase/armeria/ServerApplication.java | 47 +++++++++ .../src/main/resources/application.yaml} | 6 +- .../support-version.list} | 25 ++++- .../bin/startup.sh | 2 +- .../config/expectedData.yaml | 85 ++++++++++++++++ .../configuration.yml} | 12 ++- .../scenarios/armeria-0.96plus-scenario/pom.xml | 98 +++++++++++++++++++ .../src/main/assembly/assembly.xml | 41 ++++++++ .../apm/testcase/armeria/Application.java | 31 ++++++ .../apm/testcase/armeria/ClientApplication.java | 44 +++++++++ .../apm/testcase/armeria/ServerApplication.java | 47 +++++++++ .../src/main/resources/application.yaml} | 6 +- .../support-version.list} | 7 +- .../scenarios/dubbo-2.5.x-scenario/bin/startup.sh | 2 +- .../scenarios/dubbo-2.7.x-scenario/bin/startup.sh | 2 +- 44 files changed, 1791 insertions(+), 44 deletions(-) diff --git a/.github/workflows/plugins-test.yaml b/.github/workflows/plugins-test.yaml index 8270883..c1bccd2 100644 --- a/.github/workflows/plugins-test.yaml +++ b/.github/workflows/plugins-test.yaml @@ -121,7 +121,7 @@ jobs: - name: Run gson-scenario (7) run: bash test/plugin/run.sh gson-scenario - Feign_Canal: + Feign_Canal_Armeria: runs-on: ubuntu-18.04 timeout-minutes: 90 strategy: @@ -149,8 +149,13 @@ jobs: run: bash test/plugin/run.sh customize-scenario - name: Run canal 1.0.24-1.1.2 (5) run: bash test/plugin/run.sh canal-scenario - - name: Run Feign_Canal_Pulsar 2.2.0-2.4.1 (7) + - name: Run Pulsar 2.2.0-2.4.1 (7) run: bash test/plugin/run.sh pulsar-scenario + - name: Run Armeria 0.63.0-0.95.0 (20) + run: bash test/plugin/run.sh armeria-0.96minus-scenario + - name: Run Armeria 0.96.0-0.97.0 (2) + run: bash test/plugin/run.sh armeria-0.96plus-scenario + Hystrix_SofaRPC_Spring30x: runs-on: ubuntu-18.04 diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index 6d1eedf..8ac1799 100755 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -147,4 +147,6 @@ public class ComponentsDefine { public static final OfficialComponent REST_HIGH_LEVEL_CLIENT = new OfficialComponent(77, "rest-high-level-client"); public static final OfficialComponent SPRING_TX = new OfficialComponent(78, "spring-tx"); + + public static final OfficialComponent ARMERIA = new OfficialComponent(79, "Armeria"); } diff --git a/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/pom.xml new file mode 100644 index 0000000..d93305a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/pom.xml @@ -0,0 +1,42 @@ +<?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>apm-sdk-plugin</artifactId> + <groupId>org.apache.skywalking</groupId> + <version>6.6.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>apm-armeria-0.8.x-plugin</artifactId> + <name>armeria-0.8.x-plugin</name> + <packaging>jar</packaging> + <description>SkyWalking Agent Plugin for Armeria 0.63.0 ~ 0.84.0</description> + + <dependencies> + <dependency> + <groupId>com.linecorp.armeria</groupId> + <artifactId>armeria</artifactId> + <version>[0.63.0, 0.84.0]</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project> \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria084ClientInterceptor.java b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria084ClientInterceptor.java new file mode 100644 index 0000000..c5fd74e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria084ClientInterceptor.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria; + +import com.linecorp.armeria.client.UserClient; +import com.linecorp.armeria.common.HttpHeaders; +import com.linecorp.armeria.common.HttpMethod; +import com.linecorp.armeria.common.HttpRequest; +import io.netty.util.AsciiString; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import java.lang.reflect.Method; +import java.net.URI; + +/** + * @author kezhenxu94 + */ +@SuppressWarnings("rawtypes") +public class Armeria084ClientInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final MethodInterceptResult result) throws Throwable { + + final UserClient userClient = (UserClient) objInst; + final URI uri = userClient.uri(); + final HttpMethod httpMethod = (HttpMethod) allArguments[1]; + final String path = (String) allArguments[2]; + final Object req = allArguments[5]; + + if (!(req instanceof HttpRequest)) { + return; + } + + final HttpRequest httpReq = (HttpRequest) req; + + final ContextCarrier contextCarrier = new ContextCarrier(); + final String remotePeer = uri.getHost() + ":" + uri.getPort(); + + final AbstractSpan exitSpan = ContextManager.createExitSpan(path, contextCarrier, remotePeer); + + exitSpan.setComponent(ComponentsDefine.ARMERIA); + exitSpan.setLayer(SpanLayer.HTTP); + Tags.HTTP.METHOD.set(exitSpan, httpMethod.name()); + + HttpHeaders headers = httpReq.headers(); + for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) { + item = item.next(); + headers.add(AsciiString.of(item.getHeadKey()), item.getHeadValue()); + } + } + + @Override + public Object afterMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Object ret) { + + Object req = allArguments[5]; + + if (req instanceof HttpRequest && ContextManager.isActive()) { + ContextManager.stopSpan(); + } + + return ret; + } + + @Override + public void handleMethodException( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Throwable t) { + if (ContextManager.isActive()) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria084ServerInterceptor.java b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria084ServerInterceptor.java new file mode 100644 index 0000000..650bfe5 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria084ServerInterceptor.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria; + +import com.linecorp.armeria.common.DefaultHttpRequest; +import com.linecorp.armeria.common.HttpHeaders; +import io.netty.util.AsciiString; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import java.lang.reflect.Method; + +/** + * @author kezhenxu94 + */ +public class Armeria084ServerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final MethodInterceptResult result) throws Throwable { + + DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1]; + HttpHeaders headers = httpRequest.headers(); + + ContextCarrier carrier = new ContextCarrier(); + for (CarrierItem item = carrier.items(); item.hasNext(); ) { + item = item.next(); + item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey()))); + } + + AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier); + entrySpan.setComponent(ComponentsDefine.ARMERIA); + entrySpan.setLayer(SpanLayer.HTTP); + entrySpan.setPeer(httpRequest.authority()); + Tags.URL.set(entrySpan, httpRequest.path()); + Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name()); + } + + @Override + public Object afterMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Object ret) { + if (ContextManager.isActive()) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Throwable t) { + if (ContextManager.isActive()) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria084ClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria084ClientInstrumentation.java new file mode 100644 index 0000000..6f81562 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria084ClientInstrumentation.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria.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 net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class Armeria084ClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.linecorp.armeria.client.UserClient"; + private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria084ClientInterceptor"; + + @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("execute") + .and(takesArguments(7)) + .and(takesArgument(0, named("io.netty.channel.EventLoop"))) + .and(takesArgument(1, named("com.linecorp.armeria.common.HttpMethod"))) + .and(takesArgument(2, named("java.lang.String"))) + .and(takesArgument(3, named("java.lang.String"))) + .and(takesArgument(4, named("java.lang.String"))); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + /** + * Witness classes that are added since 0.63.0 + * + * @return witness classes + */ + @Override + protected String[] witnessClasses() { + return new String[]{ + "com.linecorp.armeria.client.endpoint.dns.DnsEndpointGroup", + "com.linecorp.armeria.common.ImmutableHttpHeaders" + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria084ServerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria084ServerInstrumentation.java new file mode 100644 index 0000000..63cd348 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria084ServerInstrumentation.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria.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 net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class Armeria084ServerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.linecorp.armeria.server.HttpServerHandler"; + private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria084ServerInterceptor"; + + @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("handleRequest") + .and(takesArgument(0, named("io.netty.channel.ChannelHandlerContext"))) + .and(takesArgument(1, named("com.linecorp.armeria.server.DecodedHttpRequest"))); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + /** + * Witness classes that are added since 0.63.0 and removed since 0.85.0 + * + * @return witness classes + */ + @Override + protected String[] witnessClasses() { + return new String[]{ + "com.linecorp.armeria.client.endpoint.dns.DnsEndpointGroup", + "com.linecorp.armeria.common.ImmutableHttpHeaders" + }; + } +} diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/resources/skywalking-plugin.def similarity index 80% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/resources/skywalking-plugin.def index 3da8446..83bd6d3 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/apm-sniffer/apm-sdk-plugin/armeria-0.84.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,5 @@ # 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=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +armeria-063-084=org.apache.skywalking.apm.plugin.armeria.define.Armeria084ServerInstrumentation +armeria-063-084=org.apache.skywalking.apm.plugin.armeria.define.Armeria084ClientInstrumentation \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index a996129..13c6dd7 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -80,6 +80,7 @@ <module>ehcache-2.x-plugin</module> <module>pulsar-plugin</module> <module>netty-socketio-plugin</module> + <module>armeria-0.84.x-plugin</module> </modules> <packaging>pom</packaging> diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/pom.xml b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/pom.xml new file mode 100644 index 0000000..692430f --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/pom.xml @@ -0,0 +1,45 @@ +<?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> + <groupId>org.apache.skywalking</groupId> + <artifactId>optional-plugins</artifactId> + <version>6.6.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>apm-armeria-0.85.x-plugin</artifactId> + <name>armeria-0.85.x-plugin</name> + <packaging>jar</packaging> + <description>SkyWalking Agent Plugin for Armeria 0.85.0 ~ 0.97.0</description> + <properties> + <compiler.version>1.8</compiler.version> + </properties> + + <dependencies> + <dependency> + <groupId>com.linecorp.armeria</groupId> + <artifactId>armeria</artifactId> + <version>0.85.0</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project> \ No newline at end of file diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria085ClientInterceptor.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria085ClientInterceptor.java new file mode 100644 index 0000000..ab6f47c --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria085ClientInterceptor.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria; + +import com.linecorp.armeria.client.UserClient; +import com.linecorp.armeria.common.HttpMethod; +import com.linecorp.armeria.common.HttpRequest; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +import java.lang.reflect.Method; +import java.net.URI; + +/** + * @author kezhenxu94 + */ +@SuppressWarnings("rawtypes") +public class Armeria085ClientInterceptor extends ArmeriaClientInterceptor { + + @Override + public void beforeMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final MethodInterceptResult result) throws Throwable { + + final UserClient userClient = (UserClient) objInst; + final URI uri = userClient.uri(); + final HttpMethod httpMethod = (HttpMethod) allArguments[1]; + final String path = (String) allArguments[2]; + final Object req = allArguments[5]; + + if (!(req instanceof HttpRequest)) { + return; + } + + beforeMethod(uri, httpMethod, path); + } + + @Override + public Object afterMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Object ret) { + + Object req = allArguments[5]; + + afterMethod(req); + + return ret; + } +} diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria085ServerInterceptor.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria085ServerInterceptor.java new file mode 100644 index 0000000..3b6a6ab --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria085ServerInterceptor.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria; + +import com.linecorp.armeria.common.DefaultHttpRequest; +import com.linecorp.armeria.common.HttpHeaders; +import io.netty.util.AsciiString; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import java.lang.reflect.Method; + +/** + * @author kezhenxu94 + */ +public class Armeria085ServerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final MethodInterceptResult result) throws Throwable { + + DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1]; + HttpHeaders headers = httpRequest.headers(); + + ContextCarrier carrier = new ContextCarrier(); + for (CarrierItem item = carrier.items(); item.hasNext(); ) { + item = item.next(); + item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey()))); + } + + AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier); + entrySpan.setComponent(ComponentsDefine.ARMERIA); + entrySpan.setLayer(SpanLayer.HTTP); + entrySpan.setPeer(httpRequest.authority()); + Tags.URL.set(entrySpan, httpRequest.path()); + Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name()); + } + + @Override + public Object afterMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Object ret) { + if (ContextManager.isActive()) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Throwable t) { + if (ContextManager.isActive()) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } +} diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria086ClientInterceptor.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria086ClientInterceptor.java new file mode 100644 index 0000000..464d1df --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/Armeria086ClientInterceptor.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria; + +import java.lang.reflect.Method; +import java.net.URI; + +import com.linecorp.armeria.client.UserClient; +import com.linecorp.armeria.common.HttpMethod; +import com.linecorp.armeria.common.HttpRequest; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * @author kezhenxu94 + */ +@SuppressWarnings("rawtypes") +public class Armeria086ClientInterceptor extends ArmeriaClientInterceptor { + + @Override + public void beforeMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final MethodInterceptResult result) throws Throwable { + + final UserClient userClient = (UserClient) objInst; + final URI uri = userClient.uri(); + final HttpMethod httpMethod = (HttpMethod) allArguments[2]; + final String path = (String) allArguments[3]; + final Object req = allArguments[6]; + + if (!(req instanceof HttpRequest)) { + return; + } + + beforeMethod(uri, httpMethod, path); + } + + @Override + public Object afterMethod( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Object ret) { + + Object req = allArguments[6]; + + afterMethod(req); + + return ret; + } +} diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/ArmeriaClientInterceptor.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/ArmeriaClientInterceptor.java new file mode 100644 index 0000000..3a7f443 --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/ArmeriaClientInterceptor.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria; + +import java.lang.reflect.Method; +import java.net.URI; + +import com.linecorp.armeria.client.Clients; +import com.linecorp.armeria.common.HttpHeadersBuilder; +import com.linecorp.armeria.common.HttpMethod; +import com.linecorp.armeria.common.HttpRequest; +import com.linecorp.armeria.common.util.SafeCloseable; +import io.netty.util.AsciiString; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * @author kezhenxu94 + */ +public abstract class ArmeriaClientInterceptor implements InstanceMethodsAroundInterceptor { + private static final String KEY_SAFE_CLOSEABLE = "SAFE_CLOSEABLE"; + + protected void beforeMethod(final URI uri, final HttpMethod httpMethod, final String path) { + final ContextCarrier contextCarrier = new ContextCarrier(); + final String remotePeer = uri.getHost() + ":" + uri.getPort(); + + final AbstractSpan exitSpan = ContextManager.createExitSpan(path, contextCarrier, remotePeer); + + exitSpan.setComponent(ComponentsDefine.ARMERIA); + exitSpan.setLayer(SpanLayer.HTTP); + Tags.HTTP.METHOD.set(exitSpan, httpMethod.name()); + + ContextManager.getRuntimeContext().put(KEY_SAFE_CLOSEABLE, Clients.withHttpHeaders(headers -> { + HttpHeadersBuilder builder = headers.toBuilder(); + for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) { + item = item.next(); + builder.add(AsciiString.of(item.getHeadKey()), item.getHeadValue()); + } + return builder.build(); + })); + } + + protected void afterMethod(final Object req) { + if (req instanceof HttpRequest && ContextManager.isActive()) { + ContextManager.stopSpan(); + } + + SafeCloseable safeCloseable = ContextManager.getRuntimeContext().get(KEY_SAFE_CLOSEABLE, SafeCloseable.class); + if (safeCloseable != null) { + safeCloseable.close(); + } + } + + @Override + public void handleMethodException( + final EnhancedInstance objInst, + final Method method, + final Object[] allArguments, + final Class<?>[] argumentsTypes, + final Throwable t) { + if (ContextManager.isActive()) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } +} diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria085ClientInstrumentation.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria085ClientInstrumentation.java new file mode 100644 index 0000000..73e85cb --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria085ClientInstrumentation.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria.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 net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class Armeria085ClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.linecorp.armeria.client.UserClient"; + private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria085ClientInterceptor"; + + @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("execute") + .and(takesArguments(7)) + .and(takesArgument(0, named("io.netty.channel.EventLoop"))) + .and(takesArgument(1, named("com.linecorp.armeria.common.HttpMethod"))) + .and(takesArgument(2, named("java.lang.String"))) + .and(takesArgument(3, named("java.lang.String"))) + .and(takesArgument(4, named("java.lang.String"))); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + /** + * Witness classes that are added since 0.63.0 + * + * @return witness classes + */ + @Override + protected String[] witnessClasses() { + return new String[]{ + "com.linecorp.armeria.common.AbstractHttpHeadersBuilder" + }; + } +} diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria085ServerInstrumentation.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria085ServerInstrumentation.java new file mode 100644 index 0000000..62dcceb --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria085ServerInstrumentation.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria.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 net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class Armeria085ServerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.linecorp.armeria.server.HttpServerHandler"; + private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria085ServerInterceptor"; + + @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("handleRequest") + .and(takesArgument(0, named("io.netty.channel.ChannelHandlerContext"))) + .and(takesArgument(1, named("com.linecorp.armeria.server.DecodedHttpRequest"))); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + /** + * Witness classes that are added since 0.63.0 and removed since 0.85.0 + * + * @return witness classes + */ + @Override + protected String[] witnessClasses() { + return new String[]{ + "com.linecorp.armeria.common.AbstractHttpHeadersBuilder" + }; + } +} diff --git a/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria086ClientInstrumentation.java b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria086ClientInstrumentation.java new file mode 100644 index 0000000..50a5613 --- /dev/null +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/armeria/define/Armeria086ClientInstrumentation.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.plugin.armeria.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 net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class Armeria086ClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.linecorp.armeria.client.UserClient"; + private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria086ClientInterceptor"; + + @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("execute") + .and(takesArguments(8)) + .and(takesArgument(0, named("io.netty.channel.EventLoop"))) + .and(takesArgument(1, named("com.linecorp.armeria.client.Endpoint"))) + .and(takesArgument(2, named("com.linecorp.armeria.common.HttpMethod"))) + .and(takesArgument(3, named("java.lang.String"))) + .and(takesArgument(4, named("java.lang.String"))) + .and(takesArgument(5, named("java.lang.String"))); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + /** + * Witness classes that are added since 0.63.0 + * + * @return witness classes + */ + @Override + protected String[] witnessClasses() { + return new String[]{ + "com.linecorp.armeria.common.AbstractHttpHeadersBuilder" + }; + } +} diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/resources/skywalking-plugin.def similarity index 74% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/resources/skywalking-plugin.def index 3da8446..2702ca9 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/apm-sniffer/optional-plugins/armeria-0.85.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,6 @@ # 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=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +armeria-085=org.apache.skywalking.apm.plugin.armeria.define.Armeria085ServerInstrumentation +armeria-085=org.apache.skywalking.apm.plugin.armeria.define.Armeria085ClientInstrumentation +armeria-086=org.apache.skywalking.apm.plugin.armeria.define.Armeria086ClientInstrumentation \ No newline at end of file diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index 6df7ad0..c038cc4 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -48,6 +48,7 @@ <module>zookeeper-3.4.x-plugin</module> <module>customize-enhance-plugin</module> <module>play-2.x-plugin</module> + <module>armeria-0.85.x-plugin</module> </modules> <dependencies> diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 35c9f3f..19ccd837 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -40,6 +40,7 @@ * [gRPC](https://github.com/grpc/grpc-java) 1.x * [Apache ServiceComb Java Chassis](https://github.com/apache/servicecomb-java-chassis) 0.1 -> 0.5,1.0.x * [SOFARPC](https://github.com/alipay/sofa-rpc) 5.4.0 + * [Armeria](https://github.com/line/armeria) 0.63.0 -> 0.97.0 * MQ * [RocketMQ](https://github.com/apache/rocketmq) 4.x * [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0 diff --git a/oap-server/server-bootstrap/src/main/resources/component-libraries.yml b/oap-server/server-bootstrap/src/main/resources/component-libraries.yml index 1f8f73d..90e1d65 100755 --- a/oap-server/server-bootstrap/src/main/resources/component-libraries.yml +++ b/oap-server/server-bootstrap/src/main/resources/component-libraries.yml @@ -263,6 +263,9 @@ rest-high-level-client: spring-tx: id: 78 languages: Java +Armeria: + id: 79 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/oap-server/server-core/src/test/resources/component-libraries.yml b/oap-server/server-core/src/test/resources/component-libraries.yml index fe1aa1f..b8db445 100755 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -236,6 +236,9 @@ rest-high-level-client: spring-tx: id: 78 languages: Java +Armeria: + id: 79 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96minus-scenario/bin/startup.sh similarity index 87% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96minus-scenario/bin/startup.sh index 3da8446..22aa8dc 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/bin/startup.sh @@ -18,4 +18,4 @@ home="$(cd "$(dirname $0)"; pwd)" -java -jar ${agent_opts} "-Dskywalking.agent.service_name=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +java -jar ${agent_opts} ${home}/../libs/armeria-0.96minus-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/armeria-0.96minus-scenario/config/expectedData.yaml b/test/plugin/scenarios/armeria-0.96minus-scenario/config/expectedData.yaml new file mode 100644 index 0000000..bb987fd --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/config/expectedData.yaml @@ -0,0 +1,85 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +registryItems: + applications: + - {'armeria-0.96minus-scenario': 2} + instances: + - {'armeria-0.96minus-scenario': 1} + operationNames: + - 'armeria-0.96minus-scenario': [/greet/skywalking] + heartbeat: [] +segmentItems: + - applicationCode: armeria-0.96minus-scenario + segmentSize: ge 2 + segments: + - segmentId: not null + spans: + - operationName: /greet/skywalking + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 79 + componentName: '' + isError: false + spanType: Entry + peer: 127.0.0.1:8085 + peerId: 0 + tags: + - {key: url, value: /greet/skywalking} + - {key: http.method, value: GET} + refs: + - {parentEndpointId: 0, parentEndpoint: /greet/skywalking, networkAddressId: 0, + entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '127.0.0.1:8085', entryEndpoint: /greet/skywalking, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: /greet/skywalking + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 79 + componentName: '' + isError: false + spanType: Exit + peer: 127.0.0.1:8085 + peerId: 0 + tags: + - {key: http.method, value: GET} + - operationName: /greet/skywalking + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/greet/skywalking'} + - {key: http.method, value: GET} \ No newline at end of file diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96minus-scenario/configuration.yml similarity index 78% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96minus-scenario/configuration.yml index 3da8446..052d769 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/configuration.yml @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,10 @@ # 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=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +type: jvm +entryService: http://localhost:8080/greet/skywalking +healthCheck: http://localhost:8080/healthCheck +runningMode: with_optional +withPlugins: apm-armeria*.jar +startScript: ./bin/startup.sh +framework: Armeria diff --git a/test/plugin/scenarios/armeria-0.96minus-scenario/pom.xml b/test/plugin/scenarios/armeria-0.96minus-scenario/pom.xml new file mode 100644 index 0000000..b8c6767 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/pom.xml @@ -0,0 +1,97 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.skywalking</groupId> + <artifactId>armeria-0.8.x-scenario</artifactId> + <version>5.0.0</version> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <compiler.version>1.8</compiler.version> + <spring.boot.version>2.1.6.RELEASE</spring.boot.version> + + <test.framework>armeria</test.framework> + <test.framework.version>0.90.0</test.framework.version> + </properties> + + <name>skywalking-armeria-scenario</name> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${spring.boot.version}</version> + </dependency> + + <dependency> + <groupId>com.linecorp.armeria</groupId> + <artifactId>armeria</artifactId> + <version>${test.framework.version}</version> + </dependency> + </dependencies> + + <build> + <finalName>armeria-0.96minus-scenario</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> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>${compiler.version}</source> + <target>${compiler.version}</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + <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> \ No newline at end of file diff --git a/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000..5875156 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ +<?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>./target/armeria-0.96minus-scenario.jar</source> + <outputDirectory>./libs</outputDirectory> + <fileMode>0775</fileMode> + </file> + </files> +</assembly> \ No newline at end of file diff --git a/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/Application.java b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/Application.java new file mode 100644 index 0000000..0dbf7f8 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/Application.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.testcase.armeria; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author kezhenxu94 + */ +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ClientApplication.java b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ClientApplication.java new file mode 100644 index 0000000..90b9f89 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ClientApplication.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.testcase.armeria; + +import java.nio.charset.StandardCharsets; + +import com.linecorp.armeria.client.HttpClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author kezhenxu94 + */ +@RestController +public class ClientApplication { + + private HttpClient httpClient = HttpClient.of("http://127.0.0.1:8085/"); + + @GetMapping("/healthCheck") + public String healthCheck() { + return httpClient.get("/healthCheck").aggregate().join().content().toString(StandardCharsets.UTF_8); + } + + @GetMapping("/greet/{username}") + public String greet(@PathVariable String username) { + return httpClient.get("/greet/" + username).aggregate().join().content().toString(StandardCharsets.UTF_8); + } +} diff --git a/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ServerApplication.java b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ServerApplication.java new file mode 100644 index 0000000..2c97c54 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ServerApplication.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.testcase.armeria; + +import javax.annotation.PostConstruct; +import java.util.concurrent.CompletableFuture; + +import com.linecorp.armeria.common.HttpResponse; +import com.linecorp.armeria.server.Server; +import com.linecorp.armeria.server.ServerBuilder; +import org.springframework.stereotype.Component; + +/** + * @author kezhenxu94 + */ +@Component +public class ServerApplication { + private static final String SUCCESS = "Success"; + + @PostConstruct + public void init() { + ServerBuilder sb = + new ServerBuilder() + .http(8085) + .service("/healthCheck", (ctx, res) -> HttpResponse.of(SUCCESS)) + .service("/greet/{name}", (ctx, res) -> HttpResponse.of("Hello %s~", ctx.pathParam("name"))); + + Server server = sb.build(); + CompletableFuture<Void> future = server.start(); + future.join(); + } +} diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/resources/application.yaml similarity index 82% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96minus-scenario/src/main/resources/application.yaml index 3da8446..6ff39eb8 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/src/main/resources/application.yaml @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -home="$(cd "$(dirname $0)"; pwd)" +server: + port: 8080 -java -jar ${agent_opts} "-Dskywalking.agent.service_name=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96minus-scenario/support-version.list similarity index 82% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96minus-scenario/support-version.list index 3da8446..d7ff782 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96minus-scenario/support-version.list @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,23 @@ # 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=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +0.95.0 +0.94.0 +0.93.0 +0.91.0 +0.90.3 +0.90.2 +0.90.1 +0.90.0 +0.89.1 +0.89.0 +0.88.0 +0.87.0 +0.86.0 +0.85.0 +0.84.0 +0.80.0 +0.79.0 +0.70.0 +0.69.0 +0.63.0 diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96plus-scenario/bin/startup.sh similarity index 87% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96plus-scenario/bin/startup.sh index 3da8446..a1037b4 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/bin/startup.sh @@ -18,4 +18,4 @@ home="$(cd "$(dirname $0)"; pwd)" -java -jar ${agent_opts} "-Dskywalking.agent.service_name=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +java -jar ${agent_opts} ${home}/../libs/armeria-0.96plus-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/armeria-0.96plus-scenario/config/expectedData.yaml b/test/plugin/scenarios/armeria-0.96plus-scenario/config/expectedData.yaml new file mode 100644 index 0000000..56c7be3 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/config/expectedData.yaml @@ -0,0 +1,85 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +registryItems: + applications: + - {'armeria-0.96plus-scenario': 2} + instances: + - {'armeria-0.96plus-scenario': 1} + operationNames: + - 'armeria-0.96plus-scenario': [/greet/skywalking] + heartbeat: [] +segmentItems: + - applicationCode: armeria-0.96plus-scenario + segmentSize: ge 2 + segments: + - segmentId: not null + spans: + - operationName: /greet/skywalking + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 79 + componentName: '' + isError: false + spanType: Entry + peer: 127.0.0.1:8085 + peerId: 0 + tags: + - {key: url, value: /greet/skywalking} + - {key: http.method, value: GET} + refs: + - {parentEndpointId: 0, parentEndpoint: /greet/skywalking, networkAddressId: 0, + entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, + parentServiceInstanceId: 1, networkAddress: '127.0.0.1:8085', entryEndpoint: /greet/skywalking, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: /greet/skywalking + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 79 + componentName: '' + isError: false + spanType: Exit + peer: 127.0.0.1:8085 + peerId: 0 + tags: + - {key: http.method, value: GET} + - operationName: /greet/skywalking + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/greet/skywalking'} + - {key: http.method, value: GET} \ No newline at end of file diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96plus-scenario/configuration.yml similarity index 78% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96plus-scenario/configuration.yml index 3da8446..052d769 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/configuration.yml @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,10 @@ # 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=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +type: jvm +entryService: http://localhost:8080/greet/skywalking +healthCheck: http://localhost:8080/healthCheck +runningMode: with_optional +withPlugins: apm-armeria*.jar +startScript: ./bin/startup.sh +framework: Armeria diff --git a/test/plugin/scenarios/armeria-0.96plus-scenario/pom.xml b/test/plugin/scenarios/armeria-0.96plus-scenario/pom.xml new file mode 100644 index 0000000..fda6fc1 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/pom.xml @@ -0,0 +1,98 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.skywalking</groupId> + <artifactId>armeria-0.96.x-scenario</artifactId> + <version>5.0.0</version> + <description>Armeria test scenarios 0.96.0+</description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <compiler.version>1.8</compiler.version> + <spring.boot.version>2.1.6.RELEASE</spring.boot.version> + + <test.framework>armeria</test.framework> + <test.framework.version>0.96.0</test.framework.version> + </properties> + + <name>skywalking-armeria-scenario</name> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${spring.boot.version}</version> + </dependency> + + <dependency> + <groupId>com.linecorp.armeria</groupId> + <artifactId>armeria</artifactId> + <version>${test.framework.version}</version> + </dependency> + </dependencies> + + <build> + <finalName>armeria-0.96plus-scenario</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> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>${compiler.version}</source> + <target>${compiler.version}</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + <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> \ No newline at end of file diff --git a/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000..2d75f73 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ +<?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>./target/armeria-0.96plus-scenario.jar</source> + <outputDirectory>./libs</outputDirectory> + <fileMode>0775</fileMode> + </file> + </files> +</assembly> \ No newline at end of file diff --git a/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/Application.java b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/Application.java new file mode 100644 index 0000000..0dbf7f8 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/Application.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.testcase.armeria; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author kezhenxu94 + */ +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ClientApplication.java b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ClientApplication.java new file mode 100644 index 0000000..a88f3b4 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ClientApplication.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.testcase.armeria; + +import java.nio.charset.StandardCharsets; + +import com.linecorp.armeria.client.WebClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author kezhenxu94 + */ +@RestController +public class ClientApplication { + + private WebClient httpClient = WebClient.of("http://127.0.0.1:8085/"); + + @GetMapping("/healthCheck") + public String healthCheck() { + return httpClient.get("/healthCheck").aggregate().join().content().toString(StandardCharsets.UTF_8); + } + + @GetMapping("/greet/{username}") + public String greet(@PathVariable String username) { + return httpClient.get("/greet/" + username).aggregate().join().content().toString(StandardCharsets.UTF_8); + } +} diff --git a/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ServerApplication.java b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ServerApplication.java new file mode 100644 index 0000000..2c97c54 --- /dev/null +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/armeria/ServerApplication.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.apm.testcase.armeria; + +import javax.annotation.PostConstruct; +import java.util.concurrent.CompletableFuture; + +import com.linecorp.armeria.common.HttpResponse; +import com.linecorp.armeria.server.Server; +import com.linecorp.armeria.server.ServerBuilder; +import org.springframework.stereotype.Component; + +/** + * @author kezhenxu94 + */ +@Component +public class ServerApplication { + private static final String SUCCESS = "Success"; + + @PostConstruct + public void init() { + ServerBuilder sb = + new ServerBuilder() + .http(8085) + .service("/healthCheck", (ctx, res) -> HttpResponse.of(SUCCESS)) + .service("/greet/{name}", (ctx, res) -> HttpResponse.of("Hello %s~", ctx.pathParam("name"))); + + Server server = sb.build(); + CompletableFuture<Void> future = server.start(); + future.join(); + } +} diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/resources/application.yaml similarity index 82% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96plus-scenario/src/main/resources/application.yaml index 3da8446..6ff39eb8 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/src/main/resources/application.yaml @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -home="$(cd "$(dirname $0)"; pwd)" +server: + port: 8080 -java -jar ${agent_opts} "-Dskywalking.agent.service_name=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/armeria-0.96plus-scenario/support-version.list similarity index 82% copy from test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh copy to test/plugin/scenarios/armeria-0.96plus-scenario/support-version.list index 3da8446..e0e06bf 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/armeria-0.96plus-scenario/support-version.list @@ -1,5 +1,3 @@ -#!/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 @@ -16,6 +14,5 @@ # 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=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +0.97.0 +0.96.0 diff --git a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh b/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh index 3da8446..214b72d 100644 --- a/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/dubbo-2.5.x-scenario/bin/startup.sh @@ -18,4 +18,4 @@ home="$(cd "$(dirname $0)"; pwd)" -java -jar ${agent_opts} "-Dskywalking.agent.service_name=dubbo-2.5.x-scenario" ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file +java -jar ${agent_opts} ${home}/../libs/dubbo-2.5.x-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/dubbo-2.7.x-scenario/bin/startup.sh b/test/plugin/scenarios/dubbo-2.7.x-scenario/bin/startup.sh index f394003..7e8e22e 100644 --- a/test/plugin/scenarios/dubbo-2.7.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/dubbo-2.7.x-scenario/bin/startup.sh @@ -18,4 +18,4 @@ home="$(cd "$(dirname $0)"; pwd)" -java -jar ${agent_opts} "-Dskywalking.agent.service_name=dubbo-2.7.x-scenario" ${home}/../libs/dubbo-2.7.x-scenario.jar & \ No newline at end of file +java -jar ${agent_opts} ${home}/../libs/dubbo-2.7.x-scenario.jar & \ No newline at end of file