From 76f0c309def30859efdcdc51d6fa8deb4fccb0a5 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 9 Jun 2019 19:56:03 +0200 Subject: [PATCH] Log workerID --- internal/app/dispatcher.go | 1 + internal/app/diun.go | 14 +++++++------- internal/app/worker.go | 8 ++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/app/dispatcher.go b/internal/app/dispatcher.go index 710f1276..d9378caa 100644 --- a/internal/app/dispatcher.go +++ b/internal/app/dispatcher.go @@ -20,6 +20,7 @@ func (di *Diun) StartDispatcher(workerCount int) Collector { for i < workerCount { i++ worker := worker{ + id: i, diun: di, workerPool: workerChannel, jobChannel: make(chan Job), diff --git a/internal/app/diun.go b/internal/app/diun.go index 17c7f55a..a4fb06e9 100644 --- a/internal/app/diun.go +++ b/internal/app/diun.go @@ -122,7 +122,7 @@ func (di *Diun) Run() { wg.Wait() } -func (di *Diun) analyze(job Job) error { +func (di *Diun) analyze(job Job, workerID int) error { defer job.Wg.Done() image, err := registry.ParseImage(job.ImageStr) if err != nil { @@ -130,10 +130,10 @@ func (di *Diun) analyze(job Job) error { } if !utl.IsIncluded(image.Tag, job.Item.IncludeTags) { - log.Warn().Str("image", image.String()).Msg("Tag not included") + log.Warn().Str("image", image.String()).Int("worker_id", workerID).Msg("Tag not included") return nil } else if utl.IsExcluded(image.Tag, job.Item.ExcludeTags) { - log.Warn().Str("image", image.String()).Msg("Tag excluded") + log.Warn().Str("image", image.String()).Int("worker_id", workerID).Msg("Tag excluded") return nil } @@ -152,19 +152,19 @@ func (di *Diun) analyze(job Job) error { status := model.ImageStatusUnchange if dbManifest.Name == "" { status = model.ImageStatusNew - log.Info().Str("image", image.String()).Msg("New image found") + log.Info().Str("image", image.String()).Int("worker_id", workerID).Msg("New image found") } else if !liveManifest.Created.Equal(*dbManifest.Created) { status = model.ImageStatusUpdate - log.Info().Str("image", image.String()).Msg("Image update found") + log.Info().Str("image", image.String()).Int("worker_id", workerID).Msg("Image update found") } else { - log.Debug().Str("image", image.String()).Msg("No changes") + log.Debug().Str("image", image.String()).Int("worker_id", workerID).Msg("No changes") return nil } if err := di.db.PutManifest(image, liveManifest); err != nil { return err } - log.Debug().Str("image", image.String()).Msg("Manifest saved to database") + log.Debug().Str("image", image.String()).Int("worker_id", workerID).Msg("Manifest saved to database") di.notif.Send(model.NotifEntry{ Status: status, diff --git a/internal/app/worker.go b/internal/app/worker.go index cf21fc25..54f3b8ed 100644 --- a/internal/app/worker.go +++ b/internal/app/worker.go @@ -16,6 +16,7 @@ type Job struct { } type worker struct { + id int diun *Diun workerPool chan chan Job jobChannel chan Job @@ -29,8 +30,11 @@ func (w *worker) Start() { w.workerPool <- w.jobChannel select { case job := <-w.jobChannel: - if err := w.diun.analyze(job); err != nil { - log.Error().Err(err).Str("image", job.ImageStr).Msg("Error analyzing image") + if err := w.diun.analyze(job, w.id); err != nil { + log.Error().Err(err). + Str("image", job.ImageStr). + Int("worker_id", w.id). + Msg("Error analyzing image") } case <-w.end: return