|
| 1 | +OpenFeature Multi-Provider |
| 2 | +------------ |
| 3 | + |
| 4 | +The Multi-Provider allows you to use multiple underlying providers as sources of flag data for the OpenFeature server SDK. |
| 5 | +When a flag is being evaluated, the Multi-Provider will consult each underlying provider it is managing in order to |
| 6 | +determine the final result. Different evaluation strategies can be defined to control which providers get evaluated and |
| 7 | +which result is used. |
| 8 | + |
| 9 | +The Multi-Provider is a powerful tool for performing migrations between flag providers, or combining multiple providers |
| 10 | +into a single feature flagging interface. For example: |
| 11 | + |
| 12 | +- **Migration**: When migrating between two providers, you can run both in parallel under a unified flagging interface. |
| 13 | +As flags are added to the new provider, the Multi-Provider will automatically find and return them, falling back to the old provider |
| 14 | +if the new provider does not have |
| 15 | +- **Multiple Data Sources**: The Multi-Provider allows you to seamlessly combine many sources of flagging data, such as |
| 16 | +environment variables, local files, database values and SaaS hosted feature management systems. |
| 17 | + |
| 18 | +# Installation |
| 19 | + |
| 20 | +```sh |
| 21 | +go get github.com/open-feature/go-sdk-contrib/providers/multi-provider |
| 22 | +go get github.com/open-feature/go-sdk |
| 23 | +``` |
| 24 | + |
| 25 | +# Usage |
| 26 | + |
| 27 | +```go |
| 28 | +import ( |
| 29 | + "github.com/open-feature/go-sdk/openfeature" |
| 30 | + mp "github.com/open-feature/go-sdk-contrib/providers/multi-provider" |
| 31 | +) |
| 32 | + |
| 33 | +providers := make(mp.ProviderMap) |
| 34 | +providers["providerA"] = providerA |
| 35 | +providers["providerB"] = providerB |
| 36 | +provider, err := mp.NewMultiProvider(providers, mp.StrategyFirstMatch, WithLogger(myLogger)) |
| 37 | +openfeature.SetProvider(provider) |
| 38 | +``` |
| 39 | + |
| 40 | +# Options |
| 41 | + |
| 42 | +- `WithTimeout` - the duration is used for the total timeout across parallel operations. If none is set it will default |
| 43 | +to 5 seconds. This is not supported for `FirstMatch` yet, which executes sequentially |
| 44 | +- `WithFallbackProvider` - Used for setting a fallback provider for the `Comparison` strategy |
| 45 | +- `WithLogger` - Provides slog support |
| 46 | + |
| 47 | +# Strategies |
| 48 | + |
| 49 | +There are multiple strategies that can be used to determine the result returned to the caller. A strategy must be set at |
| 50 | +initialization time. |
| 51 | + |
| 52 | +There are 3 strategies available currently: |
| 53 | + |
| 54 | +- _First Match_ |
| 55 | +- _First Success_ |
| 56 | +- _Comparison_ |
| 57 | + |
| 58 | +## First Match Strategy |
| 59 | + |
| 60 | +The first match strategy works by **sequentially** calling each provider in the order that they are provided to the mutli-provider. |
| 61 | +The first provider that returns a result. It will try calling the next provider whenever it encounters a `FLAG_NOT_FOUND` |
| 62 | +error. However, if a provider returns an error other than `FLAG_NOT_FOUND` the provider will stop and return the default |
| 63 | +value along with setting the error details if a detailed request is issued. (allow changing this behavior?) |
| 64 | + |
| 65 | +## First Success Strategy |
| 66 | + |
| 67 | +The First Success strategy works by calling each provider in **parallel**. The first provider that returns a response |
| 68 | +with no errors is returned and all other calls are cancelled. If no provider provides a successful result the default |
| 69 | +value will be returned to the caller. |
| 70 | + |
| 71 | +## Comparison |
| 72 | + |
| 73 | +The Comparison strategy works by calling each provider in **parallel**. All results are collected from each provider and |
| 74 | +then the resolved results are compared to each other. If they all agree then that value is returned. If not and a fallback |
| 75 | +provider is specified then the fallback will be executed. If no fallback is configured then the default value will be |
| 76 | +returned. If a provider returns `FLAG_NOT_FOUND` that is not included in the comparison. If all providers |
| 77 | +return not found then the default value is returned. Finally, if any provider returns an error other than `FLAG_NOT_FOUND` |
| 78 | +the evaluation immediately stops and that error result is returned. This strategy does NOT support `ObjectEvaluation` |
| 79 | + |
| 80 | +# Not Yet Implemented |
| 81 | + |
| 82 | +- Hooks support |
| 83 | +- Event support |
| 84 | +- Full slog support |
0 commit comments