Skip to content

Commit 1378224

Browse files
committed
We only store 25 error reports now for each incident, but keep track of volume to be able to determine impact of each incident.
1 parent cf4fede commit 1378224

File tree

33 files changed

+379
-259
lines changed

33 files changed

+379
-259
lines changed

src/Server/Coderr.Server.Api.Client/ServerApiClient.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ public void Open(Uri uri, string apiKey, string sharedSecret)
106106
private async Task<TResult> DeserializeResponse<TResult>(HttpContent content)
107107
{
108108
var jsonStr = await content.ReadAsStringAsync();
109-
var responseObj = JsonConvert.DeserializeObject(jsonStr, typeof(TResult), _jsonSerializerSettings);
110-
return (TResult)responseObj;
109+
try
110+
{
111+
var responseObj = JsonConvert.DeserializeObject(jsonStr, typeof(TResult), _jsonSerializerSettings);
112+
return (TResult) responseObj;
113+
}
114+
catch (Exception ex)
115+
{
116+
throw new InvalidOperationException("Failed to deserialize " + jsonStr, ex);
117+
}
111118
}
112119

113120
private async Task<HttpResponseMessage> RequestAsync(HttpMethod httpMethod, string cqsType, object cqsObject)

src/Server/Coderr.Server.App/Core/Reports/Jobs/DeleteOldReports.cs

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

