-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat: Update in-process resolver to support flag metadata #1102 #1122
Draft
chrfwow
wants to merge
14
commits into
open-feature:main
Choose a base branch
from
chrfwow:feat/Update-in-process-resolver-to-support-flag-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d127cb5
feat: Update in-process resolver to support flag metadata #1102
chrfwow 0bedec3
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow 319ee49
Merge branch 'main' into feat/Update-in-process-resolver-to-support-f…
chrfwow c08e7bc
feat: Update in-process resolver to support flag metadata #1102
chrfwow 4c6393a
Merge remote-tracking branch 'origin/feat/Update-in-process-resolver-…
chrfwow da9e92b
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow 18219c0
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow af0006c
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow f8e69aa
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow 72d1fbc
Merge branch 'main' into feat/Update-in-process-resolver-to-support-f…
chrfwow b495c6b
Merge branch 'main' into feat/Update-in-process-resolver-to-support-f…
toddbaert 65a508c
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow 9b49abc
Merge remote-tracking branch 'origin/feat/Update-in-process-resolver-…
chrfwow a8a2cd6
fixup! feat: Update in-process resolver to support flag metadata #1102
chrfwow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import dev.openfeature.sdk.Value; | ||
import dev.openfeature.sdk.exceptions.ParseError; | ||
import dev.openfeature.sdk.exceptions.TypeMismatchError; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
@@ -39,8 +40,9 @@ public class InProcessResolver implements Resolver { | |
private final Consumer<ConnectionEvent> onConnectionEvent; | ||
private final Operator operator; | ||
private final long deadline; | ||
private final ImmutableMetadata metadata; | ||
private final ImmutableMetadata fallBackMetadata; | ||
private final Supplier<Boolean> connectedSupplier; | ||
private final String scope; | ||
|
||
/** | ||
* Resolves flag values using | ||
|
@@ -62,11 +64,14 @@ public InProcessResolver( | |
this.onConnectionEvent = onConnectionEvent; | ||
this.operator = new Operator(); | ||
this.connectedSupplier = connectedSupplier; | ||
this.metadata = options.getSelector() == null | ||
? null | ||
: ImmutableMetadata.builder() | ||
.addString("scope", options.getSelector()) | ||
.build(); | ||
if (options.getSelector() == null) { | ||
this.scope = null; | ||
this.fallBackMetadata = null; | ||
} else { | ||
this.scope = options.getSelector(); | ||
this.fallBackMetadata = | ||
ImmutableMetadata.builder().addString("scope", this.scope).build(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -178,6 +183,7 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC | |
return ProviderEvaluation.<T>builder() | ||
.errorMessage("flag: " + key + " not found") | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.flagMetadata(fallBackMetadata) | ||
.build(); | ||
} | ||
|
||
|
@@ -186,6 +192,7 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC | |
return ProviderEvaluation.<T>builder() | ||
.errorMessage("flag: " + key + " is disabled") | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.flagMetadata(getFlagMetadata(flag)) | ||
.build(); | ||
} | ||
|
||
|
@@ -232,13 +239,51 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC | |
throw new TypeMismatchError(message); | ||
} | ||
|
||
final ProviderEvaluation.ProviderEvaluationBuilder<T> evaluationBuilder = ProviderEvaluation.<T>builder() | ||
return ProviderEvaluation.<T>builder() | ||
.value((T) value) | ||
.variant(resolvedVariant) | ||
.reason(reason); | ||
.reason(reason) | ||
.flagMetadata(getFlagMetadata(flag)) | ||
.build(); | ||
} | ||
|
||
private ImmutableMetadata getFlagMetadata(FeatureFlag flag) { | ||
if (flag == null) { | ||
return fallBackMetadata; | ||
} | ||
|
||
ImmutableMetadata.ImmutableMetadataBuilder metadataBuilder = ImmutableMetadata.builder(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to have a |
||
if (scope != null) { | ||
metadataBuilder.addString("scope", scope); | ||
} | ||
|
||
for (Map.Entry<String, Object> entry : flag.getMetadata().entrySet()) { | ||
Object value = entry.getValue(); | ||
if (value instanceof Number) { | ||
if (value instanceof Long) { | ||
metadataBuilder.addLong(entry.getKey(), (Long) value); | ||
continue; | ||
} else if (value instanceof Double) { | ||
metadataBuilder.addDouble(entry.getKey(), (Double) value); | ||
continue; | ||
} else if (value instanceof Integer) { | ||
metadataBuilder.addInteger(entry.getKey(), (Integer) value); | ||
continue; | ||
} else if (value instanceof Float) { | ||
metadataBuilder.addFloat(entry.getKey(), (Float) value); | ||
continue; | ||
} | ||
} else if (value instanceof Boolean) { | ||
metadataBuilder.addBoolean(entry.getKey(), (Boolean) value); | ||
continue; | ||
} else if (value instanceof String) { | ||
metadataBuilder.addString(entry.getKey(), (String) value); | ||
continue; | ||
} | ||
throw new IllegalArgumentException("The type of the Metadata entry with key " + entry.getKey() | ||
+ " and value " + entry.getValue() + " is not supported"); | ||
} | ||
|
||
return this.metadata == null | ||
? evaluationBuilder.build() | ||
: evaluationBuilder.flagMetadata(this.metadata).build(); | ||
return metadataBuilder.build(); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a corollary to the inheritance of the flag set metadata, for error cases we should make a "best effort" to return whatever metadata we can - so here we should still return the flag set metadata. We've added this to the spec: https://github.com/open-feature/flagd/pull/1505/files#diff-28ba4b4041b6c39c4b9deb542276312bebdd08f45b39b29d860849d9e8b81a6eR297
The simplest way might be to store the flag set metadata on the flag store and expose it there.
This will greatly help in telemetry and debugging, since we'll have some idea of the flag set, it's version, etc in error reporting and metrics.