diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-09-02 11:04:26 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-09-02 15:59:56 +0300 |
commit | dd99d044b73f648bd0d3f8f242c855996e0e9b52 (patch) | |
tree | 7a27a92050fc61dc76b2e5b56b900e16795a99e1 | |
parent | 41789fd1cb1387d188bf9765d50340bf3667d754 (diff) |
Update logging to leverage fields better
The logging used to contain details in text, while logrus shines most as
a structured logger as our ELK stack can parse structured logs, and
index data for faster retrieval.
Also, there was one log line that dumped a full struct with all the
fields. This is been replaced with just the details needed.
Fixes https://gitlab.com/gitlab-org/gitaly/issues/1883
-rw-r--r-- | changelogs/unreleased/zj-logging-praefect-fix.yml | 5 | ||||
-rw-r--r-- | internal/praefect/replicator.go | 24 |
2 files changed, 20 insertions, 9 deletions
diff --git a/changelogs/unreleased/zj-logging-praefect-fix.yml b/changelogs/unreleased/zj-logging-praefect-fix.yml new file mode 100644 index 000000000..a8bb01f84 --- /dev/null +++ b/changelogs/unreleased/zj-logging-praefect-fix.yml @@ -0,0 +1,5 @@ +--- +title: Update logging statements to leverage structured logging better +merge_request: +author: +type: other diff --git a/internal/praefect/replicator.go b/internal/praefect/replicator.go index f54a6f457..8e41c3879 100644 --- a/internal/praefect/replicator.go +++ b/internal/praefect/replicator.go @@ -124,18 +124,17 @@ func (r ReplMgr) ScheduleReplication(ctx context.Context, repo models.Repository return err } - r.log.Infof( - "replication manager for targetNode %q created replication job with ID %d", - r.targetNode, - id, - ) + r.log.WithFields(logrus.Fields{ + logWithReplJobID: id, + "relative_path": repo.RelativePath, + }).Info("replication job created") return nil } const ( jobFetchInterval = 10 * time.Millisecond - logWithReplJobID = "replication-job-ID" + logWithReplJobID = "replication_job_id" ) // ProcessBacklog will process queued jobs. It will block while processing jobs. @@ -153,7 +152,10 @@ func (r ReplMgr) ProcessBacklog(ctx context.Context) error { } if len(jobs) == 0 { - r.log.Tracef("no jobs for %d, checking again in %s", node.ID, jobFetchInterval) + r.log.WithFields(logrus.Fields{ + "node_id": node.ID, + "recheck_interval": jobFetchInterval, + }).Trace("no jobs") select { // TODO: exponential backoff when no queries are returned @@ -166,8 +168,12 @@ func (r ReplMgr) ProcessBacklog(ctx context.Context) error { } for _, job := range jobs { - r.log.WithField(logWithReplJobID, job.ID). - Infof("processing replication job %#v", job) + r.log.WithFields(logrus.Fields{ + logWithReplJobID: job.ID, + "from_storage": job.SourceNode.Storage, + "to_storage": job.TargetNode.Storage, + "relative_path": job.Repository.RelativePath, + }).Info("processing replication job") if err := r.datastore.UpdateReplJob(job.ID, JobStateInProgress); err != nil { return err |