diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-02-03 11:43:15 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-02-04 15:37:12 +0300 |
commit | 351494103c7cdfa16d87cfe7e9781254acb98e0a (patch) | |
tree | 631c0cafc3b18ab0bc5bfc447ea84f43e2b2f3a4 | |
parent | 02e1b93383796ecd7d83973c379b5f985ab7a175 (diff) |
hook: Log when transactions are about to be stopped
It's currently hard to observe why a transaction was stopped as there is
not a single log entry which gets generated when we are stopping. This
commit fixes this shortcoming by adding log messages to all three cases
where we gracefully stop transactions.
-rw-r--r-- | internal/gitaly/hook/postreceive.go | 3 | ||||
-rw-r--r-- | internal/gitaly/hook/prereceive.go | 3 | ||||
-rw-r--r-- | internal/gitaly/hook/update.go | 3 |
3 files changed, 9 insertions, 0 deletions
diff --git a/internal/gitaly/hook/postreceive.go b/internal/gitaly/hook/postreceive.go index f42e1db91..0372dc625 100644 --- a/internal/gitaly/hook/postreceive.go +++ b/internal/gitaly/hook/postreceive.go @@ -10,6 +10,7 @@ import ( "math" "strings" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -128,6 +129,8 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. if isPrimary(payload) { if err := m.postReceiveHook(ctx, payload, repo, pushOptions, env, changes, stdout, stderr); err != nil { + ctxlogrus.Extract(ctx).WithError(err).Warn("stopping transaction because post-receive hook failed") + // If the post-receive hook declines the push, then we need to stop any // secondaries voting on the transaction. m.stopTransaction(ctx, payload) diff --git a/internal/gitaly/hook/prereceive.go b/internal/gitaly/hook/prereceive.go index 8e5ce6f9c..2c3cfb4eb 100644 --- a/internal/gitaly/hook/prereceive.go +++ b/internal/gitaly/hook/prereceive.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -67,6 +68,8 @@ func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.R // Only the primary should execute hooks and increment reference counters. if isPrimary(payload) { if err := m.preReceiveHook(ctx, payload, repo, pushOptions, env, changes, stdout, stderr); err != nil { + ctxlogrus.Extract(ctx).WithError(err).Warn("stopping transaction because pre-receive hook failed") + // If the pre-receive hook declines the push, then we need to stop any // secondaries voting on the transaction. m.stopTransaction(ctx, payload) diff --git a/internal/gitaly/hook/update.go b/internal/gitaly/hook/update.go index 500573505..daa21ecf1 100644 --- a/internal/gitaly/hook/update.go +++ b/internal/gitaly/hook/update.go @@ -5,6 +5,7 @@ import ( "fmt" "io" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -18,6 +19,8 @@ func (m *GitLabHookManager) UpdateHook(ctx context.Context, repo *gitalypb.Repos if isPrimary(payload) { if err := m.updateHook(ctx, payload, repo, ref, oldValue, newValue, env, stdout, stderr); err != nil { + ctxlogrus.Extract(ctx).WithError(err).Warn("stopping transaction because update hook failed") + // If the update hook declines the push, then we need // to stop any secondaries voting on the transaction. m.stopTransaction(ctx, payload) |