Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually fix redisson instrumentation after 3.16.8 release #5201

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions instrumentation/redisson-3.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ muzzle {
pass {
group.set("org.redisson")
module.set("redisson")
// in 3.16.8 CommandsData#getPromise() and CommandData#getPromise() return type was changed in
// a backwards-incompatible way from RPromise to CompletableStage
versions.set("[3.0.0,3.16.8)")
versions.set("[3.0.0,)")
}
}

Expand All @@ -17,8 +15,6 @@ dependencies {

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")

latestDepTestLibrary("org.redisson:redisson:3.16.7")
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.redisson;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.is;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import io.opentelemetry.instrumentation.api.field.VirtualField;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.concurrent.CompletionStage;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.redisson.client.protocol.CommandData;

public class CommandDataInstrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("org.redisson.client.protocol.CommandData");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor().and(takesArgument(0, implementsInterface(is(CompletionStage.class)))),
this.getClass().getName() + "$ConstructorAdvice");
}

public static class ConstructorAdvice {
@Advice.OnMethodExit
public static void onExit(
@Advice.This CommandData<?, ?> command, @Advice.Argument(0) CompletionStage<?> promise) {
VirtualField.find(CommandData.class, CompletionStage.class).set(command, promise);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.redisson;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.is;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import io.opentelemetry.instrumentation.api.field.VirtualField;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.concurrent.CompletionStage;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.redisson.client.protocol.CommandsData;

public class CommandsDataInstrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("org.redisson.client.protocol.CommandsData");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor().and(takesArgument(0, implementsInterface(is(CompletionStage.class)))),
this.getClass().getName() + "$ConstructorAdvice");
}

public static class ConstructorAdvice {
@Advice.OnMethodExit()
public static void onExit(
@Advice.This CommandsData commands, @Advice.Argument(0) CompletionStage<?> promise) {
VirtualField.find(CommandsData.class, CompletionStage.class).set(commands, promise);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletionStage;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.redisson.client.RedisConnection;
import org.redisson.misc.RPromise;

public class RedisConnectionInstrumentation implements TypeInstrumentation {
@Override
Expand Down Expand Up @@ -66,7 +66,7 @@ public static void stopSpan(
}
scope.close();

RPromise<?> promise = request.getPromise();
CompletionStage<?> promise = request.getPromise();
if (promise == null || throwable != null) {
instrumenter().end(context, request, null, throwable);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.redisson;

import static java.util.Collections.singletonList;
import static java.util.Arrays.asList;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
Expand All @@ -21,6 +21,9 @@ public RedissonInstrumentationModule() {

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new RedisConnectionInstrumentation());
return asList(
new CommandDataInstrumentation(),
new CommandDataInstrumentation(),
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
new RedisConnectionInstrumentation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
import com.google.auto.value.AutoValue;
import io.netty.buffer.ByteBuf;
import io.opentelemetry.instrumentation.api.db.RedisCommandSanitizer;
import io.opentelemetry.instrumentation.api.field.VirtualField;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.redisson.client.protocol.CommandData;
import org.redisson.client.protocol.CommandsData;
import org.redisson.misc.RPromise;

@AutoValue
public abstract class RedissonRequest {

private static final VirtualField<CommandData<?, ?>, CompletionStage<?>> commandDataPromiseField =
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
VirtualField.find(CommandData.class, CompletionStage.class);
private static final VirtualField<CommandsData, CompletionStage<?>> commandsDataPromiseField =
VirtualField.find(CommandsData.class, CompletionStage.class);

public static RedissonRequest create(InetSocketAddress address, Object command) {
return new AutoValue_RedissonRequest(address, command);
}
Expand Down Expand Up @@ -97,13 +103,16 @@ private static String normalizeSingleCommand(CommandData<?, ?> command) {
return RedisCommandSanitizer.sanitize(command.getCommand().getName(), args);
}

// in 3.16.8 CommandsData#getPromise() and CommandData#getPromise() return type was changed in
// a backwards-incompatible way from RPromise to CompletableStage - to avoid calling that method
// and triggering muzzle we have to get the promise using a VirtualField
@Nullable
public RPromise<?> getPromise() {
public CompletionStage<?> getPromise() {
Object command = getCommand();
if (command instanceof CommandData) {
return ((CommandData<?, ?>) command).getPromise();
return commandDataPromiseField.get((CommandData<?, ?>) command);
} else if (command instanceof CommandsData) {
return ((CommandsData) command).getPromise();
return commandsDataPromiseField.get((CommandsData) command);
}
return null;
}
Expand Down