summaryrefslogtreecommitdiff
path: root/internal/command/shared
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2021-10-13 15:22:11 +0100
committerNick Thomas <nick@gitlab.com>2021-10-13 15:28:31 +0100
commit34fa7eb3499c0f85c8610f89c120c1b3c56c1462 (patch)
treee721100bcd86f394c6f13df5015d78126d005785 /internal/command/shared
parentd868b40ae666a11749ee9ec652441221197a2670 (diff)
downloadgitlab-shell-499-log-non-git-commands.tar.gz
Improve logging for non-git commands499-log-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
Diffstat (limited to 'internal/command/shared')
-rw-r--r--internal/command/shared/customaction/customaction.go18
1 files changed, 10 insertions, 8 deletions
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
}