Add openfeature module: OpenFeature Java SDK 1.23.0 and flagd 0.19.0 on Spring Boot 4.2.0, targeting, 10% rollout, live reload, flagd-down behaviour, InMemoryProvider tests, with real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
658bc52e2b
commit
24dc4ba3ff
@@ -0,0 +1,8 @@
|
||||
# One flag file, five types, as seen through the OpenFeature client
|
||||
|
||||
evaluation context: targetingKey=anon-1, no attributes
|
||||
boolean flag=new-checkout value=false variant=off reason=DEFAULT
|
||||
string flag=banner-text value=Free shipping over 999 variant=plain reason=STATIC
|
||||
integer flag=discount-percent value=0 variant=none reason=DEFAULT
|
||||
object flag=theme value=[color, density] variant=calm reason=STATIC
|
||||
disabled flag flag=legacy-export value=false variant=null reason=DISABLED
|
||||
@@ -0,0 +1,12 @@
|
||||
# Targeting rules: who sees what
|
||||
|
||||
rule new-checkout : on if tier == premium OR email ends with @ankurm.com, else default (off)
|
||||
anonymous flag=new-checkout value=false variant=off reason=DEFAULT
|
||||
standard flag=new-checkout value=false variant=off reason=DEFAULT
|
||||
premium flag=new-checkout value=true variant=on reason=TARGETING_MATCH
|
||||
staff email flag=new-checkout value=true variant=on reason=TARGETING_MATCH
|
||||
|
||||
rule discount-percent : premium -> 20, standard -> 5, otherwise default (0)
|
||||
anonymous flag=discount-percent value=0 variant=none reason=DEFAULT
|
||||
standard flag=discount-percent value=5 variant=small reason=TARGETING_MATCH
|
||||
premium flag=discount-percent value=20 variant=big reason=TARGETING_MATCH
|
||||
@@ -0,0 +1,9 @@
|
||||
# Percentage rollout: 1000 users hashed on targetingKey
|
||||
|
||||
split 10/90: users with the flag on = 100 of 1000
|
||||
split 50/50: users with the flag on = 486 of 1000
|
||||
users on at 10% but off at 50% = 0 (growing the share never takes a user back)
|
||||
same user asked twice, same answer = 1000 of 1000
|
||||
|
||||
no targetingKey at all:
|
||||
anonymous flag=payment-flow-v2 value=false variant=off reason=DEFAULT
|
||||
@@ -0,0 +1,8 @@
|
||||
# Edit flags.json while the app is running
|
||||
|
||||
before the edit flag=banner-text value=Free shipping over 999 variant=plain reason=STATIC
|
||||
asked again flag=banner-text value=Free shipping over 999 variant=plain reason=CACHED
|
||||
edit: banner-text defaultVariant plain -> sale
|
||||
provider event: CONFIGURATION_CHANGED, flagsChanged=[banner-text]
|
||||
after the edit flag=banner-text value=Year-end sale: extra 5% off variant=sale reason=STATIC
|
||||
event arrived within 10 s: true (indicative latency: about 923 ms)
|
||||
@@ -0,0 +1,17 @@
|
||||
# flagd is not there
|
||||
|
||||
(a) setProvider() against a closed port, asked immediately
|
||||
provider state: NOT_READY
|
||||
premium user flag=new-checkout value=false variant=null reason=ERROR errorCode=PROVIDER_NOT_READY (Provider not yet initialized)
|
||||
|
||||
(b) setProviderAndWait() against a closed port
|
||||
threw: GeneralError
|
||||
message: Initialization timeout exceeded; did not complete within the 1000 ms deadline.
|
||||
state afterwards: ERROR
|
||||
|
||||
(c) flagd is killed while the app is running
|
||||
before the kill flag=new-checkout value=true variant=on reason=TARGETING_MATCH
|
||||
asked again flag=new-checkout value=true variant=on reason=TARGETING_MATCH
|
||||
provider state 1.5 s after the kill: STALE
|
||||
same flag, after flag=new-checkout value=false variant=null reason=ERROR errorCode=GENERAL (DEADLINE_EXCEEDED: CallOptions deadline exceeded a...)
|
||||
never-asked flag, after flag=discount-percent value=0 variant=null reason=ERROR errorCode=GENERAL (DEADLINE_EXCEEDED: CallOptions deadline exceeded a...)
|
||||
@@ -0,0 +1,6 @@
|
||||
# Mistakes the client absorbs: the in-code default is returned, with a reason
|
||||
|
||||
unknown flag flag=no-such-flag value=true variant=null reason=ERROR errorCode=FLAG_NOT_FOUND (NOT_FOUND: Flag not found)
|
||||
typo in the key flag=new-chekout value=false variant=null reason=ERROR errorCode=FLAG_NOT_FOUND (NOT_FOUND: Flag not found)
|
||||
boolean asked of a string flag=banner-text value=true variant=null reason=ERROR errorCode=TYPE_MISMATCH (INVALID_ARGUMENT: Type mismatch error)
|
||||
string asked of an int flag=discount-percent value=n/a variant=null reason=ERROR errorCode=TYPE_MISMATCH (INVALID_ARGUMENT: Type mismatch error)
|
||||
@@ -0,0 +1,7 @@
|
||||
# FILE resolver: the same flags.json evaluated inside the JVM
|
||||
|
||||
premium flag=new-checkout value=true variant=on reason=TARGETING_MATCH
|
||||
staff email flag=new-checkout value=true variant=on reason=TARGETING_MATCH
|
||||
anonymous flag=new-checkout value=false variant=off reason=DEFAULT
|
||||
banner flag=banner-text value=Free shipping over 999 variant=plain reason=STATIC
|
||||
payment-flow-v2 on for 100 of 1000 users (the flagd daemon said 100 in transcript 03)
|
||||
@@ -0,0 +1,5 @@
|
||||
# Testing behind a flag with InMemoryProvider (no flagd, no network)
|
||||
|
||||
new-checkout, defaultVariant=off anonymous -> false
|
||||
same flag, now with a context evaluator anonymous -> false, premium -> true
|
||||
tests in this class: flagOff, flagOn, flipTheStateInsideOneTestAndTargetByContext
|
||||
@@ -0,0 +1,56 @@
|
||||
# 1. Three callers, one flag file
|
||||
$ curl -H 'X-User-Id: anon-1' localhost:8080/checkout # anonymous
|
||||
page: legacy-checkout
|
||||
newCheckout: {"value": false, "variant": "off", "reason": "DEFAULT"}
|
||||
paymentFlowV2: {"value": false, "variant": "off", "reason": "TARGETING_MATCH"}
|
||||
discountPercent: {"value": 0, "variant": "none", "reason": "DEFAULT"}
|
||||
banner: {"value": "Free shipping over 999", "variant": "plain", "reason": "CACHED"}
|
||||
|
||||
$ curl -H 'X-User-Id: u2' -H 'X-Tier: standard' localhost:8080/checkout # standard
|
||||
page: legacy-checkout
|
||||
newCheckout: {"value": false, "variant": "off", "reason": "DEFAULT"}
|
||||
paymentFlowV2: {"value": false, "variant": "off", "reason": "TARGETING_MATCH"}
|
||||
discountPercent: {"value": 5, "variant": "small", "reason": "TARGETING_MATCH"}
|
||||
banner: {"value": "Free shipping over 999", "variant": "plain", "reason": "CACHED"}
|
||||
|
||||
$ curl -H 'X-User-Id: u3' -H 'X-Tier: premium' localhost:8080/checkout # premium
|
||||
page: new-checkout
|
||||
newCheckout: {"value": true, "variant": "on", "reason": "TARGETING_MATCH"}
|
||||
paymentFlowV2: {"value": false, "variant": "off", "reason": "TARGETING_MATCH"}
|
||||
discountPercent: {"value": 20, "variant": "big", "reason": "TARGETING_MATCH"}
|
||||
banner: {"value": "Free shipping over 999", "variant": "plain", "reason": "CACHED"}
|
||||
|
||||
$ curl -H 'X-User-Id: u4' -H 'X-Tier: standard' -H 'X-Email: [email protected]' localhost:8080/checkout # staff
|
||||
page: new-checkout
|
||||
newCheckout: {"value": true, "variant": "on", "reason": "TARGETING_MATCH"}
|
||||
paymentFlowV2: {"value": false, "variant": "off", "reason": "TARGETING_MATCH"}
|
||||
discountPercent: {"value": 5, "variant": "small", "reason": "TARGETING_MATCH"}
|
||||
banner: {"value": "Free shipping over 999", "variant": "plain", "reason": "CACHED"}
|
||||
|
||||
# 2. Edit the flag file: new-checkout defaultVariant off -> on (no restart, no deploy)
|
||||
$ curl -H 'X-User-Id: anon-1' localhost:8080/checkout # anonymous, after the edit
|
||||
page: new-checkout
|
||||
newCheckout: {"value": true, "variant": "on", "reason": "DEFAULT"}
|
||||
paymentFlowV2: {"value": false, "variant": "off", "reason": "TARGETING_MATCH"}
|
||||
discountPercent: {"value": 0, "variant": "none", "reason": "DEFAULT"}
|
||||
banner: {"value": "Free shipping over 999", "variant": "plain", "reason": "CACHED"}
|
||||
|
||||
# 3. Kill flagd
|
||||
$ curl -H 'X-User-Id: u3' -H 'X-Tier: premium' localhost:8080/checkout # premium, flagd gone
|
||||
page: legacy-checkout
|
||||
newCheckout: {"value": false, "variant": null, "reason": "ERROR", "errorCode": "GENERAL"}
|
||||
paymentFlowV2: {"value": false, "variant": null, "reason": "ERROR", "errorCode": "GENERAL"}
|
||||
discountPercent: {"value": 0, "variant": null, "reason": "ERROR", "errorCode": "GENERAL"}
|
||||
banner: {"value": "Free shipping over 999", "variant": "plain", "reason": "CACHED"}
|
||||
|
||||
|
||||
# Application log: provider events, then the first hook lines
|
||||
INFO com.ankurm.openfeature.FlagConfig : flag provider READY (flagd)
|
||||
INFO com.ankurm.openfeature.FlagConfig : flag provider READY (flagd)
|
||||
INFO com.ankurm.openfeature.FlagConfig : flag configuration changed: [new-checkout]
|
||||
WARN com.ankurm.openfeature.FlagConfig : flag provider STALE: there has been an error
|
||||
...
|
||||
INFO flags : flag=new-checkout value=false variant=off reason=DEFAULT
|
||||
INFO flags : flag=new-checkout value=false variant=off reason=DEFAULT
|
||||
INFO flags : flag=payment-flow-v2 value=false variant=off reason=DEFAULT
|
||||
INFO flags : flag=discount-percent value=0 variant=none reason=DEFAULT
|
||||
Reference in New Issue
Block a user