Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Move fractional evaluation pages to website #833

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 1 addition & 115 deletions docs/configuration/fractional_evaluation.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,3 @@
# Fractional Evaluation

OpenFeature allows clients to pass contextual information which can then be used during a flag evaluation. For example, a client could pass the email address of the user.

In some scenarios, it is desirable to use that contextual information to segment the user population further and thus return dynamic values.

Look at the [headerColor](https://github.com/open-feature/flagd/blob/main/samples/example_flags.flagd.json#L88-#L133) flag. The `defaultVariant` is `red`, but it contains a [targeting rule](reusable_targeting_rules.md), meaning a fractional evaluation occurs for flag evaluation with a `context` object containing `email` and where that `email` value contains `@faas.com`.

In this case, `25%` of the email addresses will receive `red`, `25%` will receive `blue`, and so on.

Importantly, the evaluations are "sticky" meaning that the same `email` address will always belong to the same "bucket" and thus always receive the same color.

## Fractional Evaluation: Technical Description

The `fractionalEvaluation` operation is a custom JsonLogic operation which deterministically selects a variant based on
the defined distribution of each variant (as a percentage).
This works by hashing ([xxHash](https://cyan4973.github.io/xxHash/))
the given data point, converting it into an int in the range [0, 99].
Whichever range this int falls in decides which variant
is selected.
As hashing is deterministic we can be sure to get the same result every time for the same data point.

## Fractional evaluation configuration

The `fractionalEvaluation` can be added as part of a targeting definition.
The value is an array and the first element is the name of the property to use from the evaluation context.
This value should typically be something that remains consistent for the duration of a users session (e.g. email or session ID).
The other elements in the array are nested arrays with the first element representing a variant and the second being the percentage that this option is selected.
There is no limit to the number of elements but the configured percentages must add up to 100.

```js
// Factional evaluation property name used in a targeting rule
"fractionalEvaluation": [
// Evaluation context property used to determine the split
"email",
// Split definitions contain an array with a variant and percentage
// Percentages must add up to 100
[
// Must match a variant defined in the flag configuration
"red",
// The probability this configuration is selected
50
],
[
// Must match a variant defined in the flag configuration
"green",
// The probability this configuration is selected
50
]
]
```

## Example

Flags defined as such:

```json
{
"flags": {
"headerColor": {
"variants": {
"red": "#FF0000",
"blue": "#0000FF",
"green": "#00FF00"
},
"defaultVariant": "red",
"state": "ENABLED",
"targeting": {
"fractionalEvaluation": [
"email",
[
"red",
50
],
[
"blue",
20
],
[
"green",
30
]
]
}
}
}
}
```

will return variant `red` 50% of the time, `blue` 20% of the time & `green` 30% of the time.

Command:

```shell
curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "[email protected]"}}' -H "Content-Type: application/json"
```

Result:

```shell
{"value":"#0000FF","reason":"TARGETING_MATCH","variant":"blue"}
```

Command:

```shell
curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "[email protected]"}}' -H "Content-Type: application/json"
```

Result:

```json
{"value":"#00FF00","reason":"TARGETING_MATCH","variant":"green"}
```

Notice that rerunning either curl command will always return the same variant and value.
The only way to get a different value is to change the email or update the `fractionalEvaluation` configuration.
The content of this page has moved. See [flagd configuration](https://flagd.dev/reference/fractional_evaluation)
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ nav:
- 'FeatureFlagConfiguration': 'k8s/crds/featureflagconfiguration.md'
- 'Flagd Telemetry':
- 'Flagd OpenTelemetry Support': 'concepts/opentelemetry.md'
- 'Reference':
- 'Fractional Evaluation': 'reference/fractional_evaluation.md'
plugins:
- social
2 changes: 1 addition & 1 deletion web-docs/concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Fractional evaluations are "sticky" and deterministic meaning that the same emai

This is true even if you run multiple flagd APIs completely independently.

See this page for more information on [flagd fractional evaluation logic](https://github.com/open-feature/flagd/blob/main/docs/configuration/fractional_evaluation.md).
See this page for more information on [flagd fractional evaluation logic](reference/fractional_evaluation.md).

## Other target specifiers

Expand Down
117 changes: 117 additions & 0 deletions web-docs/reference/fractional_evaluation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Fractional Evaluation

OpenFeature allows clients to pass contextual information which can then be used during a flag evaluation. For example, a client could pass the email address of the user.

In some scenarios, it is desirable to use that contextual information to segment the user population further and thus return dynamic values.

Look at the [headerColor](https://github.com/open-feature/flagd/blob/main/samples/example_flags.flagd.json#L88-#L133) flag. The `defaultVariant` is `red`, but it contains a [targeting rule](reusable_targeting_rules.md), meaning a fractional evaluation occurs for flag evaluation with a `context` object containing `email` and where that `email` value contains `@faas.com`.

In this case, `25%` of the email addresses will receive `red`, `25%` will receive `blue`, and so on.

Importantly, the evaluations are "sticky" meaning that the same `email` address will always belong to the same "bucket" and thus always receive the same color.

## Fractional Evaluation: Technical Description

The `fractionalEvaluation` operation is a custom JsonLogic operation which deterministically selects a variant based on
the defined distribution of each variant (as a percentage).
This works by hashing ([murmur3](https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp))
the given data point, converting it into an int in the range [0, 99].
Whichever range this int falls in decides which variant
is selected.
As hashing is deterministic we can be sure to get the same result every time for the same data point.

## Fractional evaluation configuration

The `fractionalEvaluation` can be added as part of a targeting definition.
The value is an array and the first element is the name of the property to use from the evaluation context.
This value should typically be something that remains consistent for the duration of a users session (e.g. email or session ID).
The other elements in the array are nested arrays with the first element representing a variant and the second being the percentage that this option is selected.
There is no limit to the number of elements but the configured percentages must add up to 100.

```js
// Factional evaluation property name used in a targeting rule
"fractionalEvaluation": [
// Evaluation context property used to determine the split
"email",
// Split definitions contain an array with a variant and percentage
// Percentages must add up to 100
[
// Must match a variant defined in the flag configuration
"red",
// The probability this configuration is selected
50
],
[
// Must match a variant defined in the flag configuration
"green",
// The probability this configuration is selected
50
]
]
```

## Example

Flags defined as such:

```json
{
"flags": {
"headerColor": {
"variants": {
"red": "#FF0000",
"blue": "#0000FF",
"green": "#00FF00"
},
"defaultVariant": "red",
"state": "ENABLED",
"targeting": {
"fractionalEvaluation": [
"email",
[
"red",
50
],
[
"blue",
20
],
[
"green",
30
]
]
}
}
}
}
```

will return variant `red` 50% of the time, `blue` 20% of the time & `green` 30% of the time.

Command:

```shell
curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "[email protected]"}}' -H "Content-Type: application/json"
```

Result:

```shell
{"value":"#0000FF","reason":"TARGETING_MATCH","variant":"blue"}
```

Command:

```shell
curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "[email protected]"}}' -H "Content-Type: application/json"
```

Result:

```json
{"value":"#00FF00","reason":"TARGETING_MATCH","variant":"green"}
```

Notice that rerunning either curl command will always return the same variant and value.
The only way to get a different value is to change the email or update the `fractionalEvaluation` configuration.