Skip to content

Commit

Permalink
[#4843] Add lettuce plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim authored and emeroad committed Dec 12, 2018
1 parent 9f7ddfc commit c186476
Show file tree
Hide file tree
Showing 37 changed files with 387 additions and 116 deletions.
10 changes: 7 additions & 3 deletions agent/src/main/resources-local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,13 @@ profiler.google.httpclient.async=true
###########################################################
# redis
###########################################################
profiler.redis.pipeline
profiler.redis=true
profiler.redis.io=true
# Jedis client
profiler.redis.jedis.enable=true
profiler.redis.jedis.pipeline=true
profiler.redis.jedis.io=true

// Lettuce client
profiler.redis.lettuce.enable=true

###########################################################
# OkHttp
Expand Down
10 changes: 7 additions & 3 deletions agent/src/main/resources-release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,13 @@ profiler.google.httpclient.async=true
###########################################################
# redis
###########################################################
profiler.redis.pipeline
profiler.redis=true
profiler.redis.io=true
# Jedis client
profiler.redis.jedis.enable=true
profiler.redis.jedis.pipeline=true
profiler.redis.jedis.io=true

// Lettuce client
profiler.redis.lettuce.enable=true

###########################################################
# OkHttp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
* <tr><td>8102</td><td>ARCUS_EHCACHE_FUTURE_GET</td></tr>
* <tr><td>8103</td><td>ARCUS_INTERNAL</td></tr>
* <tr><td>8200</td><td>REDIS</td></tr>
* <tr><td>8201</td><td>REDIS_LETTUCE</td></tr>
* <tr><td>8250</td><td><i>RESERVED</i></td></tr>
* <tr><td>8251</td><td><i>RESERVED</i></td></tr>
* <tr><td>8260</td><td><i>RESERVED</i></td></tr>
Expand Down
6 changes: 6 additions & 0 deletions plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<module>jdk-http</module>
<module>json-lib</module>
<module>redis</module>
<module>redis-lettuce</module>
<module>tomcat</module>
<module>thrift</module>
<module>user</module>
Expand Down Expand Up @@ -180,6 +181,11 @@
<artifactId>pinpoint-redis-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-redis-lettuce-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-tomcat-plugin</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions plugins/redis-lettuce/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target/
/.settings/
/.classpath
/.project
/*.iml
13 changes: 13 additions & 0 deletions plugins/redis-lettuce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Redis Lettuce Client.

Currently supports Lettuce 5.0.0.RELEASE ~ 5.1.2.RELEASE

### Pinpoint Configuration
pinpoint.config

#### Set enable options.
~~~
# Enable/Disable
# Default value is true.
profiler.redis..lettuce.enable=true
~~~
44 changes: 44 additions & 0 deletions plugins/redis-lettuce/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint</artifactId>
<relativePath>../..</relativePath>
<version>1.8.1-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-redis-lettuce-plugin</artifactId>
<name>pinpoint-redis-lettuce-plugin</name>
<packaging>jar</packaging>

<properties>
<jdk.home>${env.JAVA_8_HOME}</jdk.home>
<test.jdk.home>${env.JAVA_8_HOME}</test.jdk.home>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-plugin-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2018 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.plugin.redis.lettuce;

public interface EndPointAccessor {
void _$PINPOINT$_setEndPoint(String endPoint);
String _$PINPOINT$_getEndPoint();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2018 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.plugin.redis.lettuce;

import static com.navercorp.pinpoint.common.trace.ServiceTypeProperty.*;

import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.common.trace.ServiceTypeFactory;

/**
*
* @author jaehong.kim
*
*/
public final class LettuceConstants {
private LettuceConstants() {
}

public static final ServiceType REDIS_LETTUCE = ServiceTypeFactory.of(8201, "REDIS_LETTUCE", "REDIS", TERMINAL, RECORD_STATISTICS);
public static final String REDIS_SCOPE = "redisLettuceScope";

public static final String END_POINT_ACCESSOR = "com.navercorp.pinpoint.plugin.redis.lettuce.EndPointAccessor";

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.plugin.redis;
package com.navercorp.pinpoint.plugin.redis.lettuce;

import com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod;
import com.navercorp.pinpoint.bootstrap.instrument.MethodFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
import com.navercorp.pinpoint.plugin.redis.LettuceMethodNameFilter;
import com.navercorp.pinpoint.plugin.redis.RedisConstants;
import com.navercorp.pinpoint.plugin.redis.RedisPluginConfig;

import java.security.ProtectionDomain;

import static com.navercorp.pinpoint.common.util.VarArgs.va;

/**
* @author jaehong.kim
*/
Expand All @@ -46,15 +41,15 @@ public class LettucePlugin implements ProfilerPlugin, TransformTemplateAware {

@Override
public void setup(ProfilerPluginSetupContext context) {
final RedisPluginConfig config = new RedisPluginConfig(context.getConfig());
final LettucePluginConfig config = new LettucePluginConfig(context.getConfig());
if (!config.isEnable()) {
if (logger.isInfoEnabled()) {
logger.info("Disable RedisPlugin.");
logger.info("Disable LettucePlugin.");
}
return;
}
if (logger.isInfoEnabled()) {
logger.info("Enable RedisPlugin. version range=[5.0.0.RELEASE, 5.1.2.RELEASE]");
logger.info("Enable LettucePlugin. version range=[5.0.0.RELEASE, 5.1.2.RELEASE]");
}

// Set endpoint
Expand All @@ -73,7 +68,7 @@ private void addRedisClient() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
final InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
target.addField(RedisConstants.END_POINT_ACCESSOR);
target.addField(LettuceConstants.END_POINT_ACCESSOR);

// Set endpoint
final InstrumentMethod constructor = target.getConstructor("io.lettuce.core.resource.ClientResources", "io.lettuce.core.RedisURI");
Expand All @@ -83,7 +78,7 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader,

// Attach endpoint
for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("connect", "connectAsync", "connectPubSub", "connectPubSubAsync", "connectSentinel", "connectSentinelAsync"))) {
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.redis.lettuce.interceptor.AttachEndPointInterceptor", RedisConstants.REDIS_SCOPE);
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.redis.lettuce.interceptor.AttachEndPointInterceptor", LettuceConstants.REDIS_SCOPE);
}

return target.toBytecode();
Expand All @@ -96,11 +91,11 @@ private void addDefaultConnectionFuture() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
final InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
target.addField(RedisConstants.END_POINT_ACCESSOR);
target.addField(LettuceConstants.END_POINT_ACCESSOR);

// Attach endpoint
for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("get", "join"))) {
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.redis.lettuce.interceptor.AttachEndPointInterceptor", RedisConstants.REDIS_SCOPE);
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.redis.lettuce.interceptor.AttachEndPointInterceptor", LettuceConstants.REDIS_SCOPE);
}