src/Server/Coderr.Server.App/Modules/MonthlyStats/CollectStatsJob.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ private async Task<AppResult[]> GetReportCounts(DateTime lastMonth)
174174
using (var cmd = _unitOfWork.CreateDbCommand())
175175
{
176176
cmd.CommandText = @"SELECT ApplicationId, count(*)
177-
FROM ErrorReports
178-
where CreatedAtUtc >= @fromDate AND CreatedAtUtc < @toDate
177+
FROM IncidentReports
178+
JOIN Incidents ON (Incidents.Id = IncidentId)
179+
where IncidentReports.ReceivedAtUtc >= @fromDate
180+
AND IncidentReports.ReceivedAtUtc < @toDate
179181
group by ApplicationId";
180182
cmd.AddParameter("fromDate", lastMonth);
181183
cmd.AddParameter("toDate", lastMonth.AddMonths(1));

src/Server/Coderr.Server.Domain/Core/ErrorReports/IReportsRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IReportsRepository
1515
/// <param name="errorId">Customer generated id (from the client library).</param>
1616
/// <returns>report if found; otherwise <c>null</c>.</returns>
1717
/// <exception cref="ArgumentNullException">errorId</exception>
18-
Task<ErrorReportEntity> FindByErrorIdAsync(string errorId);
18+
Task<ReportMapping> FindByErrorIdAsync(string errorId);
1919

2020

2121
/// <summary>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
3+
namespace Coderr.Server.Domain.Core.ErrorReports
4+
{
5+
/// <summary>
6+
/// Maps a received report to an incident
7+
/// </summary>
8+
/// <remarks>
9+
/// <para>
10+
/// Since we do not store complete reports for everything any more. Allows us to still keep
11+
/// track of client side generated error ids and which incident they belong to.
12+
/// </para>
13+
/// </remarks>
14+
public class ReportMapping
15+
{
16+
public int Id { get; set; }
17+
18+
/// <summary>
19+
/// Incident that the report belongs to.
20+
/// </summary>
21+
public int IncidentId { get; set; }
22+
23+
/// <summary>
24+
/// Client report id
25+
/// </summary>
26+
public string ErrorId { get; set; }
27+
28+
/// <summary>
29+
/// Only when fetching items
30+
/// </summary>
31+
public int ApplicationId { get; set; }
32+
33+
/// <summary>
34+
/// When the report was generated in the client
35+
/// </summary>
36+
public DateTime ReceivedAtUtc { get; set; }
37+
}
38+
}

src/Server/Coderr.Server.ReportAnalyzer/Feedback/Handlers/StoreFeedbackFromNewReports.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
2626
{
2727
try
2828
{
29-
_logger.Debug("storing feedback for report " + e.Report.ReportId);
3029
var userInfo = Enumerable.FirstOrDefault(e.Report.ContextCollections, x => x.Name == "UserSuppliedInformation");
3130
if (userInfo == null)
3231
return;
3332

3433
userInfo.Properties.TryGetValue("Description", out var description);
3534
userInfo.Properties.TryGetValue("Email", out var email);
35+
_logger.Debug($"storing feedback for report {e.Report.ReportId}: {email} {description}");
3636
var cmd = new SubmitFeedback(e.Report.ReportId, e.Report.RemoteAddress ?? "")
3737
{
3838
Feedback = description,

src/Server/Coderr.Server.ReportAnalyzer/IAnalyticsRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Coderr.Server.Domain.Core.ErrorReports;
34
using Coderr.Server.ReportAnalyzer.Incidents;
45

@@ -71,5 +72,6 @@ public interface IAnalyticsRepository
7172
int GetMonthReportCount();
7273

7374
void AddMissedReport(DateTime date);
75+
Task StoreReportStats(ReportMapping mapping);
7476
}
7577
}

src/Server/Coderr.Server.ReportAnalyzer/Inbound/Handlers/Reports/ReportAnalyzer.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ public async Task Analyze(IMessageContext context, ErrorReportEntity report)
102102
}
103103
else
104104
{
105-
if (incident.ReportCount > 1000)
105+
await _repository.StoreReportStats(new ReportMapping()
106106
{
107-
_logger.Debug("Report count is more than 10000. Ignoring report for incident " + incident.Id);
108-
return;
109-
}
107+
IncidentId = incident.Id,
108+
ErrorId = report.ClientReportId,
109+
ReceivedAtUtc = report.CreatedAtUtc
110+
});
110111

111112
if (incident.IsIgnored)
112113
{
@@ -139,6 +140,11 @@ public async Task Analyze(IMessageContext context, ErrorReportEntity report)
139140

140141
incident.AddReport(report);
141142
_repository.UpdateIncident(incident);
143+
if (incident.ReportCount > 25)
144+
{
145+
_logger.Debug("Report count is more than 25. Storing only report stats for incident " + incident.Id);
146+
return;
147+
}
142148
}
143149

144150
if (!string.IsNullOrWhiteSpace(report.EnvironmentName))

src/Server/Coderr.Server.SqlServer/Coderr.Server.SqlServer.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
<ItemGroup>
2626
<EmbeddedResource Include="Schema\*.sql" />
2727
</ItemGroup>
28+
29+
<ItemGroup>
30+
<None Remove="Schema\Coderr.v19.sql" />
31+
</ItemGroup>
2832
</Project>

src/Server/Coderr.Server.SqlServer/Core/Applications/Queries/GetApplicationOverviewHandler.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task<GetApplicationOverviewResult> HandleAsync(IMessageContext cont
4848
new { version = query.Version });
4949
filter1 = @"JOIN IncidentVersions On (Incidents.Id = IncidentVersions.IncidentId)
5050
WHERE IncidentVersions.VersionId = @versionId AND ";
51-
filter2 = @"JOIN IncidentVersions On (ErrorReports.IncidentId = IncidentVersions.IncidentId)
51+
filter2 = @"JOIN IncidentVersions On (IncidentReports.IncidentId = IncidentVersions.IncidentId)
5252
WHERE IncidentVersions.VersionId = @versionId AND ";
5353
cmd.AddParameter("versionId", id);
5454
}
@@ -63,18 +63,19 @@ from Incidents
6363
AND Incidents.CreatedAtUtc <= GetUtcDate()
6464
{0}
6565
group by cast(Incidents.CreatedAtUtc as date);
66-
select cast(ErrorReports.CreatedAtUtc as date), count(Id)
67-
from ErrorReports
68-
{3} ErrorReports.CreatedAtUtc >= @minDate
69-
AND ErrorReports.CreatedAtUtc <= GetUtcDate()
66+
select cast(IncidentReports.CreatedAtUtc as date), count(Id)
67+
from IncidentReports
68+
join Incidents isa ON (isa.Id = IncidentReports.IncidentId)
69+
{3} IncidentReports.ReceivedAtUtc >= @minDate
70+
AND IncidentReports.ReceivedAtUtc <= GetUtcDate()
7071
{1}
71-
group by cast(ErrorReports.CreatedAtUtc as date);";
72+
group by cast(IncidentReports.ReceivedAtUtc as date);";
7273

