Skip to content

Commit

Permalink
Merge pull request #11 from newrelic-experimental/usingCompletableFut…
Browse files Browse the repository at this point in the history
…ures

fixes due to switch to CompletableFutures
  • Loading branch information
dhilpipre authored Dec 22, 2023
2 parents e838955 + 9c7506b commit 8b4444c
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 155 deletions.
2 changes: 1 addition & 1 deletion redisson_3.16.8/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {

jar {
manifest {
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.redisson_3.16.7'
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.redisson_3.16.8'
attributes 'Implementation-Vendor': 'New Relic Labs'
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
attributes 'Implementation-Version': 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.NodeSource;
import org.redisson.liveobject.core.RedissonObjectBuilder;
import org.redisson.misc.RedissonPromise;

import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.redisson.NRBiConsumer;
import com.nr.instrumentation.redisson.Utils;

@Weave(type=MatchType.BaseClass)
Expand Down Expand Up @@ -51,26 +47,16 @@ public <V, R> RFuture<R> async(boolean readOnlyMode, NodeSource source, Codec co
cmdName = "UnknownCommandName";
}

String subName = command.getSubName();

String oName = Utils.getObjectName();

RFuture<R> mainPromise = Weaver.callOriginal();

if(mainPromise instanceof RedissonPromise) {

String collectionName = Utils.typeSet() ? Utils.getType() : objectType != null ? objectType : "?";
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName);
segment.addCustomAttribute("Command", cmdName);
if(subName != null) {
segment.addCustomAttribute("Sub", subName);
if(!Utils.typeSet()) {
if(objectType != null) {
Utils.setType(objectType);
} else {
Utils.setType("?");
}
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName);
DatastoreParameters dsParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName).build();
RedissonPromise<R> promise = (RedissonPromise<R>)mainPromise;
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams);
promise.onComplete(listener);
}

RFuture<R> mainPromise = Weaver.callOriginal();

Utils.unSetOperation();
Utils.unSetType();
Utils.unSetObjectName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.redisson.command;

import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;

import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisCommand;

import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.redisson.NRBiConsumer;
import com.nr.instrumentation.redisson.Utils;

@Weave(type = MatchType.BaseClass)
public abstract class RedisExecutor<V, R> {

final RedisCommand<V> command = Weaver.callOriginal();

protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) {
String operationName = Utils.getOperation();

String cmdName = operationName != null ? operationName : command.getName();
if(cmdName == null || cmdName.isEmpty()) {
cmdName = "UnknownCommandName";
}

String subName = command.getSubName();
String oName = Utils.getObjectName();
String collectionName = Utils.typeSet() ? Utils.getType() : "?";
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName);
segment.addCustomAttribute("Command", cmdName);
if(subName != null) {
segment.addCustomAttribute("Sub", subName);
}
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName);

RedisClient client = connection.getRedisClient();
InetSocketAddress address = client.getAddr();
String host = null;
int port = -1;

if(address != null) {
host = address.getHostName();
port = address.getPort();
}

DatastoreParameters dsParams;

DatastoreParameters.InstanceParameter iParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName);
if(host != null) {
dsParams = iParams.instance(host, port).build();
} else {
dsParams = iParams.build();
}
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams);
attemptPromise.whenComplete(listener);
Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.NodeSource;
import org.redisson.liveobject.core.RedissonObjectBuilder;
import org.redisson.misc.CompletableFutureWrapper;

import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.redisson.NRBiConsumer;
import com.nr.instrumentation.redisson.Utils;

@Weave(type=MatchType.BaseClass)
Expand Down Expand Up @@ -51,26 +47,16 @@ public <V, R> RFuture<R> async(boolean readOnlyMode, NodeSource source, Codec co
cmdName = "UnknownCommandName";
}

String subName = command.getSubName();

String oName = Utils.getObjectName();

RFuture<R> mainPromise = Weaver.callOriginal();

if(mainPromise instanceof CompletableFutureWrapper) {

String collectionName = Utils.typeSet() ? Utils.getType() : objectType != null ? objectType : "?";
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName);
segment.addCustomAttribute("Command", cmdName);
if(subName != null) {
segment.addCustomAttribute("Sub", subName);
if(!Utils.typeSet()) {
if(objectType != null) {
Utils.setType(objectType);
} else {
Utils.setType("?");
}
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName);
DatastoreParameters dsParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName).build();
CompletableFutureWrapper<R> promise = (CompletableFutureWrapper<R>)mainPromise;
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams);
promise.onComplete(listener);
}

