Skip to content

Commit 04db85b

Browse files
committed
Make sure we sum events that already have a count
1 parent ff79e37 commit 04db85b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Source/Shared/Plugins/Default/1010_DuplicateCheckerPlugin.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public DuplicateCheckerPlugin(TimeSpan? interval) {
2929

3030
public void Run(EventPluginContext context) {
3131
int hashCode = context.Event.GetHashCode();
32-
32+
int count = context.Event.Count ?? 1;
33+
3334
// Increment the occurrence count if the event is already queued for submission.
3435
var merged = _mergedEvents.FirstOrDefault(s => s.HashCode == hashCode);
3536
if (merged != null) {
36-
merged.IncrementCount();
37+
merged.IncrementCount(count);
3738
context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), String.Concat("Ignoring duplicate error event with hash:", hashCode));
3839
context.Cancel = true;
3940
return;
@@ -42,7 +43,7 @@ public void Run(EventPluginContext context) {
4243
DateTimeOffset repeatWindow = DateTimeOffset.UtcNow.Subtract(_interval);
4344
if (_processed.Any(s => s.Item1 == hashCode && s.Item2 >= repeatWindow)) {
4445
// This event is a duplicate for the first time, lets save it so we can delay it while keeping count
45-
_mergedEvents.Enqueue(new MergedEvent(hashCode, context));
46+
_mergedEvents.Enqueue(new MergedEvent(hashCode, context, count));
4647
context.Cancel = true;
4748
} else {
4849
_processed.Enqueue(Tuple.Create(hashCode, DateTimeOffset.UtcNow));
@@ -73,18 +74,19 @@ public void Dispose() {
7374
}
7475

7576
private class MergedEvent {
76-
private int _count = 1;
77+
private int _count;
7778
private readonly EventPluginContext _context;
7879

79-
public MergedEvent(int hashCode, EventPluginContext context) {
80+
public MergedEvent(int hashCode, EventPluginContext context, int count) {
8081
HashCode = hashCode;
8182
_context = context;
83+
_count = count;
8284
}
8385

8486
public int HashCode { get; private set; }
8587

86-
public void IncrementCount() {
87-
Interlocked.Increment(ref _count);
88+
public void IncrementCount(int value) {
89+
Interlocked.Add(ref _count, value);
8890
}
8991

9092
public void Enqueue() {

0 commit comments

Comments
 (0)