Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/metadata/featureflag/context.go51
-rw-r--r--internal/metadata/featureflag/context_test.go27
2 files changed, 10 insertions, 68 deletions
diff --git a/internal/metadata/featureflag/context.go b/internal/metadata/featureflag/context.go
index 25f269d60..950e81c70 100644
--- a/internal/metadata/featureflag/context.go
+++ b/internal/metadata/featureflag/context.go
@@ -92,57 +92,26 @@ func injectIntoIncomingAndOutgoingContext(ctx context.Context, key string, enabl
// by us in case they match the feature flag prefix but don't have a definition. This function also
// returns the state of the feature flag *as defined in the context*. This value may be overridden.
func FromContext(ctx context.Context) map[FeatureFlag]bool {
- rawFlags := RawFromContext(ctx)
-
- flags := map[FeatureFlag]bool{}
- for rawName, value := range rawFlags {
- flag, err := FromMetadataKey(rawName)
- if err != nil {
- continue
- }
-
- flags[flag] = value == "true"
- }
-
- return flags
-}
-
-// Raw contains feature flags and their values in their raw form with header prefix in place
-// and values unparsed.
-type Raw map[string]string
-
-// RawFromContext returns a map that contains all feature flags with their values. The feature
-// flags are in their raw format with the header prefix in place. If multiple values are set a
-// flag, the first occurrence is used.
-//
-// This is mostly intended for propagating the feature flags by other means than the metadata,
-// for example into the hooks through the environment.
-func RawFromContext(ctx context.Context) Raw {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
- return nil
+ return map[FeatureFlag]bool{}
}
- featureFlags := map[string]string{}
- for key, values := range md {
- if !strings.HasPrefix(key, ffPrefix) || len(values) == 0 {
+ flags := map[FeatureFlag]bool{}
+ for metadataName, values := range md {
+ if len(values) == 0 {
continue
}
- featureFlags[key] = values[0]
- }
-
- return featureFlags
-}
+ flag, err := FromMetadataKey(metadataName)
+ if err != nil {
+ continue
+ }
-// OutgoingWithRaw returns a new context with raw flags appended into the outgoing
-// metadata.
-func OutgoingWithRaw(ctx context.Context, flags Raw) context.Context {
- for key, value := range flags {
- ctx = metadata.AppendToOutgoingContext(ctx, key, value)
+ flags[flag] = values[0] == "true"
}
- return ctx
+ return flags
}
func rubyHeaderKey(flag string) string {
diff --git a/internal/metadata/featureflag/context_test.go b/internal/metadata/featureflag/context_test.go
index 0faf564a4..8e4e222da 100644
--- a/internal/metadata/featureflag/context_test.go
+++ b/internal/metadata/featureflag/context_test.go
@@ -177,30 +177,3 @@ func TestFromContext(t *testing.T) {
}, FromContext(ctx))
})
}
-
-func TestRaw(t *testing.T) {
- enabledFlag := FeatureFlag{Name: "enabled-flag"}
- disabledFlag := FeatureFlag{Name: "disabled-flag"}
-
- raw := Raw{
- ffPrefix + enabledFlag.Name: "true",
- ffPrefix + disabledFlag.Name: "false",
- }
-
- t.Run("RawFromContext", func(t *testing.T) {
- ctx := createContext()
- ctx = IncomingCtxWithFeatureFlag(ctx, enabledFlag, true)
- ctx = IncomingCtxWithFeatureFlag(ctx, disabledFlag, false)
-
- require.Equal(t, raw, RawFromContext(ctx))
- })
-
- t.Run("OutgoingWithRaw", func(t *testing.T) {
- outgoingMD, ok := metadata.FromOutgoingContext(OutgoingWithRaw(createContext(), raw))
- require.True(t, ok)
- require.Equal(t, metadata.MD{
- ffPrefix + enabledFlag.Name: {"true"},
- ffPrefix + disabledFlag.Name: {"false"},
- }, outgoingMD)
- })
-}