Skip to content

Commit fbafc9d

Browse files
committed
Add NonPreferredEndpointCount
1 parent 8dd98fa commit fbafc9d

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/StackExchange.Redis/PhysicalBridge.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,8 @@ internal string GetStormLog()
350350
internal void IncrementOpCount()
351351
{
352352
Interlocked.Increment(ref operationCount);
353-
354353
#if NET6_0_OR_GREATER
355-
RedisMetrics.Instance.IncrementOpCount(Name);
354+
RedisMetrics.Instance.IncrementOperationCount(Name);
356355
#endif
357356
}
358357

@@ -1408,12 +1407,22 @@ private void LogNonPreferred(CommandFlags flags, bool isReplica)
14081407
if (isReplica)
14091408
{
14101409
if (Message.GetPrimaryReplicaFlags(flags) == CommandFlags.PreferMaster)
1410+
{
14111411
Interlocked.Increment(ref nonPreferredEndpointCount);
1412+
#if NET6_0_OR_GREATER
1413+
RedisMetrics.Instance.IncrementNonPreferredEndpointCount(Name);
1414+
#endif
1415+
}
14121416
}
14131417
else
14141418
{
14151419
if (Message.GetPrimaryReplicaFlags(flags) == CommandFlags.PreferReplica)
1420+
{
14161421
Interlocked.Increment(ref nonPreferredEndpointCount);
1422+
#if NET6_0_OR_GREATER
1423+
RedisMetrics.Instance.IncrementNonPreferredEndpointCount(Name);
1424+
#endif
1425+
}
14171426
}
14181427
}
14191428
}

src/StackExchange.Redis/RedisMetrics.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal sealed class RedisMetrics
1212
//private readonly Counter<long> _completedAsynchronously;
1313
//private readonly Counter<long> _completedSynchronously;
1414
//private readonly Counter<long> _failedSynchronously;
15+
private readonly Counter<long> _nonPreferredEndpointCount;
1516

1617
public static readonly RedisMetrics Instance = new RedisMetrics();
1718

@@ -20,28 +21,41 @@ public RedisMetrics()
2021
_meter = new Meter("StackExchange.Redis");
2122

2223
_operationCount = _meter.CreateCounter<long>(
23-
"operation-count",
24+
"redis-operation-count",
2425
description: "The number of operations performed.");
2526

2627
//_completedAsynchronously = _meter.CreateCounter<long>(
27-
// "completed-asynchronously",
28+
// "redis-completed-asynchronously",
2829
// description: "The number of operations that have been completed asynchronously.");
2930

3031
//_completedSynchronously = _meter.CreateCounter<long>(
31-
// "completed-synchronously",
32+
// "redis-completed-synchronously",
3233
// description: "The number of operations that have been completed synchronously.");
3334

3435
//_failedSynchronously = _meter.CreateCounter<long>(
35-
// "failed-synchronously",
36+
// "redis-failed-synchronously",
3637
// description: "The number of operations that failed to complete asynchronously.");
38+
39+
_nonPreferredEndpointCount = _meter.CreateCounter<long>(
40+
"redis-non-preferred-endpoint-count",
41+
description: "Indicates the total number of messages dispatched to a non-preferred endpoint, for example sent to a primary when the caller stated a preference of replica.");
3742
}
3843

39-
public void IncrementOpCount(string connectionName)
44+
public void IncrementOperationCount(string endpoint)
4045
{
4146
if (_operationCount.Enabled)
4247
{
4348
_operationCount.Add(1,
44-
new KeyValuePair<string, object?>("connection-name", connectionName));
49+
new KeyValuePair<string, object?>("endpoint", endpoint));
50+
}
51+
}
52+
53+
public void IncrementNonPreferredEndpointCount(string endpoint)
54+
{
55+
if (_nonPreferredEndpointCount.Enabled)
56+
{
57+
_nonPreferredEndpointCount.Add(1,
58+
new KeyValuePair<string, object?>("endpoint", endpoint));
4559
}
4660
}
4761
}

0 commit comments

Comments
 (0)