diff options
author | John Cai <jcai@gitlab.com> | 2019-12-11 18:56:05 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-12-11 18:56:05 +0300 |
commit | b7f5ff41e0904a7cf3ded4fecc031bf2a1e4aafe (patch) | |
tree | 7db4bceb754baaca760ef5ddb207d90754554c47 | |
parent | 938493edda6e4d1b9a8a5122251aea744623cfe8 (diff) |
Add feature flag to turn on hooks to go through RPCs
To have the gitaly-hooks binary start hitting internal Gitaly RPCs, we
want to ramp this traffic up through a feature flag. To do this, we need
to define the feature flag and pass it on through environment variables
to the gitaly-hooks binary
-rw-r--r-- | internal/metadata/featureflag/feature_flags.go | 7 | ||||
-rw-r--r-- | internal/service/smarthttp/receive_pack.go | 5 | ||||
-rw-r--r-- | internal/service/ssh/receive_pack.go | 4 |
3 files changed, 16 insertions, 0 deletions
diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index 7620a3e3f..f220bd5ac 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -12,4 +12,11 @@ const ( FilterShasWithSignaturesGo = "filter_shas_with_signatures_go" // LinguistFileCountStats will invoke an additional git-linguist command to get the number of files per language LinguistFileCountStats = "linguist_file_count_stats" + // HooksRPC will invoke update, pre receive, and post receive hooks by using RPCs + HooksRPC = "hooks_rpc" +) + +const ( + // HooksRPCEnvVar is the name of the environment variable we use to pass the feature flag down into gitaly-hooks + HooksRPCEnvVar = "GITALY_HOOK_RPCS_ENABLED" ) diff --git a/internal/service/smarthttp/receive_pack.go b/internal/service/smarthttp/receive_pack.go index e4b4e0bd8..ed11ce77f 100644 --- a/internal/service/smarthttp/receive_pack.go +++ b/internal/service/smarthttp/receive_pack.go @@ -1,11 +1,15 @@ package smarthttp import ( + "fmt" + "strconv" + grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" "google.golang.org/grpc/codes" @@ -47,6 +51,7 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac env = git.AddGitProtocolEnv(ctx, req, env) env = append(env, command.GitEnv...) + env = append(env, fmt.Sprintf("%s=%s", featureflag.HooksRPCEnvVar, strconv.FormatBool(featureflag.IsEnabled(ctx, featureflag.HooksRPC)))) globalOpts := git.ReceivePackConfig() for _, o := range req.GitConfigOptions { diff --git a/internal/service/ssh/receive_pack.go b/internal/service/ssh/receive_pack.go index 89d743d3e..33b4fa7ae 100644 --- a/internal/service/ssh/receive_pack.go +++ b/internal/service/ssh/receive_pack.go @@ -2,6 +2,9 @@ package ssh import ( "fmt" + "strconv" + + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" log "github.com/sirupsen/logrus" @@ -59,6 +62,7 @@ func sshReceivePack(stream gitalypb.SSHService_SSHReceivePackServer, req *gitaly env = git.AddGitProtocolEnv(ctx, req, env) env = append(env, command.GitEnv...) + env = append(env, fmt.Sprintf("%s=%s", featureflag.HooksRPCEnvVar, strconv.FormatBool(featureflag.IsEnabled(ctx, featureflag.HooksRPC)))) globalOpts := git.ReceivePackConfig() for _, o := range req.GitConfigOptions { |