Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
run: |
mkdir example-1
cd example-1
npx --yes @featurevisor/cli@3 init --example=1
npx --yes @featurevisor/cli@latest init --example=1
npm install
npx featurevisor build
npx featurevisor test --onlyFailures
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
mkdir example-1
cd example-1
npx --yes @featurevisor/cli@3 init --example=1
npx --yes @featurevisor/cli@latest init --example=1
npm install
npx featurevisor build
npx featurevisor test --onlyFailures
Expand Down
319 changes: 207 additions & 112 deletions README.md

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions bench/sticky_session.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Serial, per getter benchmark with a constructed sticky handoff corpus.
# Run with: mix run bench/sticky_session.exs 5000

iterations =
case Enum.drop_while(System.argv(), &(&1 == "--")) do
[value | _] -> String.to_integer(value)
_ -> 5000
end

if iterations < 1, do: raise("positive iteration count required")

datafile = %{
"schemaVersion" => "2",
"revision" => "sticky-bench",
"segments" => %{},
"features" => %{
"gate" => %{
"bucketBy" => "userId",
"traffic" => [%{"key" => "all", "segments" => "*", "percentage" => 100_000}]
}
},
"variables" => %{
"leaf" => %{"type" => "integer", "defaultValue" => 1},
"root" => %{
"type" => "integer",
"defaultValue" => 1,
"disabledValue" => 0,
"requiredFeatures" => ["gate", "gate"],
"requiredVariables" => [
%{"variable" => "leaf", "operator" => "equals", "value" => 1},
%{"variable" => "leaf", "operator" => "equals", "value" => 1}
]
}
}
}

IO.puts("kind,size,scope,iterations,mean_us")

for kind <- [:features, :variables], size <- [0, 100, 1000, 5000], scope <- [:instance, :child] do
filler =
if size <= 1,
do: %{},
else: for(index <- 1..(size - 1), into: %{}, do: {"unrelated#{index}", index})

features =
if kind == :features and size > 0,
do:
Map.put(Map.new(filler, fn {key, _} -> {key, %{"enabled" => true}} end), "gate", %{
"enabled" => true
}),
else: %{}

variables = if kind == :variables and size > 0, do: Map.put(filler, "leaf", 1), else: %{}
sticky = %{sticky_features: features, sticky_variables: variables}

options =
%{datafile: datafile, log_level: :fatal}
|> Map.merge(if(scope == :instance, do: sticky, else: %{}))

f = Featurevisor.create_featurevisor(options)
child = if scope == :child, do: Featurevisor.spawn(f, %{"userId" => "bench"}, sticky), else: nil

getter =
if child,
do: fn -> Featurevisor.Child.get_global_variable(child, "root") end,
else: fn -> Featurevisor.get_global_variable(f, "root", %{"userId" => "bench"}) end

for _ <- 1..100 do
if getter.() != 1, do: raise("unexpected gated value")
end

total_ns =
Enum.reduce(1..iterations, 0, fn _, total ->
started = System.monotonic_time(:nanosecond)
value = getter.()
elapsed = System.monotonic_time(:nanosecond) - started
if value != 1, do: raise("unexpected gated value")
total + elapsed
end)

IO.puts(
"#{kind},#{size},#{scope},#{iterations},#{Float.round(total_ns / iterations / 1000, 3)}"
)

