summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2021-10-21 03:50:11 +0000
committerPatrick Bajao <ebajao@gitlab.com>2021-10-21 03:50:11 +0000
commit5cccb38df60b9ecef744e8bf1cbdff68066e9d5e (patch)
treea1b8f405c57df8ede0b85c14fc71eef4f79ede06
parent9dcfcd3a1d3001fb87b6e807f7fed31a05f509b2 (diff)
parent1dede51df96e9524b5519e115db5a0e1c719d03b (diff)
downloadgitlab-shell-5cccb38df60b9ecef744e8bf1cbdff68066e9d5e.tar.gz
Merge branch 'id-logging-for-handler' into 'main'
Add logging to handler/exec.go and config/config.go See merge request gitlab-org/gitlab-shell!539
-rw-r--r--internal/config/config.go4
-rw-r--r--internal/handler/exec.go15
-rw-r--r--internal/handler/exec_test.go2
3 files changed, 16 insertions, 5 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 5185736..cbaf6d1 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -14,6 +14,8 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/client"
"gitlab.com/gitlab-org/gitlab-shell/internal/metrics"
+
+ "gitlab.com/gitlab-org/labkit/log"
)
const (
@@ -93,6 +95,8 @@ func (sc *ServerConfig) GracePeriod() time.Duration {
func (c *Config) ApplyGlobalState() {
if c.SslCertDir != "" {
+ log.WithFields(log.Fields{"ssl_cert_dir": c.SslCertDir}).Info("SSL_CERT_DIR is configured")
+
os.Setenv("SSL_CERT_DIR", c.SslCertDir)
}
}
diff --git a/internal/handler/exec.go b/internal/handler/exec.go
index 172736d..8f4a7df 100644
--- a/internal/handler/exec.go
+++ b/internal/handler/exec.go
@@ -45,17 +45,24 @@ type GitalyCommand struct {
func (gc *GitalyCommand) RunGitalyCommand(ctx context.Context, handler GitalyHandlerFunc) error {
conn, err := getConn(ctx, gc)
if err != nil {
+ log.ContextLogger(ctx).WithError(fmt.Errorf("RunGitalyCommand: %v", err)).Error("Failed to get connection to execute Git command")
+
return err
}
defer conn.Close()
childCtx := withOutgoingMetadata(ctx, gc.Features)
- _, err = handler(childCtx, conn)
+ ctxlog := log.ContextLogger(childCtx)
+ exitStatus, err := handler(childCtx, conn)
+
+ if err != nil {
+ if grpcstatus.Convert(err).Code() == grpccodes.Unavailable {
+ ctxlog.WithError(fmt.Errorf("RunGitalyCommand: %v", err)).Error("Gitaly is unavailable")
- if err != nil && grpcstatus.Convert(err).Code() == grpccodes.Unavailable {
- log.WithError(err).Error("Gitaly is unavailable")
+ return fmt.Errorf("The git server, Gitaly, is not available at this time. Please contact your administrator.")
+ }
- return fmt.Errorf("Git service is temporarily unavailable")
+ ctxlog.WithError(err).WithFields(log.Fields{"exit_status": exitStatus}).Error("Failed to execute Git command")
}
return err
diff --git a/internal/handler/exec_test.go b/internal/handler/exec_test.go
index 1d714ef..ba6bd6a 100644
--- a/internal/handler/exec_test.go
+++ b/internal/handler/exec_test.go
@@ -56,7 +56,7 @@ func TestUnavailableGitalyErr(t *testing.T) {
expectedErr := grpcstatus.Error(grpccodes.Unavailable, "error")
err := cmd.RunGitalyCommand(context.Background(), makeHandler(t, expectedErr))
- require.EqualError(t, err, "Git service is temporarily unavailable")
+ require.EqualError(t, err, "The git server, Gitaly, is not available at this time. Please contact your administrator.")
}
func TestRunGitalyCommandMetadata(t *testing.T) {