Skip to content

Commit

Permalink
[pinpoint-apm#9606] Fix redis-lettuce plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Jan 5, 2023
1 parent 6f2d1cb commit 2a82b06
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 35 deletions.
4 changes: 2 additions & 2 deletions agent-testweb/redis-lettuce-plugin-testweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>${spring.boot.version}</version>
<version>2.4.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring.boot.version}</version>
<version>2.4.13</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
* <tr><td>8202</td><td>IOREDIS</td></tr>
* <tr><td>8203</td><td>REDIS_REDISSON</td></tr>
* <tr><td>8204</td><td>REDIS_REDISSON_INTERNAL</td></tr>
* <tr><td>8205</td><td>REDIS_REDISSON_REACTIVE</td></tr>
* <tr><td>8206</td><td>REDIS_LETTUCE_INTERNAL</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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private LettuceConstants() {
}

public static final ServiceType REDIS_LETTUCE = ServiceTypeProvider.getByName("REDIS_LETTUCE");
public static final ServiceType REDIS_LETTUCE_INTERNAL = ServiceTypeProvider.getByName("REDIS_LETTUCE_INTERNAL");
public static final String REDIS_SCOPE = "redisLettuceScope";

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class LettucePlugin implements ProfilerPlugin, TransformTemplateAware {
@Override
public void setup(ProfilerPluginSetupContext context) {
final LettucePluginConfig config = new LettucePluginConfig(context.getConfig());

if (!config.isEnable()) {
logger.info("{} disabled", this.getClass().getSimpleName());
return;
Expand All @@ -67,14 +66,11 @@ public void setup(ProfilerPluginSetupContext context) {

// Set endpoint
addRedisClient();

// Attach endpoint
addDefaultConnectionFuture();
addStatefulRedisConnection();

// Commands
addRedisCommands(config);

addReactive();
}

Expand Down Expand Up @@ -221,7 +217,7 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, Strin

final InstrumentMethod subscribeMethod = target.getDeclaredMethod("subscribe", "org.reactivestreams.Subscriber");
if (subscribeMethod != null) {
subscribeMethod.addInterceptor(FluxAndMonoOperatorSubscribeInterceptor.class, va(LettuceConstants.REDIS_LETTUCE));
subscribeMethod.addInterceptor(FluxAndMonoOperatorSubscribeInterceptor.class, va(LettuceConstants.REDIS_LETTUCE_INTERNAL));
}

return target.toBytecode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,10 @@ public void after(Object target, Object[] args, Object result, Throwable throwab

private boolean validate(final Object target, final Object result) {
if (!(target instanceof EndPointAccessor)) {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor={}, target={}", EndPointAccessor.class.getName(), target);
}
return false;
}

if (!(result instanceof EndPointAccessor)) {
if (isDebug) {
logger.debug("Invalid result object. Need field accessor={}, result={}", EndPointAccessor.class.getName(), result);
}
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] a
Throwable throwable) {
final String endPoint = toEndPoint(target);
recorder.recordApi(getMethodDescriptor());
recorder.recordEndPoint(endPoint != null ? endPoint : "Unknown");
recorder.recordEndPoint(endPoint != null ? endPoint : "UNKNOWN");
recorder.recordDestinationId(LettuceConstants.REDIS_LETTUCE.getName());
recorder.recordServiceType(LettuceConstants.REDIS_LETTUCE);
recorder.recordException(throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,14 @@ public void before(Object target, Object[] args) {

private boolean validate(final Object target, final Object[] args) {
if (ArrayUtils.getLength(args) < 2 || args[1] == null) {
if (isDebug) {
logger.debug("Invalid arguments. Null or not found args({}).", args);
}
return false;
}

if (!(target instanceof EndPointAccessor)) {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor({}).", EndPointAccessor.class.getName());
}
return false;
}

if (!(args[1] instanceof RedisURI)) {
if (isDebug) {
logger.debug("Invalid args[1] object. args[1]={}", args[1]);
}
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,14 @@ public void before(Object target, Object[] args) {

private boolean validate(final Object target, final Object[] args) {
if (ArrayUtils.getLength(args) < 2 || args[1] == null) {
if (isDebug) {
logger.debug("Invalid arguments. Null or not found args({}).", args);
}
return false;
}

if (!(target instanceof EndPointAccessor)) {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor({}).",
EndPointAccessor.class.getName());
}
return false;
}

if (!(args[1] instanceof Iterable)) {
if (isDebug) {
logger.debug("Invalid args[1] object. args[1]={}", args[1]);
}
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AsyncContext getAsyncContext(Object target, Object[] args, Object result,
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordServiceType(LettuceConstants.REDIS_LETTUCE);
recorder.recordServiceType(LettuceConstants.REDIS_LETTUCE_INTERNAL);
recorder.recordException(throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncCon
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordServiceType(LettuceConstants.REDIS_LETTUCE);
recorder.recordServiceType(LettuceConstants.REDIS_LETTUCE_INTERNAL);
recorder.recordException(throwable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ serviceTypes:
matcher:
type: 'exact'
code: 310 # redis.io
- code: 8206
name: 'REDIS_LETTUCE_INTERNAL'
desc: 'REDIS'

0 comments on commit 2a82b06

Please sign in to comment.