@@ -15,6 +15,7 @@ import (
15
15
"github.com/google/uuid"
16
16
"github.com/tidwall/gjson"
17
17
18
+ "github.com/rudderlabs/rudder-go-kit/stats"
18
19
"github.com/rudderlabs/rudder-server/jobsdb"
19
20
"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager"
20
21
"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/common"
@@ -88,13 +89,13 @@ func getFirstAttemptAtFromErrorResponse(msg stdjson.RawMessage) time.Time {
88
89
return res
89
90
}
90
91
91
- func (brt * Handle ) prepareJobStatusList (importingList []* jobsdb.JobT , defaultStatus jobsdb.JobStatusT ) ([]* jobsdb.JobStatusT , []* jobsdb.JobT ) {
92
+ func (brt * Handle ) prepareJobStatusList (importingList []* jobsdb.JobT , defaultStatus jobsdb.JobStatusT , sourceID , destinationID string ) ([]* jobsdb.JobStatusT , []* jobsdb.JobT , map [ int64 ]jobsdb. ConnectionDetails ) {
92
93
var abortedJobsList []* jobsdb.JobT
93
94
var statusList []* jobsdb.JobStatusT
94
95
if defaultStatus .ErrorResponse == nil {
95
96
defaultStatus .ErrorResponse = routerutils .EmptyPayload
96
97
}
97
-
98
+ jobIdConnectionDetailsMap := make ( map [ int64 ]jobsdb. ConnectionDetails )
98
99
for _ , job := range importingList {
99
100
resp := enhanceResponseWithFirstAttemptedAt (job .LastJobStatus .ErrorResponse , defaultStatus .ErrorResponse )
100
101
status := jobsdb.JobStatusT {
@@ -109,6 +110,10 @@ func (brt *Handle) prepareJobStatusList(importingList []*jobsdb.JobT, defaultSta
109
110
JobParameters : job .Parameters ,
110
111
WorkspaceId : job .WorkspaceId ,
111
112
}
113
+ jobIdConnectionDetailsMap [job .JobID ] = jobsdb.ConnectionDetails {
114
+ SourceID : sourceID ,
115
+ DestinationID : destinationID ,
116
+ }
112
117
113
118
if defaultStatus .JobState == jobsdb .Failed .State {
114
119
if brt .retryLimitReached (& status ) {
@@ -118,7 +123,7 @@ func (brt *Handle) prepareJobStatusList(importingList []*jobsdb.JobT, defaultSta
118
123
}
119
124
statusList = append (statusList , & status )
120
125
}
121
- return statusList , abortedJobsList
126
+ return statusList , abortedJobsList , jobIdConnectionDetailsMap
122
127
}
123
128
124
129
func (brt * Handle ) getParamertsFromJobs (jobs []* jobsdb.JobT ) map [int64 ]stdjson.RawMessage {
@@ -129,25 +134,28 @@ func (brt *Handle) getParamertsFromJobs(jobs []*jobsdb.JobT) map[int64]stdjson.R
129
134
return parametersMap
130
135
}
131
136
132
- func (brt * Handle ) updatePollStatusToDB (ctx context.Context , destinationID string ,
133
- importingJob * jobsdb.JobT , pollResp common.PollStatusResponse ,
137
+ func (brt * Handle ) updatePollStatusToDB (
138
+ ctx context.Context ,
139
+ destinationID string ,
140
+ sourceID string ,
141
+ importingJob * jobsdb.JobT ,
142
+ pollResp common.PollStatusResponse ,
134
143
) ([]* jobsdb.JobStatusT , error ) {
135
144
var statusList []* jobsdb.JobStatusT
145
+ jobIDConnectionDetailsMap := make (map [int64 ]jobsdb.ConnectionDetails )
136
146
list , err := brt .getImportingJobs (ctx , destinationID , brt .maxEventsInABatch )
137
147
if err != nil {
138
148
return statusList , err
139
149
}
140
150
importingList := list .Jobs
141
151
if pollResp .StatusCode == http .StatusOK && pollResp .Complete {
142
152
if ! pollResp .HasFailed && ! pollResp .HasWarning {
143
- statusList , _ = brt .prepareJobStatusList (importingList , jobsdb.JobStatusT {JobState : jobsdb .Succeeded .State })
153
+ statusList , _ , jobIDConnectionDetailsMap = brt .prepareJobStatusList (importingList , jobsdb.JobStatusT {JobState : jobsdb .Succeeded .State }, sourceID , destinationID )
144
154
if err := brt .updateJobStatuses (ctx , destinationID , importingList , importingList , statusList ); err != nil {
145
155
brt .logger .Errorf ("[Batch Router] Failed to update job status for Dest Type %v with error %v" , brt .destType , err )
146
156
return statusList , err
147
157
}
148
158
brt .asyncSuccessfulJobCount .Count (len (statusList ))
149
- brt .updateProcessedEventsMetrics (statusList )
150
- return statusList , nil
151
159
} else {
152
160
getUploadStatsInput := common.GetUploadStatsInput {
153
161
FailedJobURLs : pollResp .FailedJobURLs ,
@@ -171,6 +179,10 @@ func (brt *Handle) updatePollStatusToDB(ctx context.Context, destinationID strin
171
179
successfulJobIDs := append (uploadStatsResp .Metadata .SucceededKeys , uploadStatsResp .Metadata .WarningKeys ... )
172
180
for _ , job := range importingList {
173
181
jobID := job .JobID
182
+ jobIDConnectionDetailsMap [jobID ] = jobsdb.ConnectionDetails {
183
+ SourceID : sourceID ,
184
+ DestinationID : destinationID ,
185
+ }
174
186
var status * jobsdb.JobStatusT
175
187
if slices .Contains (successfulJobIDs , jobID ) {
176
188
warningRespString := uploadStatsResp .Metadata .WarningReasons [jobID ]
@@ -226,26 +238,24 @@ func (brt *Handle) updatePollStatusToDB(ctx context.Context, destinationID strin
226
238
brt .logger .Errorf ("[Batch Router] Failed to update job status for Dest Type %v with error %v" , brt .destType , err )
227
239
return statusList , err
228
240
}
229
- brt .updateProcessedEventsMetrics (statusList )
230
241
}
231
242
} else if pollResp .StatusCode == http .StatusBadRequest {
232
- statusList , _ : = brt .prepareJobStatusList (importingList , jobsdb.JobStatusT {JobState : jobsdb .Aborted .State , ErrorResponse : misc .UpdateJSONWithNewKeyVal (routerutils .EmptyPayload , "error" , "poll failed with status code 400" )})
243
+ statusList , _ , jobIDConnectionDetailsMap = brt .prepareJobStatusList (importingList , jobsdb.JobStatusT {JobState : jobsdb .Aborted .State , ErrorResponse : misc .UpdateJSONWithNewKeyVal (routerutils .EmptyPayload , "error" , "poll failed with status code 400" )}, sourceID , destinationID )
233
244
if err := brt .updateJobStatuses (ctx , destinationID , importingList , importingList , statusList ); err != nil {
234
245
brt .logger .Errorf ("[Batch Router] Failed to update job status for Dest Type %v with error %v" , brt .destType , err )
235
246
return statusList , err
236
247
}
237
248
brt .asyncAbortedJobCount .Count (len (statusList ))
238
- brt .updateProcessedEventsMetrics (statusList )
239
249
} else {
240
- statusList , abortedJobsList := brt .prepareJobStatusList (importingList , jobsdb.JobStatusT {JobState : jobsdb .Failed .State , ErrorResponse : misc .UpdateJSONWithNewKeyVal (routerutils .EmptyPayload , "error" , pollResp .Error )})
250
+ var abortedJobsList []* jobsdb.JobT
251
+ statusList , abortedJobsList , jobIDConnectionDetailsMap = brt .prepareJobStatusList (importingList , jobsdb.JobStatusT {JobState : jobsdb .Failed .State , ErrorResponse : misc .UpdateJSONWithNewKeyVal (routerutils .EmptyPayload , "error" , pollResp .Error )}, sourceID , destinationID )
241
252
if err := brt .updateJobStatuses (ctx , destinationID , importingList , abortedJobsList , statusList ); err != nil {
242
253
brt .logger .Errorf ("[Batch Router] Failed to update job status for Dest Type %v with error %v" , brt .destType , err )
243
254
return statusList , err
244
255
}
245
256
brt .asyncFailedJobCount .Count (len (statusList ))
246
- brt .updateProcessedEventsMetrics (statusList )
247
257
}
248
-
258
+ routerutils . UpdateProcessedEventsMetrics ( stats . Default , module , brt . destType , statusList , jobIDConnectionDetailsMap )
249
259
return statusList , nil
250
260
}
251
261
@@ -280,7 +290,7 @@ func (brt *Handle) pollAsyncStatus(ctx context.Context) {
280
290
if pollResp .InProgress {
281
291
continue
282
292
}
283
- statusList , err := brt .updatePollStatusToDB (ctx , destinationID , importingJob , pollResp )
293
+ statusList , err := brt .updatePollStatusToDB (ctx , destinationID , sourceID , importingJob , pollResp )
284
294
if err == nil {
285
295
brt .asyncDestinationStruct [destinationID ].UploadInProgress = false
286
296
brt .recordAsyncDestinationDeliveryStatus (sourceID , destinationID , statusList )
@@ -576,8 +586,13 @@ func (brt *Handle) setMultipleJobStatus(asyncOutput common.AsyncUploadOutput, at
576
586
workspaceID := brt .GetWorkspaceIDForDestID (asyncOutput .DestinationID )
577
587
var completedJobsList []* jobsdb.JobT
578
588
var statusList []* jobsdb.JobStatusT
589
+ jobIDConnectionDetailsMap := make (map [int64 ]jobsdb.ConnectionDetails )
579
590
if len (asyncOutput .ImportingJobIDs ) > 0 {
580
591
for _ , jobId := range asyncOutput .ImportingJobIDs {
592
+ jobIDConnectionDetailsMap [jobId ] = jobsdb.ConnectionDetails {
593
+ DestinationID : asyncOutput .DestinationID ,
594
+ SourceID : gjson .GetBytes (originalJobParameters [jobId ], "source_id" ).String (),
595
+ }
581
596
status := jobsdb.JobStatusT {
582
597
JobID : jobId ,
583
598
JobState : jobsdb .Importing .State ,
@@ -595,6 +610,10 @@ func (brt *Handle) setMultipleJobStatus(asyncOutput common.AsyncUploadOutput, at
595
610
}
596
611
if len (asyncOutput .SucceededJobIDs ) > 0 {
597
612
for _ , jobId := range asyncOutput .SucceededJobIDs {
613
+ jobIDConnectionDetailsMap [jobId ] = jobsdb.ConnectionDetails {
614
+ DestinationID : asyncOutput .DestinationID ,
615
+ SourceID : gjson .GetBytes (originalJobParameters [jobId ], "source_id" ).String (),
616
+ }
598
617
status := jobsdb.JobStatusT {
599
618
JobID : jobId ,
600
619
JobState : jobsdb .Succeeded .State ,
@@ -613,6 +632,10 @@ func (brt *Handle) setMultipleJobStatus(asyncOutput common.AsyncUploadOutput, at
613
632
}
614
633
if len (asyncOutput .FailedJobIDs ) > 0 {
615
634
for _ , jobId := range asyncOutput .FailedJobIDs {
635
+ jobIDConnectionDetailsMap [jobId ] = jobsdb.ConnectionDetails {
636
+ DestinationID : asyncOutput .DestinationID ,
637
+ SourceID : gjson .GetBytes (originalJobParameters [jobId ], "source_id" ).String (),
638
+ }
616
639
resp := misc .UpdateJSONWithNewKeyVal (routerutils .EmptyPayload , "error" , asyncOutput .FailedReason )
617
640
status := jobsdb.JobStatusT {
618
641
JobID : jobId ,
@@ -641,6 +664,10 @@ func (brt *Handle) setMultipleJobStatus(asyncOutput common.AsyncUploadOutput, at
641
664
}
642
665
if len (asyncOutput .AbortJobIDs ) > 0 {
643
666
for _ , jobId := range asyncOutput .AbortJobIDs {
667
+ jobIDConnectionDetailsMap [jobId ] = jobsdb.ConnectionDetails {
668
+ DestinationID : asyncOutput .DestinationID ,
669
+ SourceID : gjson .GetBytes (originalJobParameters [jobId ], "source_id" ).String (),
670
+ }
644
671
status := jobsdb.JobStatusT {
645
672
JobID : jobId ,
646
673
JobState : jobsdb .Aborted .State ,
@@ -696,14 +723,13 @@ func (brt *Handle) setMultipleJobStatus(asyncOutput common.AsyncUploadOutput, at
696
723
if err != nil {
697
724
panic (err )
698
725
}
699
- brt . updateProcessedEventsMetrics ( statusList )
726
+ routerutils . UpdateProcessedEventsMetrics ( stats . Default , module , brt . destType , statusList , jobIDConnectionDetailsMap )
700
727
rmetrics .DecreasePendingEvents (
701
728
"batch_rt" ,
702
729
workspaceID ,
703
730
brt .destType ,
704
731
float64 (len (completedJobsList )),
705
732
)
706
-
707
733
if attempted {
708
734
var sourceID string
709
735
if len (statusList ) > 0 {
0 commit comments