forked from apache/skywalking
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support lettuce plugin (apache#2152)
* Support lettuce plugin * lettuce plugin bugfix * lettuce plugin fix license issue * lettuce plugin fix cluster and config issue * plugin lettuce compatible with low 5.0.x version * lettuce plugin support version accurately describes on Supported-list.md * plugin lettuce compatible with low 5.0.2 version * lettuce plugin fix wrong batch method intercept point * move lettuce to optional plugins * fix ci issue * fix ci issue * Modify the description file * Pom code optimization * Optimization operation name * Optimization operation name2
- Loading branch information
1 parent
3b0a1d3
commit a36394d
Showing
24 changed files
with
887 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ 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> | ||
<parent> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>optional-plugins</artifactId> | ||
<version>6.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>apm-lettuce-5.x-plugin</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>lettuce-5.x-plugin</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<lettuce-core.version>5.1.3.RELEASE</lettuce-core.version> | ||
<compiler.version>1.8</compiler.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.lettuce</groupId> | ||
<artifactId>lettuce-core</artifactId> | ||
<version>${lettuce-core.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
60 changes: 60 additions & 0 deletions
60
.../main/java/org/apache/skywalking/apm/plugin/lettuce/v5/AsyncCommandMethodInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.lettuce.v5; | ||
|
||
import io.lettuce.core.protocol.AsyncCommand; | ||
import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; | ||
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.util.function.Consumer; | ||
|
||
/** | ||
* @author zhaoyuguang | ||
*/ | ||
public class AsyncCommandMethodInterceptor implements InstanceMethodsAroundInterceptor { | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
MethodInterceptResult result) throws Throwable { | ||
AsyncCommand asyncCommand = (AsyncCommand) objInst; | ||
String operationName = "Lettuce/" + asyncCommand.getType().name(); | ||
AbstractSpan span = ContextManager.createLocalSpan(operationName + "/onComplete"); | ||
span.setComponent(ComponentsDefine.LETTUCE); | ||
allArguments[0] = new SWConsumer((Consumer) allArguments[0], ContextManager.capture(), operationName); | ||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
Class<?>[] argumentsTypes, Object ret) throws Throwable { | ||
ContextManager.stopSpan(); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
Class<?>[] argumentsTypes, Throwable t) { | ||
ContextManager.activeSpan().errorOccurred().log(t); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...java/org/apache/skywalking/apm/plugin/lettuce/v5/ClientOptionsConstructorInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.lettuce.v5; | ||
|
||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; | ||
|
||
/** | ||
* ClientOptions is the link between RedisChannelWriter and AbstractRedisClient. | ||
* to enhance ClientOptions for bring peer(the cluster configuration information) | ||
* in AbstractRedisClient to RedisChannelWriter. | ||
* | ||
* @author zhaoyuguang | ||
*/ | ||
public class ClientOptionsConstructorInterceptor implements InstanceConstructorInterceptor { | ||
|
||
@Override | ||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
.../main/java/org/apache/skywalking/apm/plugin/lettuce/v5/RedisChannelWriterInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.lettuce.v5; | ||
|
||
import io.lettuce.core.protocol.RedisCommand; | ||
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.InstanceConstructorInterceptor; | ||
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.util.Collection; | ||
|
||
/** | ||
* @author zhaoyuguang | ||
*/ | ||
public class RedisChannelWriterInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { | ||
|
||
@Override | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
MethodInterceptResult result) throws Throwable { | ||
String peer = (String) objInst.getSkyWalkingDynamicField(); | ||
|
||
StringBuilder dbStatement = new StringBuilder(); | ||
String operationName = "Lettuce/"; | ||
|
||
if (allArguments[0] instanceof RedisCommand) { | ||
RedisCommand redisCommand = (RedisCommand) allArguments[0]; | ||
String command = redisCommand.getType().name(); | ||
operationName = operationName + command; | ||
dbStatement.append(command); | ||
} else if (allArguments[0] instanceof Collection) { | ||
@SuppressWarnings("unchecked") | ||
Collection<RedisCommand> redisCommands = (Collection<RedisCommand>) allArguments[0]; | ||
operationName = operationName + "BATCH_WRITE"; | ||
for (RedisCommand redisCommand : redisCommands) { | ||
dbStatement.append(redisCommand.getType().name()).append(";"); | ||
} | ||
} | ||
|
||
AbstractSpan span = ContextManager.createExitSpan(operationName, peer); | ||
span.setComponent(ComponentsDefine.LETTUCE); | ||
Tags.DB_TYPE.set(span, "Redis"); | ||
Tags.DB_STATEMENT.set(span, dbStatement.toString()); | ||
SpanLayer.asCache(span); | ||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
Class<?>[] argumentsTypes, Object ret) throws Throwable { | ||
ContextManager.stopSpan(); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
Class<?>[] argumentsTypes, Throwable t) { | ||
AbstractSpan span = ContextManager.activeSpan(); | ||
span.errorOccurred(); | ||
span.log(t); | ||
} | ||
|
||
@Override | ||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { | ||
EnhancedInstance optionsInst = (EnhancedInstance) allArguments[0]; | ||
objInst.setSkyWalkingDynamicField(optionsInst.getSkyWalkingDynamicField()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...n/java/org/apache/skywalking/apm/plugin/lettuce/v5/RedisClientConstructorInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
|
||
package org.apache.skywalking.apm.plugin.lettuce.v5; | ||
|
||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.RedisURI; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; | ||
|
||
/** | ||
* @author zhaoyuguang | ||
*/ | ||
public class RedisClientConstructorInterceptor implements InstanceConstructorInterceptor { | ||
|
||
@Override | ||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { | ||
RedisURI redisURI = (RedisURI) allArguments[1]; | ||
RedisClient redisClient = (RedisClient) objInst; | ||
EnhancedInstance optionsInst = (EnhancedInstance) redisClient.getOptions(); | ||
optionsInst.setSkyWalkingDynamicField(redisURI.getHost() + ":" + redisURI.getPort()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...org/apache/skywalking/apm/plugin/lettuce/v5/RedisClusterClientConstructorInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.plugin.lettuce.v5; | ||
|
||
import io.lettuce.core.RedisURI; | ||
import io.lettuce.core.cluster.RedisClusterClient; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; | ||
|
||
/** | ||
* @author zhaoyuguang | ||
*/ | ||
public class RedisClusterClientConstructorInterceptor implements InstanceConstructorInterceptor { | ||
|
||
@Override | ||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { | ||
@SuppressWarnings("unchecked") | ||
Iterable<RedisURI> redisURIs = (Iterable<RedisURI>) allArguments[1]; | ||
RedisClusterClient redisClusterClient = (RedisClusterClient) objInst; | ||
StringBuilder peer = new StringBuilder(); | ||
for (RedisURI redisURI : redisURIs) { | ||
peer.append(redisURI.getHost()).append(":").append(redisURI.getPort()).append(";"); | ||
} | ||
EnhancedInstance optionsInst = (EnhancedInstance) redisClusterClient.getOptions(); | ||
optionsInst.setSkyWalkingDynamicField(peer.toString()); | ||
} | ||
} |
Oops, something went wrong.