Skip to content

Commit 75f0b1e

Browse files
committed
Add NonPreferredEndpointCount
1 parent 5990f8e commit 75f0b1e

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
@@ -348,9 +348,8 @@ internal string GetStormLog()
348348
internal void IncrementOpCount()
349349
{
350350
Interlocked.Increment(ref operationCount);
351-
352351
#if NET6_0_OR_GREATER
353-
RedisMetrics.Instance.IncrementOpCount(Name);
352+
RedisMetrics.Instance.IncrementOperationCount(Name);
354353
#endif
355354
}
356355

@@ -1406,12 +1405,22 @@ private void LogNonPreferred(CommandFlags flags, bool isReplica)
14061405
if (isReplica)
14071406
{
14081407
if (Message.GetPrimaryReplicaFlags(flags) == CommandFlags.PreferMaster)
1408+
{
14091409
Interlocked.Increment(ref nonPreferredEndpointCount);
1410+
#if NET6_0_OR_GREATER
1411+
RedisMetrics.Instance.IncrementNonPreferredEndpointCount(Name);
1412+
#endif
1413+
}
14101414
}
14111415
else
14121416
{
14131417
if (Message.GetPrimaryReplicaFlags(flags) == CommandFlags.PreferReplica)
1418+
{
14141419
Interlocked.Increment(ref nonPreferredEndpointCount);
1420+
#if NET6_0_OR_GREATER
1421+
RedisMetrics.Instance.IncrementNonPreferredEndpointCount(Name);
1422+
#endif
1423+
}
14151424
}
14161425
}
14171426
}

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)