Skip to content

Commit fc9b3ab

Browse files
committed
Changed the duplicate checker to be a plugin!
1 parent f930245 commit fc9b3ab

14 files changed

+22
-65
lines changed

Source/Extras/Plugins/ErrorPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Exceptionless.Models;
55

66
namespace Exceptionless.Plugins {
7-
[Priority(40)]
7+
[Priority(30)]
88
public class ErrorPlugin : IEventPlugin {
99
private readonly IExceptionlessLog _log;
1010

Source/Samples/SampleConsole/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ private static void Main() {
4242
Console.CursorVisible = false;
4343
StartDisplayingLogMessages();
4444

45+
ExceptionlessClient.Default.Configuration.UseTraceLogEntriesPlugin();
46+
ExceptionlessClient.Default.Configuration.AddPlugin<SystemUptimePlugin>();
4547
ExceptionlessClient.Default.Configuration.UseFolderStorage("store");
4648
ExceptionlessClient.Default.Configuration.UseLogger(_log);
4749
//ExceptionlessClient.Default.Configuration.SubmissionBatchSize = 1;
@@ -62,8 +64,6 @@ private static void Main() {
6264
if (false)
6365
SampleApiUsages();
6466

65-
ExceptionlessClient.Default.Configuration.UseTraceLogEntriesPlugin();
66-
ExceptionlessClient.Default.Configuration.AddPlugin<SystemUptimePlugin>();
6767

6868
ExceptionlessClient.Default.Configuration.AddPlugin(ctx => ctx.Event.Data[RandomData.GetWord()] = RandomData.GetWord());
6969
ExceptionlessClient.Default.Configuration.AddPlugin(ctx => ctx.Event.Data[RandomData.GetWord()] = RandomData.GetWord());

Source/Shared/Dependency/DependencyResolver.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Exceptionless.Duplicates;
32
using Exceptionless.Logging;
43
using Exceptionless.Queue;
54
using Exceptionless.Serializer;
@@ -50,9 +49,6 @@ public static void RegisterDefaultServices(IDependencyResolver resolver) {
5049
var lastClientIdManager = new Lazy<ILastReferenceIdManager>(() => resolver.Resolve<DefaultLastReferenceIdManager>());
5150
resolver.Register(typeof(ILastReferenceIdManager), () => lastClientIdManager.Value);
5251

53-
var duplicateChecker = new Lazy<IDuplicateChecker>(() => resolver.Resolve<DefaultDuplicateChecker>());
54-
resolver.Register(typeof(IDuplicateChecker), () => duplicateChecker.Value);
55-
5652
var persistedClientData = new Lazy<PersistedDictionary>(() => new PersistedDictionary("client-data.json", resolver.Resolve<IObjectStorage>(), resolver.Resolve<IJsonSerializer>()));
5753
resolver.Register(typeof(PersistedDictionary), () => persistedClientData.Value);
5854
}

Source/Shared/Dependency/DependencyResolverExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Exceptionless.Duplicates;
32
using Exceptionless.Logging;
43
using Exceptionless.Queue;
54
using Exceptionless.Serializer;
@@ -82,9 +81,5 @@ public static IEnvironmentInfoCollector GetEnvironmentInfoCollector(this IDepend
8281
public static ILastReferenceIdManager GetLastReferenceIdManager(this IDependencyResolver resolver) {
8382
return resolver.Resolve<ILastReferenceIdManager>() ?? resolver.Resolve<DefaultLastReferenceIdManager>();
8483
}
85-
86-
public static IDuplicateChecker GetDuplicateChecker(this IDependencyResolver resolver) {
87-
return resolver.Resolve<IDuplicateChecker>() ?? resolver.Resolve<DefaultDuplicateChecker>();
88-
}
8984
}
9085
}

Source/Shared/Duplicates/IDuplicateChecker.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

Source/Shared/Duplicates/NoDuplicateChecker.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

Source/Shared/Exceptionless.Portable.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
<Compile Include="Dependency\DependencyResolverExtensions.cs" />
4949
<Compile Include="Dependency\IDependencyResolver.cs" />
5050
<Compile Include="Dependency\TinyIoC.cs" />
51-
<Compile Include="Duplicates\DefaultDuplicateChecker.cs" />
52-
<Compile Include="Duplicates\IDuplicateChecker.cs" />
53-
<Compile Include="Duplicates\NoDuplicateChecker.cs" />
51+
<Compile Include="Plugins\Default\DuplicateCheckerPlugin.cs" />
5452
<Compile Include="Plugins\ContextData.cs" />
5553
<Compile Include="Plugins\Default\ActionPlugin.cs" />
5654
<Compile Include="Plugins\Default\ConfigurationDefaultsPlugin.cs" />

Source/Shared/ExceptionlessClient.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
33
using Exceptionless.Dependency;
4-
using Exceptionless.Duplicates;
54
using Exceptionless.Plugins;
65
using Exceptionless.Logging;
76
using Exceptionless.Models;
@@ -15,7 +14,6 @@ public class ExceptionlessClient : IDisposable {
1514
private readonly Lazy<IEventQueue> _queue;
1615
private readonly Lazy<ISubmissionClient> _submissionClient;
1716
private readonly Lazy<ILastReferenceIdManager> _lastReferenceIdManager;
18-
private readonly Lazy<IDuplicateChecker> _duplicateChecker;
1917

2018
public ExceptionlessClient() : this(new ExceptionlessConfiguration(DependencyResolver.CreateDefault())) { }
2119

@@ -43,7 +41,6 @@ public ExceptionlessClient(ExceptionlessConfiguration configuration) {
4341

4442
_submissionClient = new Lazy<ISubmissionClient>(() => Configuration.Resolver.GetSubmissionClient());
4543
_lastReferenceIdManager = new Lazy<ILastReferenceIdManager>(() => Configuration.Resolver.GetLastReferenceIdManager());
46-
_duplicateChecker = new Lazy<IDuplicateChecker>(() => Configuration.Resolver.GetDuplicateChecker());
4744
}
4845

4946
public ExceptionlessConfiguration Configuration { get; private set; }
@@ -144,9 +141,6 @@ public void SubmitEvent(Event ev, ContextData pluginContextData = null) {
144141
if (context.Cancel)
145142
return;
146143

147-
if (_duplicateChecker.Value != null && _duplicateChecker.Value.IsDuplicate(ev))
148-
return;
149-
150144
// ensure all required data
151145
if (String.IsNullOrEmpty(ev.Type))
152146
ev.Type = Event.KnownTypes.Log;

Source/Shared/Plugins/Default/ActionPlugin.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Exceptionless.Dependency;
32
using Exceptionless.Logging;
43

54
namespace Exceptionless.Plugins.Default {
@@ -14,7 +13,7 @@ public void Run(EventPluginContext context) {
1413
try {
1514
_pluginAction(context);
1615
} catch (Exception ex) {
17-
context.Resolver.GetLog().FormattedError(typeof(ActionPlugin), ex, "An error occurred while running an custom plugin: {0}", ex.Message);
16+
context.Log.FormattedError(typeof(ActionPlugin), ex, "An error occurred while running an custom plugin: {0}", ex.Message);
1817
}
1918
}
2019
}

Source/Shared/Duplicates/DefaultDuplicateChecker.cs renamed to Source/Shared/Plugins/Default/DuplicateCheckerPlugin.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,28 @@
22
using System.Collections.Concurrent;
33
using System.Linq;
44
using Exceptionless.Logging;
5-
using Exceptionless.Models;
65
using Exceptionless.Models.Data;
76

8-
namespace Exceptionless.Duplicates {
9-
public class DefaultDuplicateChecker : IDuplicateChecker {
7+
namespace Exceptionless.Plugins.Default {
8+
[Priority(40)]
9+
public class DuplicateCheckerPlugin : IEventPlugin {
1010
private readonly ConcurrentQueue<Tuple<int, DateTime>> _recentlyProcessedErrors = new ConcurrentQueue<Tuple<int, DateTime>>();
11-
private readonly IExceptionlessLog _log;
1211

13-
public DefaultDuplicateChecker(IExceptionlessLog log) {
14-
_log = log;
15-
}
16-
17-
public bool IsDuplicate(Event ev) {
18-
if (!ev.IsError())
19-
return false;
12+
public void Run(EventPluginContext context) {
13+
if (!context.Event.IsError())
14+
return;
2015

21-
InnerError current = ev.GetError();
16+
InnerError current = context.Event.GetError();
2217
DateTime repeatWindow = DateTime.Now.AddSeconds(-2);
2318

2419
while (current != null) {
2520
int hashCode = current.GetHashCode();
2621

2722
// make sure that we don't process the same error multiple times within 2 seconds.
2823
if (_recentlyProcessedErrors.Any(s => s.Item1 == hashCode && s.Item2 >= repeatWindow)) {
29-
_log.FormattedInfo(typeof(ExceptionlessClient), "Ignoring duplicate error event: hash={0}", hashCode);
30-
return true;
24+
context.Log.FormattedInfo(typeof(ExceptionlessClient), "Ignoring duplicate error event: hash={0}", hashCode);
25+
context.Cancel = true;
26+
return;
3127
}
3228

3329
// add this exception to our list of recent errors that we have processed.
@@ -40,8 +36,6 @@ public bool IsDuplicate(Event ev) {
4036

4137
current = current.Inner;
4238
}
43-
44-
return false;
4539
}
4640
}
47-
}
41+
}

0 commit comments

Comments
 (0)