diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2019-03-26 21:13:47 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2019-03-26 21:13:47 +0300 |
commit | 342f96040a362cbb27dbfa992cf1a5867eebd3a4 (patch) | |
tree | b4c9ce05c92b6c3513fe6bf88d5acf875de53419 /doc/development/gitaly.md | |
parent | b0ed83e0e0fecb54e5cd2596649388df16bfc531 (diff) | |
parent | 1c2bfc99bad4b2b1579334b2e018bfec53b96025 (diff) |
Merge branch 'jc-add-docs-for-gitaly-feature-flags' into 'master'
Add development documentation for gitaly feature flags
See merge request gitlab-org/gitlab-ce!25624
Diffstat (limited to 'doc/development/gitaly.md')
-rw-r--r-- | doc/development/gitaly.md | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/doc/development/gitaly.md b/doc/development/gitaly.md index 1a4b1743a00..27b69ba8278 100644 --- a/doc/development/gitaly.md +++ b/doc/development/gitaly.md @@ -197,3 +197,82 @@ as a [CI environment variable](../ci/variables/README.md#variables). --- [Return to Development documentation](README.md) + +## Wrapping RPCs in Feature Flags + +Here are the steps to gate a new feature in Gitaly behind a feature flag. + +### Gitaly + +1. Create a package scoped flag name: + + ```go + var findAllTagsFeatureFlag = "go-find-all-tags" + ``` + +1. Create a switch in the code using the `featureflag` package: + + ```go + if featureflag.IsEnabled(ctx, findAllTagsFeatureFlag) { + // go implementation + } else { + // ruby implementation + } + ``` + +1. Create prometheus metrics: + + ```go + var findAllTagsRequests = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Name: "gitaly_find_all_tags_requests_total", + Help: "Counter of go vs ruby implementation of FindAllTags", + }, + []string{"implementation"}, + ) + ) + + func init() { + prometheus.Register(findAllTagsRequests) + } + + if featureflag.IsEnabled(ctx, findAllTagsFeatureFlag) { + findAllTagsRequests.WithLabelValues("go").Inc() + // go implementation + } else { + findAllTagsRequests.WithLabelValues("ruby").Inc() + // ruby impelmentation + } + ``` + +1. Set headers in tests: + + ```go + import ( + "google.golang.org/grpc/metadata" + + "gitlab.com/gitlab-org/gitaly/internal/featureflag" + ) + + //... + + md := metadata.New(map[string]string{featureflag.HeaderKey(findAllTagsFeatureFlag): "true"}) + ctx = metadata.NewOutgoingContext(context.Background(), md) + + c, err = client.FindAllTags(ctx, rpcRequest) + require.NoError(t, err) + ``` + +### Gitlab-Rails + +1. Add feature flag to `lib/gitlab/gitaly_client.rb` (in gitlab-rails): + + ```ruby + SERVER_FEATURE_FLAGS = %w[go-find-all-tags].freeze + ``` + +1. Test in rails console by setting feature flag: + + ```ruby + Feature.enable('gitaly_go-find-all-tags') + ``` |