Skip to content

Commit

Permalink
Simplify the duplicate check to be based on GUID providers are alread…
Browse files Browse the repository at this point in the history
…y changing.
  • Loading branch information
NickCraver committed Oct 12, 2015
1 parent b7e472e commit 4416813
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
2 changes: 0 additions & 2 deletions StackExchange.Exceptional.MySQL/MySQLErrorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ And DeletionDate Is Null
And ApplicationName = @ApplicationName
And DeletionDate Is Null
And CreationDate >= @minDate limit 1 ", queryParams).First();
error.IsOriginalError = false;
return;
}
}
Expand Down Expand Up @@ -235,7 +234,6 @@ Insert Into Exceptions (GUID, ApplicationName, MachineName, CreationDate, Type,
error.ErrorHash,
error.DuplicateCount
});
error.IsOriginalError = true;
}
}

Expand Down
7 changes: 7 additions & 0 deletions StackExchange.Exceptional.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GUID/@EntryIndexedValue">GUID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HTTP/@EntryIndexedValue">HTTP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=JSON/@EntryIndexedValue">JSON</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQL/@EntryIndexedValue">SQL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSL/@EntryIndexedValue">SSL</s:String></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion StackExchange.Exceptional/Email/ErrorEmailer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void SendMail(Error error)
{
if (!Enabled) return;
// The following prevents errors that have already been stored from being emailed a second time.
if (PreventDuplicates && !error.IsOriginalError) return;
if (PreventDuplicates && error.IsDuplicate) return;
try
{

Expand Down
6 changes: 2 additions & 4 deletions StackExchange.Exceptional/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public Error(Exception e, HttpContext context, string applicationName = null)
Detail = e.ToString();
CreationDate = DateTime.UtcNow;
DuplicateCount = 1;
IsOriginalError = true; //Default to true, but it should always be set by the store.

var httpException = e as HttpException;
if (httpException != null)
Expand Down Expand Up @@ -334,11 +333,10 @@ private bool IsBuiltInException(Exception e)
public int? DuplicateCount { get; set; }

/// <summary>
/// This flag is to indicate that there were no matches of this error in the store nor in the queue. This is slightly different than checking for DuplicateCount > 1
/// because DuplicateCount can be incremented even before the error is committed to the store.
/// This flag is to indicate that there were no matches of this error in when added to the queue or store.
/// </summary>
[ScriptIgnore]
public bool IsOriginalError { get; set; }
public bool IsDuplicate { get; set; }

/// <summary>
/// Gets the SQL command text assocaited with this error
Expand Down
5 changes: 5 additions & 0 deletions StackExchange.Exceptional/ErrorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ public void Log(Error error)
{
if (error == null) throw new ArgumentNullException(nameof(error));

// Track the GUID we made vs. what the store returns. If it's different, it's a dupe.
var originalGuid = error.GUID;
// if we're in a retry state, log directly to the queue
if (_isInRetry)
{
QueueError(error);
if (originalGuid != error.GUID) error.IsDuplicate = true;
ErrorEmailer.SendMail(error);
return;
}
Expand All @@ -230,6 +233,7 @@ public void Log(Error error)
{
LogError(error);
}
if (originalGuid != error.GUID) error.IsDuplicate = true;
ErrorEmailer.SendMail(error);
}
catch (Exception ex)
Expand Down Expand Up @@ -396,6 +400,7 @@ public void QueueError(Error e)
// try and rollup in the queue, to save space
foreach (var err in WriteQueue.Where(err => e.ErrorHash == err.ErrorHash))
{
e.GUID = err.GUID;
err.DuplicateCount++;
return;
}
Expand Down
2 changes: 0 additions & 2 deletions StackExchange.Exceptional/Stores/JSONErrorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ protected override void LogError(Error error)
// just update the existing file after incrementing its "duplicate count"
original.DuplicateCount = original.DuplicateCount.GetValueOrDefault(0) + error.DuplicateCount;
error.GUID = original.GUID;
error.IsOriginalError = false;

FileInfo f;
if (!TryGetErrorFile(original.GUID, out f))
Expand All @@ -167,7 +166,6 @@ protected override void LogError(Error error)

// we added a new file, so clean up old smack over our max errors limit
RemoveOldErrors();
error.IsOriginalError = true;
}
}

Expand Down
2 changes: 0 additions & 2 deletions StackExchange.Exceptional/Stores/MemoryErrorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ protected override void LogError(Error error)
{
dupe.DuplicateCount += error.DuplicateCount;
error.GUID = dupe.GUID;
error.IsOriginalError = false;
return;
}
}
Expand All @@ -132,7 +131,6 @@ protected override void LogError(Error error)
}

_errors.Add(error);
error.IsOriginalError = true;
}
}

Expand Down
2 changes: 0 additions & 2 deletions StackExchange.Exceptional/Stores/SQLErrorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ And DeletionDate Is Null
if (count > 0)
{
error.GUID = queryParams.Get<Guid>("@newGUID");
error.IsOriginalError = false;
return;
}
}
Expand Down Expand Up @@ -223,7 +222,6 @@ Insert Into Exceptions (GUID, ApplicationName, MachineName, CreationDate, Type,
error.ErrorHash,
error.DuplicateCount
});
error.IsOriginalError = true;
}
}

Expand Down

0 comments on commit 4416813

Please sign in to comment.