Open lukos opened 8 years ago
Do you guys think you will add support for this?
i really don't think thats a good idea... at least not bluntly put as such... my redis logs about 14 million operations per hour (avg of 4 operations per millisecond) and i'm operating from a single 2 core 3gb ram PaaS... that would affect me in 3 ways:
the simple fact of detecting whether or not to log would hurt my performance,
if yes-log, most likely (like SQL dependency log) the log operation wouldn't yield any new information that you don't already have in exceptions or redis itself
the cost of storing such data would be significant (i currently use the basic C2 that goes for about 70 bucks/months)
I'm currently bypasses this problem using a custom implementation for track events in my Application Insights.
My code seems like this:
/// <summary>
///
/// </summary>
public class RedisFacade : IRedisFacade {
private readonly IDatabaseAsync _cache;
private readonly TelemetryClient _telemetry;
private readonly Stopwatch _watch;
private const string Redis = "REDIS";
private readonly string _redisHost;
/// <summary>
///
/// </summary>
/// <param name="multiplexer"></param>
/// <param name="options"></param>
/// <param name="telemetry"></param>
public RedisFacade(IConnectionMultiplexer multiplexer, IOptions<ConnectionsOptions> options,
TelemetryClient telemetry) {
_cache = multiplexer.GetDatabase();
_telemetry = telemetry;
_watch = new Stopwatch();
_redisHost = "myredishost:6379";
}
/// <summary>
///
/// </summary>
/// <param name="method"></param>
/// <param name="func"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
private async Task<T> ExecuteWithTracking<T>(string method, Func<Task<T>> func) {
var start = DateTimeOffset.Now;
if (_watch.IsRunning)
_watch.Restart();
else
_watch.Start();
var result = await func().ConfigureAwait(false);
_watch.Stop();
var end = _watch.Elapsed;
_telemetry.TrackDependency(Redis, _redisHost,
method, string.Empty, start, end, string.Empty, true);
return result;
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public async Task<RedisValue> StringGetAsync(RedisKey key) {
return await ExecuteWithTracking("StringGetAsync", () => _cache.StringGetAsync(key))
.ConfigureAwait(false);
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public async Task<bool> KeyExistsAsync(RedisKey key) {
return await ExecuteWithTracking("KeyExistsAsync", () => _cache.KeyExistsAsync(key))
.ConfigureAwait(false);
}
}
My Application Insights Application Map:
@andre-castro-garcia, is IRedisFacade your own abstraction? If not, how do we inject this abstraction into RedisSessionStateProvider.cs to make sure everything goes through this override.
Currently, Redis does not use Dependency Tracking for Application Insights, and we have seen many issues related to Redis timeouts and network latency that would be much easier to debug and see if dependency tracking was built into this provider.