-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1897ca
commit df5d9b8
Showing
5 changed files
with
233 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.jedis-4.0.0' } | ||
} | ||
|
||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation(project(":agent-bridge-datastore")) | ||
implementation(project(":newrelic-api")) | ||
implementation(project(":newrelic-weaver-api")) | ||
implementation("redis.clients:jedis:4.0.0") | ||
} | ||
|
||
verifyInstrumentation { | ||
passes 'redis.clients:jedis:[4.0.0,)' | ||
fails 'redis.clients:jedis:[1.4.0,3.8.0]' | ||
// fails 'redis.clients:jedis:[4.0.0,)' | ||
excludeRegex 'redis.clients:jedis:.*-(m|rc|RC|beta)[0-9]*' | ||
// there's something weird about how the verifier treats this version | ||
// exclude 'redis.clients:jedis:3.6.2' | ||
} | ||
|
||
site { | ||
title 'Jedis' | ||
type 'Datastore' | ||
} |
116 changes: 116 additions & 0 deletions
116
...rumentation/jedis-4.0.0/src/main/java/redis/clients/jedis/Connection_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,116 @@ | ||
/* | ||
* | ||
* * Copyright 2020 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package redis.clients.jedis; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.agent.bridge.datastore.DatastoreVendor; | ||
import com.newrelic.api.agent.DatastoreParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
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 redis.clients.jedis.args.Rawable; | ||
import redis.clients.jedis.commands.ProtocolCommand; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.logging.Level; | ||
|
||
@SuppressWarnings({ "ResultOfMethodCallIgnored", "WeakerAccess", "unused" }) // Weaver.callOriginal(), matching signatures | ||
@Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.Connection") | ||
public abstract class Connection_Instrumentation { | ||
|
||
@NewField | ||
private long db = 0; | ||
|
||
@NewField | ||
private String host; | ||
|
||
@NewField | ||
private int port; | ||
|
||
@NewField | ||
private HostAndPort hostAndPort; | ||
|
||
final HostAndPort getHostAndPort(){ | ||
this.hostAndPort = Weaver.callOriginal(); | ||
this.host = this.hostAndPort.getHost(); | ||
this.port = this.hostAndPort.getPort(); | ||
return this.hostAndPort; | ||
|
||
} | ||
|
||
public void disconnect() { | ||
db = 0; | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace(leaf = true) | ||
public void sendCommand(final ProtocolCommand cmd, final byte[]... args) { | ||
Weaver.callOriginal(); | ||
|
||
updateDbIndex(cmd, new String(args[0], StandardCharsets.UTF_8)); | ||
reportMethodAsExternal(cmd, this.host, this.port); | ||
} | ||
|
||
@Trace(leaf = true) | ||
public void sendCommand(final ProtocolCommand cmd, final String... args) { | ||
Weaver.callOriginal(); | ||
|
||
updateDbIndex(cmd, args[0]); | ||
reportMethodAsExternal(cmd, this.host, this.port); | ||
} | ||
|
||
@Trace(leaf = true) | ||
public void sendCommand(final ProtocolCommand cmd) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal(cmd, this.host, this.port); | ||
} | ||
|
||
@Trace(leaf = true) | ||
public void sendCommand(final CommandArguments args){ | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal(args.getCommand(), this.host, this.port); | ||
|
||
} | ||
|
||
private void updateDbIndex(ProtocolCommand cmd, String arg0) { | ||
try { | ||
if (cmd == Protocol.Command.SELECT) { | ||
db = Long.parseLong(arg0); | ||
} else if (cmd == Protocol.Command.QUIT) { | ||
db = 0; | ||
} | ||
} catch (Throwable t) { | ||
AgentBridge.getAgent().getLogger().log(Level.FINER, t, "Unable to set DB index"); | ||
} | ||
} | ||
|
||
private void reportMethodAsExternal(ProtocolCommand command, String serverUsed, int serverPortUsed) { | ||
String operation = "unknown"; | ||
try { | ||
//TODO: investigate eliminating new String usage. Was it used here for a good reason? | ||
//Seems unlikely there's a good reason and all of these usages should benefit from the String pool since | ||
//the commands are from a known bound set of Strings. Maybe the bytes need the charset defined? default for jdk should be UTF-8 anyway. | ||
operation = new String(command.getRaw(), Protocol.CHARSET).toLowerCase(); | ||
} catch (Exception ignored) { } | ||
|
||
NewRelic.getAgent().getTracedMethod().reportAsExternal(DatastoreParameters | ||
.product(DatastoreVendor.Redis.name()) | ||
.collection(null) | ||
.operation(operation) | ||
.instance(serverUsed, serverPortUsed) | ||
.databaseName(String.valueOf(db)) | ||
.build()); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...umentation/jedis-4.0.0/src/main/java/redis/clients/jedis/JedisPubSub_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,90 @@ | ||
/* | ||
* | ||
* * Copyright 2020 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package redis.clients.jedis; | ||
|
||
import com.newrelic.agent.bridge.datastore.DatastoreVendor; | ||
import com.newrelic.api.agent.DatastoreParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
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; | ||
|
||
@SuppressWarnings({ "ResultOfMethodCallIgnored", "unused" }) | ||
@Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.JedisPubSub") | ||
public class JedisPubSub_Instrumentation { | ||
|
||
@NewField | ||
private String host; | ||
|
||
@NewField | ||
private int port; | ||
|
||
@Trace | ||
private void process() { | ||
Weaver.callOriginal(); | ||
} | ||
|
||
public void proceed(Connection client, String... channels){ | ||
this.host = client.getHostAndPort().getHost(); | ||
this.port = client.getHostAndPort().getPort(); | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace | ||
public void onMessage(String channel, String message) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal("message", host, port); | ||
} | ||
|
||
@Trace | ||
public void onPMessage(String pattern, String channel, String message) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal("message", host, port); | ||
} | ||
|
||
@Trace | ||
public void onSubscribe(String channel, int subscribedChannels) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal("subscribe", host, port); | ||
} | ||
|
||
@Trace | ||
public void onUnsubscribe(String channel, int subscribedChannels) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal("unsubscribe", host, port); | ||
} | ||
|
||
@Trace | ||
public void onPUnsubscribe(String pattern, int subscribedChannels) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal("unsubscribe", host, port); | ||
} | ||
|
||
@Trace | ||
public void onPSubscribe(String pattern, int subscribedChannels) { | ||
Weaver.callOriginal(); | ||
|
||
reportMethodAsExternal("subscribe", host, port); | ||
} | ||
|
||
private void reportMethodAsExternal(String commandName, String host, int port) { | ||
NewRelic.getAgent().getTracedMethod().reportAsExternal(DatastoreParameters | ||
.product(DatastoreVendor.Redis.name()) | ||
.collection(null) | ||
.operation(commandName) | ||
.instance(host, port) | ||
.build()); | ||
} | ||
} |
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