Skip to content

Commit b8b5527

Browse files
authored
feat: update error table with new columns (#4356)
1 parent 26d4729 commit b8b5527

File tree

4 files changed

+161
-42
lines changed

4 files changed

+161
-42
lines changed

enterprise/reporting/error_reporting.go

+35-15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ var ErrorDetailReportsColumns = []string{
4848
"count",
4949
"status_code",
5050
"event_type",
51+
"event_name",
52+
"sample_event",
53+
"sample_response",
5154
"error_code",
5255
"error_message",
5356
}
@@ -188,7 +191,6 @@ func (edr *ErrorDetailReporter) Report(ctx context.Context, metrics []*types.PUR
188191
"sourceId": metric.ConnectionDetails.SourceID,
189192
"destinationId": metric.ConnectionDetails.DestinationID,
190193
}).Count(int(metric.StatusDetail.Count))
191-
192194
_, err = stmt.Exec(
193195
workspaceID,
194196
edr.namespace,
@@ -203,6 +205,9 @@ func (edr *ErrorDetailReporter) Report(ctx context.Context, metrics []*types.PUR
203205
metric.StatusDetail.Count,
204206
metric.StatusDetail.StatusCode,
205207
metric.StatusDetail.EventType,
208+
metric.StatusDetail.EventName,
209+
string(metric.StatusDetail.SampleEvent),
210+
metric.StatusDetail.SampleResponse,
206211
errDets.ErrorCode,
207212
errDets.ErrorMessage,
208213
)
@@ -398,6 +403,9 @@ func (edr *ErrorDetailReporter) getReports(ctx context.Context, currentMs int64,
398403
"count",
399404
"status_code",
400405
"event_type",
406+
"event_name",
407+
"sample_event",
408+
"sample_response",
401409
"error_code",
402410
"error_message",
403411
"dest_type",
@@ -427,6 +435,9 @@ func (edr *ErrorDetailReporter) getReports(ctx context.Context, currentMs int64,
427435
"count",
428436
"status_code",
429437
"event_type",
438+
"event_name"
439+
"sample_event",
440+
"sample_response",
430441
"error_code",
431442
"error_message",
432443
"dest_type",
@@ -448,6 +459,9 @@ func (edr *ErrorDetailReporter) getReports(ctx context.Context, currentMs int64,
448459
&dbEdMetric.Count,
449460
&dbEdMetric.EDErrorDetails.StatusCode,
450461
&dbEdMetric.EDErrorDetails.EventType,
462+
&dbEdMetric.EDErrorDetails.EventName,
463+
&dbEdMetric.EDErrorDetails.SampleEvent,
464+
&dbEdMetric.EDErrorDetails.SampleResponse,
451465
&dbEdMetric.EDErrorDetails.ErrorCode,
452466
&dbEdMetric.EDErrorDetails.ErrorMessage,
453467
&dbEdMetric.EDConnectionDetails.DestType,
@@ -505,16 +519,19 @@ func (edr *ErrorDetailReporter) aggregate(reports []*types.EDReportsDB) []*types
505519
ReportedAt: firstReport.ReportedAt * 60 * 1000,
506520
},
507521
}
508-
var errs []types.EDErrorDetails
509-
510-
reportsCountMap := lo.CountValuesBy(reports, func(rep *types.EDReportsDB) types.EDErrorDetails {
511-
return types.EDErrorDetails{
522+
messageMap := make(map[string]int)
523+
reportsCountMap := make(map[types.EDErrorDetails]int64)
524+
for index, rep := range reports {
525+
messageMap[rep.EDErrorDetails.ErrorMessage] = index
526+
errDet := types.EDErrorDetails{
512527
StatusCode: rep.StatusCode,
513528
ErrorCode: rep.ErrorCode,
514529
ErrorMessage: rep.ErrorMessage,
515530
EventType: rep.EventType,
531+
EventName: rep.EventName,
516532
}
517-
})
533+
reportsCountMap[errDet] += rep.Count
534+
}
518535

519536
reportGrpKeys := lo.Keys(reportsCountMap)
520537
sort.SliceStable(reportGrpKeys, func(i, j int) bool {
@@ -525,15 +542,18 @@ func (edr *ErrorDetailReporter) aggregate(reports []*types.EDReportsDB) []*types
525542
irep.ErrorMessage < jrep.ErrorMessage ||
526543
irep.EventType < jrep.EventType)
527544
})
528-
for _, rep := range reportGrpKeys {
529-
errs = append(errs, types.EDErrorDetails{
530-
StatusCode: rep.StatusCode,
531-
ErrorCode: rep.ErrorCode,
532-
ErrorMessage: rep.ErrorMessage,
533-
EventType: rep.EventType,
534-
Count: reportsCountMap[rep],
535-
})
536-
}
545+
errs := lo.MapToSlice(reportsCountMap, func(rep types.EDErrorDetails, count int64) types.EDErrorDetails {
546+
return types.EDErrorDetails{
547+
StatusCode: rep.StatusCode,
548+
ErrorCode: rep.ErrorCode,
549+
ErrorMessage: rep.ErrorMessage,
550+
EventType: rep.EventType,
551+
EventName: rep.EventName,
552+
SampleEvent: reports[messageMap[rep.ErrorMessage]].SampleEvent,
553+
SampleResponse: reports[messageMap[rep.ErrorMessage]].SampleResponse,
554+
Count: count,
555+
}
556+
})
537557
edrSchema.Errors = errs
538558
edrortingMetrics = append(edrortingMetrics, &edrSchema)
539559
}

enterprise/reporting/reporting_test.go

+110-25
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ func TestAggregationLogic(t *testing.T) {
455455
ReportMetadata: types.ReportMetadata{
456456
ReportedAt: 124335445,
457457
},
458+
Count: 5,
458459
},
459460
{
460461
PU: "dest_transformer",
@@ -479,6 +480,7 @@ func TestAggregationLogic(t *testing.T) {
479480
ReportMetadata: types.ReportMetadata{
480481
ReportedAt: 124335445,
481482
},
483+
Count: 10,
482484
},
483485
{
484486
PU: "dest_transformer",
@@ -503,6 +505,7 @@ func TestAggregationLogic(t *testing.T) {
503505
ReportMetadata: types.ReportMetadata{
504506
ReportedAt: 124335445,
505507
},
508+
Count: 10,
506509
},
507510
{
508511
PU: "dest_transformer",
@@ -527,6 +530,7 @@ func TestAggregationLogic(t *testing.T) {
527530
ReportMetadata: types.ReportMetadata{
528531
ReportedAt: 124335446,
529532
},
533+
Count: 1,
530534
},
531535
// error occurred at router level(assume this is batching enabled)
532536
{
@@ -544,14 +548,74 @@ func TestAggregationLogic(t *testing.T) {
544548
DestType: "DES_1",
545549
},
546550
EDErrorDetails: types.EDErrorDetails{
547-
StatusCode: 500,
548-
ErrorCode: "",
549-
ErrorMessage: "Cannot read type property of undefined", // some error during batching
550-
EventType: "identify",
551+
StatusCode: 500,
552+
ErrorCode: "",
553+
ErrorMessage: "Cannot read type property of undefined", // some error during batching
554+
EventType: "track",
555+
EventName: "Page View",
556+
SampleResponse: "some response",
557+
SampleEvent: "some sample event",
551558
},
552559
ReportMetadata: types.ReportMetadata{
553560
ReportedAt: 124335446,
554561
},
562+
Count: 6,
563+
},
564+
{
565+
PU: "router",
566+
EDInstanceDetails: types.EDInstanceDetails{
567+
WorkspaceID: "wsp1",
568+
InstanceID: "instance-1",
569+
Namespace: "nmspc",
570+
},
571+
EDConnectionDetails: types.EDConnectionDetails{
572+
SourceID: "src-1",
573+
SourceDefinitionId: "src-def-1",
574+
DestinationDefinitionId: "des-def-1",
575+
DestinationID: "des-1",
576+
DestType: "DES_1",
577+
},
578+
EDErrorDetails: types.EDErrorDetails{
579+
StatusCode: 500,
580+
ErrorCode: "",
581+
ErrorMessage: "Cannot read type property of undefined", // some error during batching
582+
EventType: "track",
583+
EventName: "Page View",
584+
SampleResponse: "different response",
585+
SampleEvent: "different sample event",
586+
},
587+
ReportMetadata: types.ReportMetadata{
588+
ReportedAt: 124335446,
589+
},
590+
Count: 10,
591+
},
592+
{
593+
PU: "router",
594+
EDInstanceDetails: types.EDInstanceDetails{
595+
WorkspaceID: "wsp1",
596+
InstanceID: "instance-1",
597+
Namespace: "nmspc",
598+
},
599+
EDConnectionDetails: types.EDConnectionDetails{
600+
SourceID: "src-1",
601+
SourceDefinitionId: "src-def-1",
602+
DestinationDefinitionId: "des-def-1",
603+
DestinationID: "des-1",
604+
DestType: "DES_1",
605+
},
606+
EDErrorDetails: types.EDErrorDetails{
607+
StatusCode: 401,
608+
ErrorCode: "",
609+
ErrorMessage: "Request had invalid authentication credentials Expected OAuth access token login cookie or other valid authentication credential See ",
610+
EventType: "track",
611+
EventName: "Page View",
612+
SampleResponse: "some different response",
613+
SampleEvent: "some different sample event",
614+
},
615+
ReportMetadata: types.ReportMetadata{
616+
ReportedAt: 124335446,
617+
},
618+
Count: 10,
555619
},
556620
}
557621
configSubscriber := newConfigSubscriber(logger.NOP)
@@ -578,18 +642,24 @@ func TestAggregationLogic(t *testing.T) {
578642
},
579643
Errors: []types.EDErrorDetails{
580644
{
581-
StatusCode: dbErrs[0].StatusCode,
582-
ErrorCode: dbErrs[0].ErrorCode,
583-
ErrorMessage: dbErrs[0].ErrorMessage,
584-
EventType: dbErrs[0].EventType,
585-
Count: 1,
645+
StatusCode: dbErrs[0].StatusCode,
646+
ErrorCode: dbErrs[0].ErrorCode,
647+
ErrorMessage: dbErrs[0].ErrorMessage,
648+
EventType: dbErrs[0].EventType,
649+
EventName: dbErrs[0].EventName,
650+
Count: 5,
651+
SampleResponse: dbErrs[0].SampleResponse,
652+
SampleEvent: dbErrs[0].SampleEvent,
586653
},
587654
{
588-
StatusCode: dbErrs[1].StatusCode,
589-
ErrorCode: dbErrs[1].ErrorCode,
590-
ErrorMessage: dbErrs[1].ErrorMessage,
591-
EventType: dbErrs[1].EventType,
592-
Count: 2,
655+
StatusCode: dbErrs[1].StatusCode,
656+
ErrorCode: dbErrs[1].ErrorCode,
657+
ErrorMessage: dbErrs[1].ErrorMessage,
658+
EventType: dbErrs[1].EventType,
659+
EventName: dbErrs[1].EventName,
660+
Count: 20,
661+
SampleResponse: dbErrs[1].SampleResponse,
662+
SampleEvent: dbErrs[1].SampleEvent,
593663
},
594664
},
595665
},
@@ -612,11 +682,14 @@ func TestAggregationLogic(t *testing.T) {
612682
},
613683
Errors: []types.EDErrorDetails{
614684
{
615-
StatusCode: dbErrs[3].StatusCode,
616-
ErrorCode: dbErrs[3].ErrorCode,
617-
ErrorMessage: dbErrs[3].ErrorMessage,
618-
EventType: dbErrs[3].EventType,
619-
Count: 1,
685+
StatusCode: dbErrs[3].StatusCode,
686+
ErrorCode: dbErrs[3].ErrorCode,
687+
ErrorMessage: dbErrs[3].ErrorMessage,
688+
EventType: dbErrs[3].EventType,
689+
EventName: dbErrs[3].EventName,
690+
Count: 1,
691+
SampleResponse: dbErrs[3].SampleResponse,
692+
SampleEvent: dbErrs[3].SampleEvent,
620693
},
621694
},
622695
},
@@ -639,15 +712,27 @@ func TestAggregationLogic(t *testing.T) {
639712
},
640713
Errors: []types.EDErrorDetails{
641714
{
642-
StatusCode: dbErrs[4].StatusCode,
643-
ErrorCode: dbErrs[4].ErrorCode,
644-
ErrorMessage: dbErrs[4].ErrorMessage,
645-
EventType: dbErrs[4].EventType,
646-
Count: 1,
715+
StatusCode: dbErrs[4].StatusCode,
716+
ErrorCode: dbErrs[4].ErrorCode,
717+
ErrorMessage: dbErrs[4].ErrorMessage,
718+
EventType: dbErrs[4].EventType,
719+
EventName: dbErrs[4].EventName,
720+
Count: 16,
721+
SampleResponse: dbErrs[5].SampleResponse,
722+
SampleEvent: dbErrs[5].SampleEvent,
723+
},
724+
{
725+
StatusCode: dbErrs[6].StatusCode,
726+
ErrorCode: dbErrs[6].ErrorCode,
727+
ErrorMessage: dbErrs[6].ErrorMessage,
728+
EventType: dbErrs[6].EventType,
729+
EventName: dbErrs[6].EventName,
730+
Count: 10,
731+
SampleResponse: dbErrs[6].SampleResponse,
732+
SampleEvent: dbErrs[6].SampleEvent,
647733
},
648734
},
649735
},
650736
}
651-
652737
require.Equal(t, reportResults, reportingMetrics)
653738
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
--- Error Detail Reports
3+
---
4+
ALTER TABLE
5+
error_detail_reports
6+
ADD
7+
COLUMN IF NOT EXISTS event_name TEXT DEFAULT '',
8+
ADD
9+
COLUMN IF NOT EXISTS sample_event JSONB NOT NULL DEFAULT '{}'::jsonb,
10+
ADD
11+
COLUMN IF NOT EXISTS sample_response TEXT DEFAULT '';

utils/types/reporting_types.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ type EDErrorDetails struct {
113113
ErrorCode string `json:"errorCode"`
114114
ErrorMessage string `json:"errorMessage"`
115115
// TODO: need to check with team if this makes sense ?
116-
EventType string `json:"-"`
117-
Count int `json:"count"`
116+
EventType string `json:"eventType"`
117+
EventName string `json:"eventName"`
118+
Count int64 `json:"count"`
119+
SampleResponse string `json:"sampleResponse"`
120+
SampleEvent string `json:"sampleEvent"`
118121
}
119122

120123
type EDReportsDB struct {

0 commit comments

Comments
 (0)