-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: OpenFeature provider (DVC-7165) (#228)
* simple OpenFeature wrapper for the go SDK * doing some proper data conversions and adding unit tests * fix lint error * More unit tests * code tweak * fixed logging reference * removed deprecated references * fix linter errors * test all examples on PRs * add note to README about openfeature * convert openfeature_provider_test to use testify * test for ignoring nested custom properties * add tests for string, int, float, and object evaluation and fix some bugs * add string, number, and json variables and variations to fixture_small_config.json * add match and unsupported type tests for JSON variables * return type mismatch error when invalid default provided * add Client.OpenFeatureProvider * update openfeature example * handle and test for mismatched types and nils internally * test for errors returned by Variable to increase coverage * use local bucketing instead of cloud bucketing for openfeature example * return DevCycleProvider Local|Cloud for the OF metadata * prefer targetingKey over userId when building user from context * allow nil to be set in custom data * add tests for float values and truncating to int * fix bad import * update README * fix error messages for nil and unexpected variable result type * remove direct dependency on golang.org/x/exp/maps * fix typo in README * fix edge cases in createUserFromEvaluationContext --------- Co-authored-by: chris-hoefgen <[email protected]>
- Loading branch information
1 parent
2c52fe1
commit 274ca7c
Showing
14 changed files
with
1,407 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Test Examples | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test_examples: | ||
name: Test Examples | ||
runs-on: ubuntu-latest | ||
env: | ||
DEVCYCLE_SERVER_SDK_KEY: ${{ secrets.DEVCYCLE_SERVER_SDK_KEY }} | ||
DEVCYCLE_VARIABLE_KEY: test-boolean-variable | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19 | ||
|
||
- name: Run local bucketing example | ||
run: | | ||
go run ./example/local | ||
- name: Run cloud bucketing example | ||
run: | | ||
go run ./example/cloud | ||
- name: Run openfeature example | ||
run: | | ||
go run ./example/openfeature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
devcycle "github.com/devcyclehq/go-server-sdk/v2" | ||
"github.com/open-feature/go-sdk/pkg/openfeature" | ||
) | ||
|
||
func main() { | ||
sdkKey := os.Getenv("DEVCYCLE_SERVER_SDK_KEY") | ||
if sdkKey == "" { | ||
log.Fatal("DEVCYCLE_SERVER_SDK_KEY env var not set: set it to your SDK key") | ||
} | ||
|
||
dvcOptions := devcycle.Options{ | ||
EnableEdgeDB: false, | ||
EnableCloudBucketing: false, | ||
EventFlushIntervalMS: time.Second * 10, | ||
ConfigPollingIntervalMS: time.Second * 10, | ||
RequestTimeout: time.Second * 10, | ||
DisableAutomaticEventLogging: false, | ||
DisableCustomEventLogging: false, | ||
} | ||
dvcClient, _ := devcycle.NewClient(sdkKey, &dvcOptions) | ||
|
||
if err := openfeature.SetProvider(dvcClient.OpenFeatureProvider()); err != nil { | ||
log.Fatalf("Failed to set DevCycle provider: %v", err) | ||
} | ||
client := openfeature.NewClient("devcycle") | ||
|
||
evalCtx := openfeature.NewEvaluationContext("test-1234", map[string]interface{}{ | ||
"email": "[email protected]", | ||
"name": "Test User", | ||
"language": "en", | ||
"country": "CA", | ||
"appVersion": "1.0.0", | ||
"appBuild": "1", | ||
"customData": map[string]interface{}{"custom": "data"}, | ||
"privateCustomData": map[string]interface{}{"private": "data"}, | ||
"deviceModel": "Macbook", | ||
}) | ||
|
||
// Retrieving an object variable with a default value | ||
value, err := client.ObjectValue(context.Background(), "test-json-variable", map[string]interface{}{"value": "default"}, evalCtx) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("Variable results: %#v", value) | ||
|
||
// Checking a boolean variable flag | ||
booleanVariable := "test-boolean-variable" | ||
if featureEnabled, err := client.BooleanValue(context.Background(), booleanVariable, false, evalCtx); err != nil { | ||
log.Printf("Error retrieving feature flag: %v", err) | ||
} else if featureEnabled { | ||
log.Printf("%v = true, feature is enabled", booleanVariable) | ||
} else { | ||
log.Printf("%v = false, feature is disabled", booleanVariable) | ||
} | ||
|
||
// Retrieving a string variable along with the resolution details | ||
details, err := client.StringValueDetails(context.Background(), "doesnt-exist", "default", evalCtx) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("Variable results for unknown variable: %#v", details) | ||
} |
Oops, something went wrong.