From 34fa7eb3499c0f85c8610f89c120c1b3c56c1462 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 13 Oct 2021 15:22:11 +0100 Subject: Improve logging for non-git commands Several of our commands only touch the internal API, and go nowhere near Gitaly. Improve logging for each of these in a single MR. In general, we want to be able to tell what happened in the execution of each command, and to track failures down to a specific line of code. Changelog: added --- internal/command/shared/customaction/customaction.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'internal/command/shared') diff --git a/internal/command/shared/customaction/customaction.go b/internal/command/shared/customaction/customaction.go index 73d2ce4..191ec42 100644 --- a/internal/command/shared/customaction/customaction.go +++ b/internal/command/shared/customaction/customaction.go @@ -4,19 +4,17 @@ import ( "bytes" "context" "errors" - - "gitlab.com/gitlab-org/gitlab-shell/client" - "io" "net/http" + "gitlab.com/gitlab-org/labkit/log" + + "gitlab.com/gitlab-org/gitlab-shell/client" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/internal/config" "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet" "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier" "gitlab.com/gitlab-org/gitlab-shell/internal/pktline" - - "gitlab.com/gitlab-org/labkit/log" ) type Request struct { @@ -59,12 +57,12 @@ func (c *Command) processApiEndpoints(ctx context.Context, response *accessverif request.Data.UserId = response.Who for _, endpoint := range data.ApiEndpoints { - fields := log.Fields{ + ctxlog := log.WithContextFields(ctx, log.Fields{ "primary_repo": data.PrimaryRepo, "endpoint": endpoint, - } + }) - log.WithContextFields(ctx, fields).Info("Performing custom action") + ctxlog.Info("customaction: processApiEndpoints: Performing custom action") response, err := c.performRequest(ctx, client, endpoint, request) if err != nil { @@ -90,6 +88,10 @@ func (c *Command) processApiEndpoints(ctx context.Context, response *accessverif } else { output = c.readFromStdinNoEOF() } + ctxlog.WithFields(log.Fields{ + "eof_sent": c.EOFSent, + "stdin_bytes": len(output), + }).Debug("customaction: processApiEndpoints: stdin buffered") request.Output = output } -- cgit v1.2.1