-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup lettuce instrumentation and add tests
- Loading branch information
Showing
88 changed files
with
2,152 additions
and
1,288 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
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
Binary file not shown.
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,8 @@ | ||
Lettuce 4.3 Instrumentation | ||
=========================== | ||
|
||
This instrumentation only supports synchronous and asynchronous API usage. | ||
|
||
It does NOT support reactive as this version uses RxJava Observables which at | ||
the time of this documentation, is not supported by the Java Agent. For reactive | ||
Lettuce instrumentation, please use 5 or 6 for reactive support with Reactor Core. |
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,24 @@ | ||
dependencies { | ||
implementation(project(":newrelic-weaver-api")) | ||
implementation(project(":agent-bridge")) | ||
implementation 'biz.paluch.redis:lettuce:4.4.1.Final' | ||
testImplementation('org.testcontainers:testcontainers:1.17.1') | ||
testImplementation('junit:junit:4.13.1') | ||
|
||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.lettuce-4.3' | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'biz.paluch.redis:lettuce:[4.3.0,4.4.4.Final]' | ||
excludeRegex '.*SNAPSHOT' | ||
} | ||
|
||
site { | ||
title 'Lettuce 4.3' | ||
type 'Framework' | ||
} |
60 changes: 60 additions & 0 deletions
60
...e-4.3/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands_Instrumentation.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 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.lambdaworks.redis; | ||
|
||
import com.lambdaworks.redis.api.StatefulConnection; | ||
import com.lambdaworks.redis.protocol.AsyncCommand; | ||
import com.lambdaworks.redis.protocol.ProtocolKeyword; | ||
import com.lambdaworks.redis.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.Trace; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.nr.lettuce43.instrumentation.NRBiConsumer; | ||
|
||
@Weave(originalName = "com.lambdaworks.redis.AbstractRedisAsyncCommands") | ||
public abstract class AbstractRedisAsyncCommands_Instrumentation<K, V> { | ||
|
||
public abstract StatefulConnection<K, V> getConnection(); | ||
|
||
@SuppressWarnings("unchecked") | ||
@Trace | ||
public <T> AsyncCommand<K, V, T> dispatch(RedisCommand<K, V, T> cmd) { | ||
AsyncCommand<K, V, T> acmd = Weaver.callOriginal(); | ||
String collName = "?"; | ||
RedisURI uri = null; | ||
|
||
StatefulConnection<K, V> conn = getConnection(); | ||
if (StatefulRedisConnectionImpl_Instrumentation.class.isInstance(conn)) { | ||
StatefulRedisConnectionImpl_Instrumentation<K, V> connImpl = (StatefulRedisConnectionImpl_Instrumentation<K, V>) conn; | ||
if (connImpl.redisURI != null) { | ||
uri = connImpl.redisURI; | ||
} | ||
} | ||
String operation = "UnknownOp"; | ||
ProtocolKeyword t = cmd.getType(); | ||
if (t != null && t.name() != null && !t.name().isEmpty()) { | ||
operation = t.name(); | ||
} | ||
DatastoreParameters params = null; | ||
if (uri != null) { | ||
|
||
params = DatastoreParameters.product("Redis").collection(collName).operation(operation) | ||
.instance(uri.getHost(), uri.getPort()).noDatabaseName().build(); | ||
} else { | ||
params = DatastoreParameters.product("Redis").collection(collName).operation("").noInstance() | ||
.noDatabaseName().noSlowQuery().build(); | ||
} | ||
Segment segment = NewRelic.getAgent().getTransaction().startSegment("Lettuce", operation); | ||
|
||
NRBiConsumer<T> nrBiConsumer = new NRBiConsumer<T>(segment, params); | ||
acmd.whenComplete(nrBiConsumer); | ||
return acmd; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...entation/lettuce-4.3/src/main/java/com/lambdaworks/redis/RedisClient_Instrumentation.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,35 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.lambdaworks.redis; | ||
|
||
import com.lambdaworks.redis.api.StatefulRedisConnection; | ||
import com.lambdaworks.redis.codec.RedisCodec; | ||
import com.lambdaworks.redis.protocol.CommandHandler; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@SuppressWarnings("deprecation") | ||
@Weave(originalName = "com.lambdaworks.redis.RedisClient") | ||
public abstract class RedisClient_Instrumentation extends AbstractRedisClient { | ||
|
||
private final RedisURI redisURI = Weaver.callOriginal(); | ||
|
||
public static RedisClient_Instrumentation create(String uri) { | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public abstract StatefulRedisConnection<String, String> connect(); | ||
|
||
protected <K, V> StatefulRedisConnectionImpl_Instrumentation<K, V> newStatefulRedisConnection(CommandHandler<K, V> commandHandler, | ||
RedisCodec<K, V> codec, long timeout, TimeUnit unit) { | ||
StatefulRedisConnectionImpl_Instrumentation<K, V> connection = Weaver.callOriginal(); | ||
connection.redisURI = redisURI; | ||
return connection; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...-4.3/src/main/java/com/lambdaworks/redis/StatefulRedisConnectionImpl_Instrumentation.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,26 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.lambdaworks.redis; | ||
|
||
import com.lambdaworks.redis.api.StatefulConnection; | ||
import com.lambdaworks.redis.codec.RedisCodec; | ||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Weave(originalName = "com.lambdaworks.redis.StatefulRedisConnectionImpl") | ||
public abstract class StatefulRedisConnectionImpl_Instrumentation<K, V> implements StatefulConnection<K, V> { | ||
|
||
@NewField | ||
public RedisURI redisURI = null; | ||
|
||
public StatefulRedisConnectionImpl_Instrumentation(RedisChannelWriter<K, V> writer, RedisCodec<K, V> codec, long timeout, | ||
TimeUnit unit) { | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
instrumentation/lettuce-4.3/src/main/java/com/nr/lettuce43/instrumentation/NRBiConsumer.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 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.nr.lettuce43.instrumentation; | ||
|
||
import com.newrelic.api.agent.ExternalParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Segment; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
public class NRBiConsumer<T> implements BiConsumer<T, Throwable> { | ||
|
||
private Segment segment = null; | ||
private ExternalParameters params = null; | ||
|
||
public NRBiConsumer(Segment s, ExternalParameters p) { | ||
segment = s; | ||
params = p; | ||
} | ||
|
||
@Override | ||
public void accept(T t, Throwable u) { | ||
if (u != null) { | ||
NewRelic.noticeError(u); | ||
} | ||
|
||
if (segment != null) { | ||
if (params != null) { | ||
segment.reportAsExternal(params); | ||
} | ||
segment.end(); | ||
segment = null; | ||
} else { | ||
if (params != null) { | ||
NewRelic.getAgent().getTracedMethod().reportAsExternal(params); | ||
} | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
instrumentation/lettuce-4.3/src/main/java/com/nr/lettuce43/instrumentation/StringUtils.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,51 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.nr.lettuce43.instrumentation; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class StringUtils { | ||
|
||
public static String getCSS(List<?> list) { | ||
StringBuffer sb = new StringBuffer(); | ||
int i = 0; | ||
int size = list.size(); | ||
for (Object obj : list) { | ||
sb.append(obj); | ||
if (i < size - 1) { | ||
sb.append(','); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
public static String getKeysAsCSS(Map<?, ?> map) { | ||
StringBuffer sb = new StringBuffer(); | ||
int i = 0; | ||
Set<?> keys = map.keySet(); | ||
int size = keys.size(); | ||
for (Object obj : keys) { | ||
sb.append(obj); | ||
if (i < size - 1) { | ||
sb.append(','); | ||
} | ||
} | ||
return sb.toString(); | ||
|
||
} | ||
|
||
public static String getCSSFromArray(Object[] objects) { | ||
if (objects == null || objects.length == 0) { | ||
return " "; | ||
} | ||
List<Object> objectList = Arrays.asList(objects); | ||
return getCSS(objectList); | ||
} | ||
} |
Oops, something went wrong.