Adapt Armeria's plugins to the latest version 1.22.x (#459)
This commit is contained in:
parent
37aa3f8bd0
commit
e648ca2145
|
|
@ -17,6 +17,7 @@ Release Notes.
|
|||
* Fix OracleURLParser ignoring actual port when :SID is absent.
|
||||
* Change gRPC instrumentation point to fix plugin not working for server side.
|
||||
* Fix servicecomb plugin trace break.
|
||||
* Adapt Armeria's plugins to the latest version 1.22.x
|
||||
|
||||
#### Documentation
|
||||
* Update docs of Tracing APIs, reorganize the API docs into six parts.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
<?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-armeria-plugins</artifactId>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<version>8.15.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>apm-armeria-1.0.x-plugin</artifactId>
|
||||
<name>apm-armeria-1.0.x-plugin</name>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<description>SkyWalking Agent Plugin for Armeria 1.0.x+</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.linecorp.armeria</groupId>
|
||||
<artifactId>armeria</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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.Clients;
|
||||
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.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
public abstract class AbstractArmeriaClientInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
private static final String KEY_SAFE_CLOSEABLE = "SAFE_CLOSEABLE";
|
||||
|
||||
protected abstract URI getUri(EnhancedInstance objInst);
|
||||
|
||||
protected abstract HttpMethod getHttpMethod(Object[] allArguments);
|
||||
|
||||
protected abstract String getPath(Object[] allArguments);
|
||||
|
||||
protected abstract HttpRequest getHttpRequest(Object[] allArguments);
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) {
|
||||
URI uri = getUri(objInst);
|
||||
HttpMethod httpMethod = getHttpMethod(allArguments);
|
||||
String path = getPath(allArguments);
|
||||
|
||||
final ContextCarrier contextCarrier = new ContextCarrier();
|
||||
final String remotePeer = uri.getPort() > 0 ? uri.getHost() + ":" + uri.getPort() : uri.getHost();
|
||||
|
||||
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.withHeaders(builder -> {
|
||||
for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) {
|
||||
item = item.next();
|
||||
builder.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) {
|
||||
HttpRequest req = getHttpRequest(allArguments);
|
||||
if (req != null && ContextManager.isActive()) {
|
||||
ContextManager.stopSpan();
|
||||
}
|
||||
|
||||
SafeCloseable safeCloseable = ContextManager.getRuntimeContext().get(KEY_SAFE_CLOSEABLE, SafeCloseable.class);
|
||||
if (safeCloseable != null) {
|
||||
safeCloseable.close();
|
||||
}
|
||||
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().log(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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.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 java.net.URI;
|
||||
|
||||
public class Armeria100ClientInterceptor extends AbstractArmeriaClientInterceptor {
|
||||
|
||||
@Override
|
||||
protected URI getUri(EnhancedInstance objInst) {
|
||||
UserClient userClient = (UserClient) objInst;
|
||||
return userClient.uri();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpMethod getHttpMethod(Object[] allArguments) {
|
||||
return (HttpMethod) allArguments[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPath(Object[] allArguments) {
|
||||
return (String) allArguments[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpRequest getHttpRequest(Object[] allArguments) {
|
||||
return (HttpRequest) allArguments[6];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Instruments Armeria client 1.0.x
|
||||
*/
|
||||
public class Armeria100ClientInstrumentation 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.Armeria100ClientInterceptor";
|
||||
|
||||
@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(takesArgument(0, named("com.linecorp.armeria.common.SessionProtocol"))).and(takesArgument(1, named("com.linecorp.armeria.client.endpoint.EndpointGroup"))).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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] witnessClasses() {
|
||||
return new String[]{"com.linecorp.armeria.common.AbstractHttpHeadersBuilder"};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# 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.
|
||||
|
||||
armeria-100=org.apache.skywalking.apm.plugin.armeria.define.Armeria100ClientInstrumentation
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?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>8.15.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>apm-armeria-plugins</artifactId>
|
||||
<name>apm-armeria-plugins</name>
|
||||
|
||||
<modules>
|
||||
<module>apm-armeria-1.0.x-plugin</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<sdk.plugin.related.dir>/..</sdk.plugin.related.dir>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
@ -17,10 +17,9 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.armeria;
|
||||
|
||||
import com.linecorp.armeria.common.DefaultHttpRequest;
|
||||
import com.linecorp.armeria.common.HttpHeaders;
|
||||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import io.netty.util.AsciiString;
|
||||
import java.lang.reflect.Method;
|
||||
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -32,13 +31,15 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
|
|||
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;
|
||||
|
||||
@SuppressWarnings("unused") // actually used
|
||||
public class Armeria085ServerInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
|
||||
|
||||
DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
|
||||
HttpRequest httpRequest = (HttpRequest) allArguments[1];
|
||||
HttpHeaders headers = httpRequest.headers();
|
||||
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@
|
|||
<module>nats-2.14.x-2.15.x-plugin</module>
|
||||
<module>jedis-plugins</module>
|
||||
<module>impala-jdbc-2.6.x-plugin</module>
|
||||
<module>apm-armeria-plugins</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
- armeria-085
|
||||
- armeria-086
|
||||
- armeria-098
|
||||
- armeria-100
|
||||
- async-http-client-2.x
|
||||
- avro-1.x
|
||||
- brpc-java
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ metrics based on the tracing data.
|
|||
* [gRPC](https://github.com/grpc/grpc-java) 1.x
|
||||
* [Apache ServiceComb Java Chassis](https://github.com/apache/servicecomb-java-chassis) 1.x, 2.x
|
||||
* [SOFARPC](https://github.com/alipay/sofa-rpc) 5.4.0
|
||||
* [Armeria](https://github.com/line/armeria) 0.63.0 -> 0.98.0
|
||||
* [Armeria](https://github.com/line/armeria) 0.63.0 -> 1.22.0
|
||||
* [Apache Avro](http://avro.apache.org) 1.7.0 - 1.8.x
|
||||
* [Finagle](https://github.com/twitter/finagle) 6.44.0 -> 20.1.0 (6.25.0 -> 6.44.0 not tested)
|
||||
* [Brpc-Java](https://github.com/baidu/brpc-java) 2.3.7 -> 3.0.5
|
||||
|
|
|
|||
|
|
@ -20,17 +20,18 @@ package org.apache.skywalking.apm.testcase.armeria;
|
|||
import com.linecorp.armeria.common.HttpResponse;
|
||||
import com.linecorp.armeria.server.Server;
|
||||
import com.linecorp.armeria.server.ServerBuilder;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class ServerApplication {
|
||||
private static final String SUCCESS = "Success";
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
ServerBuilder sb = new ServerBuilder().http(8085)
|
||||
ServerBuilder sb = Server.builder().http(8085)
|
||||
.service("/healthCheck", (ctx, res) -> HttpResponse.of(SUCCESS))
|
||||
.service("/greet/{name}", (ctx, res) -> HttpResponse.of("Hello %s~", ctx.pathParam("name")));
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,30 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
1.22.0
|
||||
1.21.0
|
||||
1.20.0
|
||||
1.19.0
|
||||
1.18.0
|
||||
1.17.0
|
||||
1.16.0
|
||||
1.15.0
|
||||
1.14.0
|
||||
1.13.0
|
||||
1.12.0
|
||||
1.11.0
|
||||
1.10.0
|
||||
1.9.0
|
||||
1.8.0
|
||||
1.7.0
|
||||
1.6.0
|
||||
1.5.0
|
||||
1.4.0
|
||||
1.3.0
|
||||
1.2.0
|
||||
1.1.0
|
||||
1.0.0
|
||||
0.99.0
|
||||
0.98.0
|
||||
0.97.0
|
||||
0.96.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue