Skip to content

Commit f47c5b3

Browse files
committed
Improve logging statements.
1 parent 063759d commit f47c5b3

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

internal/verifier/check.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,30 @@ func FetchFailedAndIncompleteTasks(ctx context.Context, coll *mongo.Collection,
370370

371371
func (verifier *Verifier) Work(ctx context.Context, workerNum int, wg *sync.WaitGroup) {
372372
defer wg.Done()
373-
verifier.logger.Debug().Msgf("[Worker %d] Started", workerNum)
373+
374+
verifier.logger.Debug().
375+
Int("workerNum", workerNum).
376+
Msg("Worker started.")
377+
378+
defer verifier.logger.Debug().
379+
Int("workerNum", workerNum).
380+
Msg("Worker finished.")
381+
374382
for {
375383
select {
376384
case <-ctx.Done():
377385
return
378386
default:
379387
task, err := verifier.FindNextVerifyTaskAndUpdate()
380388
if errors.Is(err, mongo.ErrNoDocuments) {
381-
verifier.logger.Debug().Msgf("[Worker %d] No tasks found, sleeping...", workerNum)
382-
time.Sleep(verifier.workerSleepDelayMillis * time.Millisecond)
389+
duration := verifier.workerSleepDelayMillis * time.Millisecond
390+
391+
verifier.logger.Debug().
392+
Int("workerNum", workerNum).
393+
Stringer("duration", duration).
394+
Msg("No tasks found. Sleeping.")
395+
396+
time.Sleep(duration)
383397
continue
384398
} else if err != nil {
385399
panic(err)

internal/verifier/migration_verifier.go

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,22 @@ func (verifier *Verifier) compareOneDocument(srcClientDoc, dstClientDoc bson.Raw
540540
}
541541

542542
func (verifier *Verifier) ProcessVerifyTask(workerNum int, task *VerificationTask) {
543-
verifier.logger.Debug().Msgf("[Worker %d] Processing verify task", workerNum)
543+
start := time.Now()
544+
545+
verifier.logger.Debug().
546+
Int("workerNum", workerNum).
547+
Interface("task", task.PrimaryKey).
548+
Msg("Processing document comparison task.")
549+
550+
defer func() {
551+
elapsed := time.Now().Sub(start)
552+
553+
verifier.logger.Debug().
554+
Int("workerNum", workerNum).
555+
Interface("task", task.PrimaryKey).
556+
Stringer("timeElapsed", elapsed).
557+
Msg("Finished document comparison task.")
558+
}()
544559

545560
problems, docsCount, bytesCount, err := verifier.FetchAndCompareDocuments(
546561
context.Background(),
@@ -549,7 +564,11 @@ func (verifier *Verifier) ProcessVerifyTask(workerNum int, task *VerificationTas
549564

550565
if err != nil {
551566
task.Status = verificationTaskFailed
552-
verifier.logger.Error().Msgf("[Worker %d] Error comparing docs: %+v", workerNum, err)
567+
verifier.logger.Error().
568+
Err(err).
569+
Int("workerNum", workerNum).
570+
Interface("task", task.PrimaryKey).
571+
Msg("Failed to fetch and compare documents for document comparison task.")
553572
} else {
554573
task.SourceDocumentCount = docsCount
555574
task.SourceByteCount = bytesCount
@@ -560,10 +579,15 @@ func (verifier *Verifier) ProcessVerifyTask(workerNum int, task *VerificationTas
560579
task.Status = verificationTaskFailed
561580
// We know we won't change lastGeneration while verification tasks are running, so no mutex needed here.
562581
if verifier.lastGeneration {
563-
verifier.logger.Error().Msgf("[Worker %d] Verification Task %+v failed critical section and is a true error",
564-
workerNum, task.PrimaryKey)
582+
verifier.logger.Error().
583+
Int("workerNum", workerNum).
584+
Interface("task", task.PrimaryKey).
585+
Msg("Document comparison task failed critical section and is a true error.")
565586
} else {
566-
verifier.logger.Debug().Msgf("[Worker %d] Verification Task %+v failed, may pass next generation", workerNum, task.PrimaryKey)
587+
verifier.logger.Debug().
588+
Int("workerNum", workerNum).
589+
Interface("task", task.PrimaryKey).
590+
Msg("Document comparison task failed, but it may pass in the next generation.")
567591

568592
var mismatches []VerificationResult
569593
var missingIds []interface{}
@@ -594,15 +618,24 @@ func (verifier *Verifier) ProcessVerifyTask(workerNum int, task *VerificationTas
594618
// mismatched & missing docs.
595619
err := verifier.InsertFailedCompareRecheckDocs(task.QueryFilter.Namespace, idsToRecheck, dataSizes)
596620
if err != nil {
597-
verifier.logger.Error().Msgf("[Worker %d] Error inserting document mismatch into Recheck queue: %+v", workerNum, err)
621+
verifier.logger.Error().
622+
Err(err).
623+
Int("workerNum", workerNum).
624+
Interface("task", task.PrimaryKey).
625+
Int("rechecksCount", len(idsToRecheck)).
626+
Msg("Failed to enqueue rechecks after document mismatches.")
598627
}
599628
}
600629
}
601630
}
602631

603632
err = verifier.UpdateVerificationTask(task)
604633
if err != nil {
605-
verifier.logger.Error().Msgf("Failed updating verification status: %v", err)
634+
verifier.logger.Error().
635+
Err(err).
636+
Int("workerNum", workerNum).
637+
Interface("task", task.PrimaryKey).
638+
Msg("Failed to update task status.")
606639
}
607640
}
608641

0 commit comments

Comments
 (0)