@@ -226,7 +226,7 @@ func (s *Syncer) SyncExternalService(
226
226
minSyncInterval time.Duration ,
227
227
progressRecorder progressRecorderFunc ,
228
228
) (err error ) {
229
- logger := s .ObsvCtx .Logger .With (log .Int64 ("externalServiceID" , externalServiceID ))
229
+ logger := s .ObsvCtx .Logger .Scoped ( "SyncExternalService" ). With (log .Int64 ("externalServiceID" , externalServiceID ))
230
230
logger .Info ("syncing external service" )
231
231
232
232
// Ensure the job field is recorded when monitoring external API calls
@@ -365,6 +365,29 @@ func (s *Syncer) SyncExternalService(
365
365
modified = modified || len (diff .Modified )+ len (diff .Added ) > 0
366
366
}
367
367
368
+ // This information isn't necessarily an error in and of itself, but it's possible
369
+ // for the code host to misbehave in a way that returns a legitimate-looking response
370
+ // (e.g. a non-fatal HTTP status code, with a well-formed response body) that is
371
+ // nonetheless incorrect (e.g. temporarily returning empty set of repositories
372
+ // instead of an error).
373
+ //
374
+ // Because of this, we have to be able to log every response from the code host
375
+ // so that we can audit them later so that we can rule in/out the above scenario.
376
+ // So, we choose the WARN level instead of INFO so that this info is logged by default.
377
+ logger .Warn ("finished listing repositories from external service" ,
378
+ log .Object ("syncProgress" ,
379
+ log .Int32 ("synced" , syncProgress .Synced ),
380
+ log .Int32 ("errors" , syncProgress .Errors ),
381
+ log .Int32 ("added" , syncProgress .Added ),
382
+ log .Int32 ("removed" , syncProgress .Removed ),
383
+ log .Int32 ("modified" , syncProgress .Modified ),
384
+ log .Int32 ("unmodified" , syncProgress .Unmodified ),
385
+ ),
386
+ log .Int ("seen" , len (seen )),
387
+ log .Bool ("modified" , modified ),
388
+ log .Error (errs ),
389
+ )
390
+
368
391
// We don't delete any repos of site-level external services if there were any
369
392
// non-warning errors during a sync.
370
393
//
@@ -380,13 +403,15 @@ func (s *Syncer) SyncExternalService(
380
403
// repos (by removing ones if code-host permissions have changed).
381
404
abortDeletion := false
382
405
if errs != nil {
406
+ logger .Error ("received errors during sync" , log .Error (errs ))
383
407
var ref errors.MultiError
384
408
if errors .As (errs , & ref ) {
385
409
for _ , e := range ref .Errors () {
386
410
if errors .IsWarning (e ) {
387
411
baseError := errors .Unwrap (e )
388
412
if ! errcode .IsForbidden (baseError ) && ! errcode .IsUnauthorized (baseError ) {
389
413
abortDeletion = true
414
+ logger .Info ("aborting deletion due to fatal error" , log .Error (e ))
390
415
break
391
416
}
392
417
continue
@@ -395,6 +420,7 @@ func (s *Syncer) SyncExternalService(
395
420
continue
396
421
}
397
422
abortDeletion = true
423
+ logger .Info ("aborting deletion due to fatal error" , log .Error (e ))
398
424
break
399
425
}
400
426
}
0 commit comments