RFuture<R> mainPromise = Weaver.callOriginal();

Utils.unSetOperation();
Utils.unSetType();
Utils.unSetObjectName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.redisson.command;

import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;

import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisCommand;

import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.redisson.NRBiConsumer;
import com.nr.instrumentation.redisson.Utils;

@Weave(type = MatchType.BaseClass)
public abstract class RedisExecutor<V, R> {

final RedisCommand<V> command = Weaver.callOriginal();

protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) {
String operationName = Utils.getOperation();

String cmdName = operationName != null ? operationName : command.getName();
if(cmdName == null || cmdName.isEmpty()) {
cmdName = "UnknownCommandName";
}

String subName = command.getSubName();
String oName = Utils.getObjectName();
String collectionName = Utils.typeSet() ? Utils.getType() : "?";
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName);
segment.addCustomAttribute("Command", cmdName);
if(subName != null) {
segment.addCustomAttribute("Sub", subName);
}
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName);

RedisClient client = connection.getRedisClient();
InetSocketAddress address = client.getAddr();
String host = null;
int port = -1;

if(address != null) {
host = address.getHostName();
port = address.getPort();
}

DatastoreParameters dsParams;

DatastoreParameters.InstanceParameter iParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName);
if(host != null) {
dsParams = iParams.instance(host, port).build();
} else {
dsParams = iParams.build();
}
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams);
attemptPromise.whenComplete(listener);
Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.NodeSource;
import org.redisson.liveobject.core.RedissonObjectBuilder;
import org.redisson.misc.CompletableFutureWrapper;

import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.redisson.NRBiConsumer;
import com.nr.instrumentation.redisson.Utils;

@Weave(type=MatchType.BaseClass)
Expand Down Expand Up @@ -51,26 +47,16 @@ public <V, R> RFuture<R> async(boolean readOnlyMode, NodeSource source, Codec co
cmdName = "UnknownCommandName";
}

String subName = command.getSubName();

String oName = Utils.getObjectName();

RFuture<R> mainPromise = Weaver.callOriginal();

if(mainPromise instanceof CompletableFutureWrapper) {

String collectionName = Utils.typeSet() ? Utils.getType() : objectType != null ? objectType : "?";
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName);
segment.addCustomAttribute("Command", cmdName);
if(subName != null) {
segment.addCustomAttribute("Sub", subName);
if(!Utils.typeSet()) {
if(objectType != null) {
Utils.setType(objectType);
} else {
Utils.setType("?");
}
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName);
DatastoreParameters dsParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName).build();
CompletableFutureWrapper<R> promise = (CompletableFutureWrapper<R>)mainPromise;
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams);
promise.onComplete(listener);
}

RFuture<R> mainPromise = Weaver.callOriginal();

Utils.unSetOperation();
Utils.unSetType();
Utils.unSetObjectName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.redisson.command;

import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;

import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisCommand;

import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.redisson.NRBiConsumer;
import com.nr.instrumentation.redisson.Utils;

@Weave(type = MatchType.BaseClass)
public abstract class RedisExecutor<V, R> {

final RedisCommand<V> command = Weaver.callOriginal();

protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) {
String operationName = Utils.getOperation();

String cmdName = operationName != null ? operationName : command.getName();
if(cmdName == null || cmdName.isEmpty()) {
cmdName = "UnknownCommandName";
}

String subName = command.getSubName();
String oName = Utils.getObjectName();
String collectionName = Utils.typeSet() ? Utils.getType() : "?";
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName);
segment.addCustomAttribute("Command", cmdName);
if(subName != null) {
segment.addCustomAttribute("Sub", subName);
}
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName);

RedisClient client = connection.getRedisClient();
InetSocketAddress address = client.getAddr();
String host = null;
int port = -1;

if(address != null) {
host = address.getHostName();
port = address.getPort();
}

DatastoreParameters dsParams;

DatastoreParameters.InstanceParameter iParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName);
if(host != null) {
dsParams = iParams.instance(host, port).build();
} else {
dsParams = iParams.build();
}
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams);
attemptPromise.whenComplete(listener);
Weaver.callOriginal();
}
}
Loading

0 comments on commit 8b4444c

Please sign in to comment.