7374
if (query.ApplicationId > 0)
7475
{
7576
cmd.CommandText = string.Format(sql,
7677
" AND Incidents.ApplicationId = @appId",
77-
" AND ErrorReports.ApplicationId = @appId",
78+
" AND isa.ApplicationId = @appId",
7879
filter1, filter2);
7980
cmd.AddParameter("appId", query.ApplicationId);
8081
}
@@ -127,11 +128,11 @@ JOIN IncidentVersions ON (Incidents.Id = IncidentVersions.IncidentId)
127128
AND Incidents.State <> {(int)IncidentState.Ignored}
128129
AND Incidents.State <> {(int)IncidentState.Closed};
129130
130-
SELECT count(id) from ErrorReports
131-
JOIN IncidentVersions ON (ErrorReports.IncidentId = IncidentVersions.IncidentId)
131+
SELECT count(id) from IncidentReports
132+
JOIN IncidentVersions ON (IncidentReports.IncidentId = IncidentVersions.IncidentId)
132133
WHERE IncidentVersions.VersionId = @versionId
133-
AND CreatedAtUtc >= @minDate
134-
AND CreatedAtUtc <= GetUtcDate()
134+
AND ReceivedAtUtc >= @minDate
135+
AND ReceivedAtUtc <= GetUtcDate()
135136
AND ApplicationId = @appId;
136137
137138
SELECT count(distinct emailaddress) from IncidentFeedback
@@ -162,9 +163,11 @@ AND Description is not null
162163
AND Incidents.State <> {(int)IncidentState.Ignored}
163164
AND Incidents.State <> {(int)IncidentState.Closed};
164165
165-
select count(id) from ErrorReports
166-
where CreatedAtUtc >= @minDate
167-
AND CreatedAtUtc <= GetUtcDate()
166+
SELECT count(id)
167+
FROM IncidentReports
168+
JOIN Incidents ON (Incidents.Id = IncidentReports.IncidentId)
169+
WHERE ReceivedAtUtc >= @minDate
170+
AND ReceivedAtUtc <= GetUtcDate()
168171
AND ApplicationId = @appId;
169172
170173
select count(distinct emailaddress) from IncidentFeedback
@@ -236,7 +239,7 @@ private async Task<GetApplicationOverviewResult> GetTodaysOverviewAsync(GetAppli
236239
new { version = query.Version });
237240
filter1 = @"JOIN IncidentVersions On (Incidents.Id = IncidentVersions.IncidentId)
238241
WHERE IncidentVersions.VersionId = @versionId AND ";
239-
filter2 = @"JOIN IncidentVersions On (ErrorReports.IncidentId = IncidentVersions.IncidentId)
242+
filter2 = @"JOIN IncidentVersions On (IncidentReports.IncidentId = IncidentVersions.IncidentId)
240243
WHERE IncidentVersions.VersionId = @versionId AND ";
241244
cmd.AddParameter("versionId", id);
242245
}
@@ -252,12 +255,13 @@ from Incidents
252255
AND Incidents.CreatedAtUtc <= GetUtcDate()
253256
AND Incidents.ApplicationId = @appId
254257
group by DATEPART(HOUR, Incidents.CreatedAtUtc);
255-
select DATEPART(HOUR, ErrorReports.CreatedAtUtc), cast(count(Id) as int)
256-
from ErrorReports
257-
{1} ErrorReports.CreatedAtUtc >= @minDate
258-
AND ErrorReports.CreatedAtUtc <= GetUtcDate()
259-
AND ErrorReports.ApplicationId = @appId
260-
group by DATEPART(HOUR, ErrorReports.CreatedAtUtc);";
258+
select DATEPART(HOUR, IncidentReports.ReceivedAtUtc), cast(count(Id) as int)
259+
from IncidentReports
260+
JOIN Incidents ice ON (ice.Id = IncidentId)
261+
{1} IncidentReports.ReceivedAtUtc >= @minDate
262+
AND IncidentReports.ReceivedAtUtc <= GetUtcDate()
263+
AND ice.ApplicationId = @appId
264+
group by DATEPART(HOUR, IncidentReports.ReceivedAtUtc);";
261265

262266
cmd.CommandText = string.Format(sql, filter1, filter2);
263267
cmd.AddParameter("appId", query.ApplicationId);

0 commit comments

Comments
 (0)