return target.toBytecode();
Expand All @@ -121,13 +116,13 @@ private void addStatefulRedisConnection(final String className) {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
final InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
target.addField(RedisConstants.END_POINT_ACCESSOR);
target.addField(LettuceConstants.END_POINT_ACCESSOR);
return target.toBytecode();
}
});
}

private void addRedisCommands(final RedisPluginConfig config) {
private void addRedisCommands(final LettucePluginConfig config) {
// Commands
addAbstractRedisCommands("io.lettuce.core.AbstractRedisAsyncCommands", true, config);

Expand All @@ -146,7 +141,7 @@ private void addRedisCommands(final RedisPluginConfig config) {
addAbstractRedisCommands("io.lettuce.core.sentinel.RedisSentinelReactiveCommandsImpl", false, config);
}

private void addAbstractRedisCommands(final String className, final boolean getter, final RedisPluginConfig config) {
private void addAbstractRedisCommands(final String className, final boolean getter, final LettucePluginConfig config) {
transformTemplate.transform(className, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
Expand All @@ -157,7 +152,7 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader,

for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.chain(lettuceMethodNameFilter, MethodFilters.modifierNot(MethodFilters.SYNTHETIC)))) {
try {
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.redis.lettuce.interceptor.LettuceMethodInterceptor", va(config.isIo()), RedisConstants.REDIS_SCOPE);
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.redis.lettuce.interceptor.LettuceMethodInterceptor", LettuceConstants.REDIS_SCOPE);
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported method {}", method, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2018 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.plugin.redis.lettuce;

import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;

/**
* @author jaehong.kim
*/
public class LettucePluginConfig {
private boolean enable = true;

public LettucePluginConfig(ProfilerConfig src) {
this.enable = src.readBoolean("profiler.redis.lettuce.enable", true);
}

public boolean isEnable() {
return enable;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("LettucePluginConfig{");
sb.append("enable=").append(enable);
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2018 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.plugin.redis.lettuce;

import com.navercorp.pinpoint.common.trace.AnnotationKey;
import com.navercorp.pinpoint.common.trace.AnnotationKeyMatchers;
import com.navercorp.pinpoint.common.trace.TraceMetadataProvider;
import com.navercorp.pinpoint.common.trace.TraceMetadataSetupContext;

public class LettuceTypeProvider implements TraceMetadataProvider {

@Override
public void setup(TraceMetadataSetupContext context) {
context.addServiceType(LettuceConstants.REDIS_LETTUCE, AnnotationKeyMatchers.exact(AnnotationKey.REDIS_IO));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.plugin.redis.EndPointAccessor;
import com.navercorp.pinpoint.plugin.redis.lettuce.EndPointAccessor;

/**
* @author jaehong.kim
Expand Down
Loading

0 comments on commit c186476

Please sign in to comment.