if child, do: Featurevisor.Child.close(child)
Featurevisor.close(f)
end
264 changes: 264 additions & 0 deletions conformance/openfeature-provider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
{
"kind": "featurevisor.openfeature-provider",
"schemaVersion": 1,
"datafile": {
"schemaVersion": "2",
"revision": "provider-conformance",
"segments": {},
"features": {
"checkout": {
"bucketBy": "userId",
"variations": [
{ "value": "on", "variables": { "config": "{\"enabled\":true}", "nullable": "null" } }
],
"variablesSchema": {
"config": { "type": "json", "defaultValue": "{}" },
"nullable": { "type": "json", "defaultValue": "null" }
},
"force": [
{
"conditions": { "attribute": "userId", "operator": "equals", "value": "forced" },
"enabled": true,
"variation": "on"
}
],
"traffic": [{ "key": "all", "segments": "*", "percentage": 100000, "variation": "on" }]
},
"disabled": {
"bucketBy": "userId",
"variations": [],
"force": [
{
"conditions": { "attribute": "blocked", "operator": "equals", "value": true },
"enabled": false
}
],
"traffic": []
},
"accountTargeted": {
"bucketBy": "accountId",
"variations": [],
"force": [
{
"conditions": { "attribute": "accountId", "operator": "equals", "value": "" },
"enabled": true
}
],
"traffic": []
},
"targetOnly": {
"bucketBy": "userId",
"variations": [],
"force": [
{
"conditions": { "attribute": "userId", "operator": "equals", "value": "forced" },
"enabled": true
}
],
"traffic": []
},
"conditional": {
"bucketBy": "userId",
"conditions": { "feature": "checkout", "enabled": false },
"traffic": [{ "key": "all", "conditions": "*", "percentage": 100000 }]
}
},
"variables": {
"settings": { "type": "json", "defaultValue": "{\"region\":\"eu\"}" },
"nullable": { "type": "json", "defaultValue": "null" },
"settingsAlias": { "type": "json", "compose": "settings" },
"jsonText": { "type": "json", "defaultValue": "\"null\"" },
"jsonTextAlias": { "type": "json", "compose": "jsonText" },
"screen": {
"type": "object",
"compose": [
{ "key": "enabled", "feature": "checkout" },
{ "key": "settings", "variable": "settings" }
]
},
"restricted": {
"type": "boolean",
"defaultValue": true,
"disabledValue": false,
"conditions": { "attribute": "allowed", "operator": "equals", "value": true }
},
"screenOverride": {
"type": "object",
"compose": "screen",
"overrideProgram": [
{
"key": "regional",
"conditions": "*",
"operations": [{ "op": "set", "path": ["settings", "region"], "value": "us" }],
"onMatch": 1,
"onMiss": 1
}
]
},
"brokenAlias": { "type": "object", "compose": "brokenAlias" }
}
},
"cases": [
{
"name": "forced flag",
"flagKey": "checkout",
"type": "boolean",
"default": false,
"context": { "targetingKey": "forced" },
"expected": { "value": true, "reason": "TARGETING_MATCH" }
},
{
"name": "variation selector",
"flagKey": "checkout:variation",
"type": "string",
"default": "fallback",
"context": { "targetingKey": "forced" },
"expected": { "value": "on", "reason": "TARGETING_MATCH", "variant": "on" }
},
{
"name": "feature JSON",
"flagKey": "checkout:config",
"type": "object",
"default": {},
"context": { "targetingKey": "forced" },
"expected": { "value": { "enabled": true } }
},
{
"name": "global JSON",
"flagKey": "variable:settings",
"type": "object",
"default": {},
"context": {},
"expected": { "value": { "region": "eu" }, "reason": "DEFAULT" }
},
{
"name": "feature JSON null",
"flagKey": "checkout:nullable",
"type": "object",
"default": { "fallback": true },
"context": { "targetingKey": "forced" },
"expected": { "value": { "fallback": true } }
},
{
"name": "global JSON null",
"flagKey": "variable:nullable",
"type": "object",
"default": { "fallback": true },
"context": {},
"expected": { "value": { "fallback": true }, "reason": "DEFAULT" }
},
{
"name": "disabled flag",
"flagKey": "disabled",
"type": "boolean",
"default": true,
"context": { "blocked": true },
"expected": { "value": false, "reason": "TARGETING_MATCH" }
},
{
"name": "missing flag",
"flagKey": "missing",
"type": "boolean",
"default": false,
"context": {},
"expected": { "value": false, "reason": "ERROR", "errorCode": "FLAG_NOT_FOUND" }
},
{
"name": "type mismatch",
"flagKey": "checkout:config",
"type": "string",
"default": "fallback",
"context": { "targetingKey": "forced" },
"expected": { "value": "fallback", "reason": "ERROR", "errorCode": "TYPE_MISMATCH" }
},
{
"name": "composed object",
"flagKey": "variable:screen",
"type": "object",
"default": {},
"context": { "targetingKey": "forced" },
"expected": {
"value": { "enabled": true, "settings": { "region": "eu" } },
"reason": "TARGETING_MATCH"
}
},
{
"name": "string alias to JSON object",
"flagKey": "variable:settingsAlias",
"type": "object",
"default": {},
"context": {},
"expected": { "value": { "region": "eu" }, "reason": "TARGETING_MATCH" }
},
{
"name": "string alias decodes JSON exactly once",
"flagKey": "variable:jsonTextAlias",
"type": "string",
"default": "fallback",
"context": {},
"expected": { "value": "null", "reason": "TARGETING_MATCH" }
},
{
"name": "composed override",
"flagKey": "variable:screenOverride",
"type": "object",
"default": {},
"context": { "targetingKey": "forced" },
"expected": {
"value": { "enabled": true, "settings": { "region": "us" } },
"reason": "TARGETING_MATCH"
}
},
{
"name": "unmet variable root conditions",
"flagKey": "variable:restricted",
"type": "boolean",
"default": true,
"context": {},
"expected": { "value": false, "reason": "DISABLED" }
},
{
"name": "unmet feature root conditions",
"flagKey": "conditional",
"type": "boolean",
"default": true,
"context": { "targetingKey": "forced" },
"expected": { "value": false, "reason": "DISABLED" }
},
{
"name": "composition dependency error",
"flagKey": "variable:brokenAlias",
"type": "object",
"default": { "fallback": true },
"context": {},
"expected": { "value": { "fallback": true }, "reason": "ERROR", "errorCode": "GENERAL" }
}
],
"targetingCases": [
{
"name": "absent preserves field",
"context": { "userId": "forced" },
"expectedUserId": "forced",
"expectedValue": true
},
{
"name": "empty overrides field",
"context": { "targetingKey": "", "userId": "forced" },
"expectedUserId": "",
"expectedValue": false
},
{
"name": "nonempty overrides field",
"context": { "targetingKey": "other", "userId": "forced" },
"expectedUserId": "other",
"expectedValue": false
}
],
"customTargetingCase": {
"flagKey": "accountTargeted",
"context": { "targetingKey": "", "accountId": "old" },
"targetingKeyField": "accountId",
"expectedValue": true,
"expectedReason": "TARGETING_MATCH"
}
}
Loading
Loading