@@ -226,7 +226,7 @@ func (s *Syncer) SyncExternalService(
226226 minSyncInterval time.Duration ,
227227 progressRecorder progressRecorderFunc ,
228228) (err error ) {
229- logger := s .ObsvCtx .Logger .With (log .Int64 ("externalServiceID" , externalServiceID ))
229+ logger := s .ObsvCtx .Logger .Scoped ( "SyncExternalService" ). With (log .Int64 ("externalServiceID" , externalServiceID ))
230230 logger .Info ("syncing external service" )
231231
232232 // Ensure the job field is recorded when monitoring external API calls
@@ -365,6 +365,29 @@ func (s *Syncer) SyncExternalService(
365365 modified = modified || len (diff .Modified )+ len (diff .Added ) > 0
366366 }
367367
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+
368391 // We don't delete any repos of site-level external services if there were any
369392 // non-warning errors during a sync.
370393 //
@@ -380,13 +403,15 @@ func (s *Syncer) SyncExternalService(
380403 // repos (by removing ones if code-host permissions have changed).
381404 abortDeletion := false
382405 if errs != nil {
406+ logger .Error ("received errors during sync" , log .Error (errs ))
383407 var ref errors.MultiError
384408 if errors .As (errs , & ref ) {
385409 for _ , e := range ref .Errors () {
386410 if errors .IsWarning (e ) {
387411 baseError := errors .Unwrap (e )
388412 if ! errcode .IsForbidden (baseError ) && ! errcode .IsUnauthorized (baseError ) {
389413 abortDeletion = true
414+ logger .Info ("aborting deletion due to fatal error" , log .Error (e ))
390415 break
391416 }
392417 continue
@@ -395,6 +420,7 @@ func (s *Syncer) SyncExternalService(
395420 continue
396421 }
397422 abortDeletion = true
423+ logger .Info ("aborting deletion due to fatal error" , log .Error (e ))
398424 break
399425 }
400426 }
0 commit comments