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

feat: multi-provider implementation #1028

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

liran2000
Copy link
Member

@liran2000 liran2000 commented Oct 21, 2024

Readme describes the provider.

References

Signed-off-by: liran2000 <[email protected]>
Signed-off-by: liran2000 <[email protected]>
Signed-off-by: liran2000 <[email protected]>
Signed-off-by: liran2000 <[email protected]>
Signed-off-by: liran2000 <[email protected]>
@liran2000 liran2000 requested a review from a team as a code owner October 21, 2024 11:56
Copy link
Member

@aepfli aepfli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks really cool. But especially the Strategy initialization and the handling of 'exception-less Errors' might be problematic

Function<FeatureProvider, ProviderEvaluation<T>> providerFunction) {
for (FeatureProvider provider: getProviders().values()) {
try {
return providerFunction.apply(provider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all providers throw exceptions sometimes, they return the information in the provider evaluation instead of throwing as exceptions for flows is expensive see open-feature/java-sdk#1095 - applies to all strategies

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated accordingly.

@Slf4j
public class FirstMatchStrategy extends BaseStrategy {

public FirstMatchStrategy(Map<String, FeatureProvider> providers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a problem, as the map is generated in the multi-provider; we need these values to be generated before we pass the strategy to the provider. Maybe we should also put those as parameters to the evaluate method else it will be hard to use any other strategy than the default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it a bit. The providers can be reached via BaseStrategy, as done at MultiProviderTest. What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure, now we do have to separate maps where the state needs to be in sync. this might cause problems. we should centralize this on the provider, what if we change the signature of the evaluate method like

public interface Strategy {
    <T> ProviderEvaluation<T> evaluate(Map<...> providers, String key, T defaultValue, EvaluationContext ctx,
           Function<FeatureProvider, ProviderEvaluation<T>> providerFunction);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is commonly the same providers instance at the multi-provider and the strategy, and it is built as unmodifiable when initialized. Why can this be a problem ? I am fine with your approach above too, just want to understand better first.

another thing, reg. ProviderEvaluation> providerFunction as parameter:
it is pretty straight-forward to implement with it, but I have some concerns that if a custom strategy implementation want to do change the function call and/or arguments, it will limit it. Other approach can be to pass the type. e.g. Boolean.class instead of the function, and convert it to the specific evaluation method. What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i eg. switch to the FirstSuccessful implementation my code would look like

var providers = List.of(...);
var strategy = new FirstSuccessful(providers);
var provider = new MultiProvider(providers, strategy);

but that means that theoretically the providers list could be a different one, or am i missing here something?

Regarding your providerFunction, i do think that this is the clearest way also maintainence wise - trying to hassle with type information adds unnecessary overhead in my opinion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, updated accordingly.

Signed-off-by: liran2000 <[email protected]>
Signed-off-by: liran2000 <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this changelog. A new one should be created by Release Please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -100,6 +100,17 @@
"README.md"
]
},
"providers/multi-provider": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file path is providers/multiprovider. Please either update the path name or this configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, originally I had "multi-provider" like other providers, but it failed validation on Invalid Automatic-Module-Name:

❌ no - allowed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would Maven Central allow invalid names to be uploaded?

Signed-off-by: liran2000 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants