diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-06-30 12:45:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-06 09:13:46 +0300 |
commit | f00ed2d000b6d92dd54b18dcec09ab7976497634 (patch) | |
tree | 48ebb5c81e9e140b05aec878e6a52752f526599f | |
parent | a8c7c3e210bf5f0a2f7ef2418248429e2187cba0 (diff) |
coordinator: Refactor injection of default flags to not use raw flags
When injecting default values for feature flags into the outgoing gRPC
context of Gitaly peers we're using `RawFlags()` to extract currently
set feature flags. This function is going away in favor of the type-safe
`FromContext()` function.
Migrate the coordinator to use `FromContext()`.
-rw-r--r-- | internal/praefect/coordinator.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/praefect/coordinator.go b/internal/praefect/coordinator.go index 9fbb8171c..6f6d439b6 100644 --- a/internal/praefect/coordinator.go +++ b/internal/praefect/coordinator.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "strconv" "sync" "time" @@ -612,16 +611,17 @@ func streamParametersContext(ctx context.Context) context.Context { // Praefect. But given that feature flags should be introduced with a default value of // `false` to account for zero-dodwntime upgrades, the view would also be consistent in that // case. - rawFeatureFlags := featureflag.RawFromContext(ctx) - if rawFeatureFlags == nil { - rawFeatureFlags = map[string]string{} + + explicitlySetFlags := map[string]bool{} + for flag := range featureflag.FromContext(ctx) { + explicitlySetFlags[flag.Name] = true } outgoingCtx := metadata.IncomingToOutgoing(ctx) - for _, ff := range featureflag.DefinedFlags() { - if _, ok := rawFeatureFlags[ff.MetadataKey()]; !ok { - outgoingCtx = grpc_metadata.AppendToOutgoingContext( - outgoingCtx, ff.MetadataKey(), strconv.FormatBool(ff.OnByDefault), + for _, flag := range featureflag.DefinedFlags() { + if !explicitlySetFlags[flag.Name] { + outgoingCtx = featureflag.OutgoingCtxWithFeatureFlag( + outgoingCtx, flag, flag.OnByDefault, ) } } |