-
Notifications
You must be signed in to change notification settings - Fork 147
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
StackExchange.Redis Batch Integration + tests #159
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d404f43
test async methods
dd-caleb cb07d33
add batch implementation
dd-caleb 776c6b4
fix field
dd-caleb cb37c4f
look for operations
dd-caleb 93d855f
Merge branch 'master' into caleb/redis-tests
dd-caleb 3b1449c
fix integrations, use a dictionary for test
dd-caleb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
119 changes: 119 additions & 0 deletions
119
src/Datadog.Trace.ClrProfiler.Managed/Integrations/StackExchange.Redis/Base.cs
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,119 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis | ||
{ | ||
/// <summary> | ||
/// Base class for redis integration. | ||
/// </summary> | ||
public class Base | ||
{ | ||
private static Func<object, string> _getCommandAndKeyMethod; | ||
|
||
private static Func<object, string> _getConfigurationMethod; | ||
|
||
/// <summary> | ||
/// Get the configuration for the multiplexer. | ||
/// </summary> | ||
/// <param name="multiplexer">The multiplexer</param> | ||
/// <returns>The configuration</returns> | ||
protected static string GetConfiguration(object multiplexer) | ||
{ | ||
try | ||
{ | ||
if (_getConfigurationMethod == null) | ||
{ | ||
_getConfigurationMethod = DynamicMethodBuilder<Func<object, string>>.CreateMethodCallDelegate(multiplexer.GetType(), "get_Configuration"); | ||
} | ||
|
||
return _getConfigurationMethod(multiplexer); | ||
} | ||
catch | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the host and port from the config | ||
/// </summary> | ||
/// <param name="config">The config</param> | ||
/// <returns>The host and port</returns> | ||
protected static Tuple<string, string> GetHostAndPort(string config) | ||
{ | ||
string host = null; | ||
string port = null; | ||
|
||
if (config != null) | ||
{ | ||
// config can contain several settings separated by commas: | ||
// hostname:port,name=MyName,keepAlive=180,syncTimeout=10000,abortConnect=False | ||
// split in commas, find the one without '=', split that one on ':' | ||
string[] hostAndPort = config.Split(',') | ||
.FirstOrDefault(p => !p.Contains("=")) | ||
?.Split(':'); | ||
|
||
if (hostAndPort != null) | ||
{ | ||
host = hostAndPort[0]; | ||
} | ||
|
||
// check length because port is optional | ||
if (hostAndPort?.Length > 1) | ||
{ | ||
port = hostAndPort[1]; | ||
} | ||
} | ||
|
||
return new Tuple<string, string>(host, port); | ||
} | ||
|
||
/// <summary> | ||
/// Get the raw command. | ||
/// </summary> | ||
/// <param name="multiplexer">The multiplexer</param> | ||
/// <param name="message">The message</param> | ||
/// <returns>The raw command</returns> | ||
protected static string GetRawCommand(object multiplexer, object message) | ||
{ | ||
string cmdAndKey = null; | ||
try | ||
{ | ||
if (_getCommandAndKeyMethod == null) | ||
{ | ||
var asm = multiplexer.GetType().Assembly; | ||
var messageType = asm.GetType("StackExchange.Redis.Message"); | ||
_getCommandAndKeyMethod = DynamicMethodBuilder<Func<object, string>>.CreateMethodCallDelegate(messageType, "get_CommandAndKey"); | ||
} | ||
|
||
cmdAndKey = _getCommandAndKeyMethod(message); | ||
} | ||
catch | ||
{ | ||
} | ||
|
||
return cmdAndKey ?? "COMMAND"; | ||
} | ||
|
||
/// <summary> | ||
/// GetMultiplexer returns the Multiplexer for an object | ||
/// </summary> | ||
/// <param name="obj">The object</param> | ||
/// <returns>The multiplexer</returns> | ||
protected static object GetMultiplexer(object obj) | ||
{ | ||
object multiplexer = null; | ||
try | ||
{ | ||
var fi = obj.GetType().GetField("multiplexer", BindingFlags.NonPublic | BindingFlags.Instance); | ||
multiplexer = fi.GetValue(obj); | ||
} | ||
catch | ||
{ | ||
} | ||
|
||
return multiplexer; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You weren't kidding, that's a lot of methods.