Skip to content

Commit

Permalink
Add doc
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Aug 1, 2024
1 parent d866762 commit 8e905c4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ describe('Provider tests', () => {
});
goffClient = OpenFeature.getClient('my-app')
await OpenFeature.setProviderAndWait('my-app', goFeatureFlagProvider);
OpenFeature.setContext({
gofeatureflag:{
flagList: ["flag1", "flag2"]
}
})

userCtx = {
targetingKey: 'd45e303a-38c2-11ed-a261-0242ac120002', // user unique identifier (mandatory)
Expand Down
7 changes: 4 additions & 3 deletions website/docs/configure_flag/rule_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ The targeting key is a fundamental part of the evaluation context because it dir
When you create an evaluation context some fields are reserved for GO Feature Flag.
Those fields are used by GO Feature Flag directly, you can use them as will but you should be aware that they are used by GO Feature Flag.

| Field | Description |
|---------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `gofeatureflag.currentDateTime` | If this property is set, we will use this date as base for all the rollout strategies which implies dates _(experimentation, progressive and scheduled)_.<br/>**Format:** Date following the RF3339 format. |
| Field | Description |
|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `gofeatureflag.currentDateTime` | If this property is set, we will use this date as base for all the rollout strategies which implies dates _(experimentation, progressive and scheduled)_.<br/>**Format:** Date following the RF3339 format. |
| `gofeatureflag.flagList` | If this property is set, in the bulk evaluation mode (for the client SDK) we will only evaluate the flags in this list.<br/>If empty or not set the default behavior is too evaluate all the flags.<br/>**Format:** []string |

## Rule format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,41 @@ OpenFeatureAPI.setEvaluationContext(newEvalCtx)

`setEvaluationContext()` is a synchronous function similar to `setProvider()` and will fetch the new version of the feature flags based on this new `EvaluationContext`.

### Limit the flags to evaluate

By default, the provider will fetch all the flags configured in the GO Feature Flag server to be ready to evaluate them.
If you know in advance, what are the flags you will evaluate in your application, you can specify the list of flags to evaluate in the context.

You need to add in the evaluation context the restricted key `gofeatureflag.flagList` with the list of flags you want to evaluate.

```kotlin
val newContext: EvaluationContext = ImmutableContext(
targetingKey = "userId",
attributes = mapOf(
"gofeatureflag" to Value.Structure(
mapOf(
"flagList" to Value.List(
listOf(
// list of flags to evaluate
Value.String("flag1"),
Value.String("flag2"),
Value.String("flag3")
)
),
)
),
)
)

OpenFeatureAPI.setEvaluationContext(newEvalCtx)
```

By setting the `gofeatureflag.flagList` key in the context, the provider will only fetch the flags specified in the list.

:::warning
When limiting the flags to evaluate, if you try to evaluate a flag not in the list, the provider will return the default value with the error `FLAG_NOT_FOUND`.
:::

### Evaluate a feature flag
The client is used to retrieve values for the current `EvaluationContext`. For example, retrieving a boolean value for the flag **"my-flag"**:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ client.addHandler(ProviderEvents.Stale, () => { //... });
client.addHandler(ProviderEvents.ConfigurationChanged, () => { //... });
```
### Limit the flags to evaluate
By default, the provider will fetch all the flags configured in the GO Feature Flag server to be ready to evaluate them.
If you know in advance, what are the flags you will evaluate in your application, you can specify the list of flags to evaluate in the context.
You need to add in the evaluation context the restricted key `gofeatureflag.flagList` with the list of flags you want to evaluate.
```typescript
OpenFeature.setContext({
// ...
gofeatureflag: {
flagList: ['flag1', 'flag2']
}
});

await OpenFeature.setContext(evaluationCtx);
```
By setting the `gofeatureflag.flagList` key in the context, the provider will only fetch the flags specified in the list.
:::warning
When limiting the flags to evaluate, if you try to evaluate a flag not in the list, the provider will return the default value with the error `FLAG_NOT_FOUND`.
:::
### Available options
| Option name | Type | Default | Description |
|-------------------------------|--------|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)

`setEvaluationContext()` is a synchronous function similar to `setProvider()` and will fetch the new version of the feature flags based on this new `EvaluationContext`.

### Limit the flags to evaluate

By default, the provider will fetch all the flags configured in the GO Feature Flag server to be ready to evaluate them.
If you know in advance, what are the flags you will evaluate in your application, you can specify the list of flags to evaluate in the context.

You need to add in the evaluation context the restricted key `gofeatureflag.flagList` with the list of flags you want to evaluate.

```swift
let ctx = MutableContext(targetingKey: "myNewTargetingKey")
ctx.add(
key: "gofeatureflag",
value: Value.list([
Value.string("flag1"),
Value.string("flag2")
])
)
OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)
```

By setting the `gofeatureflag.flagList` key in the context, the provider will only fetch the flags specified in the list.

:::warning
When limiting the flags to evaluate, if you try to evaluate a flag not in the list, the provider will return the default value with the error `FLAG_NOT_FOUND`.
:::

### Evaluate a feature flag
The client is used to retrieve values for the current `EvaluationContext`. For example, retrieving a boolean value for the flag **"my-flag"**:

Expand Down

0 comments on commit 8e905c4

Please sign in to comment.