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

Return variant and feature enabled from a single method #159

Closed
jameshartig opened this issue Dec 7, 2023 · 5 comments · Fixed by #164 or #166
Closed

Return variant and feature enabled from a single method #159

jameshartig opened this issue Dec 7, 2023 · 5 comments · Fixed by #164 or #166

Comments

@jameshartig
Copy link
Contributor

jameshartig commented Dec 7, 2023

Describe the feature request

Currently there's no way with a single call to differentiate between a feature being disabled and no variants on the feature. Both of those cases return the default variant. Ideally there would be a call that returns (variant, enabled).

Background

We would like to make a single call and understand if a feature is enabled and what variant is applicable, if any. Instead we have to make 2 calls to understand the distinction. I'm surprised that this hasn't been brought up already and I'm curious how others are using this library in production with variants.

Solution suggestions

There are 2 potential solutions I see:

  1. Fixing the fallback options. Currently the descriptions of WithVariantFallback and WithVariantFallbackFunc are wrong. Those are actually used when a feature is not found. I filed this as WithVariantFallback and WithVariantFallbackFunc are called when feature isn't found #160. A new option could be added that is used to fallback when a feature is not found and the existing fallbacks could be correctly used when there are no variants on the feature. This would be a breaking change though, but I'm not sure how many people realize the existing options are not doing what they say they do.
  2. Add a new method that returns a variant and if it's enabled or not. This could also return a struct similar to the StrategyResult struct so it could be added to in the future if more things need to be returned.

Personally we're fine with either but the options being broken does seem like it should be fixed and might lend itself to just adding a new option.

@jameshartig
Copy link
Contributor Author

If we can decide on a path I'm fine doing the change and submitting a PR.

@jameshartig
Copy link
Contributor Author

jameshartig commented Dec 7, 2023

I'm actually leaning more towards the second path because we also need the underlying api.Feature to know what type of feature it is (see #162). We will have some special logic for kill-switch-type features. In #161 I mentioned it might be useful to return the api.Feature in the api.StrategyResult method. If we added a new method that returned api.StrategyResult with a Feature then that would solve both of those.

@FredrikOseberg
Copy link
Contributor

Describe the feature request

Currently there's no way with a single call to differentiate between a feature being disabled and no variants on the feature. Both of those cases return the default variant. Ideally there would be a call that returns (variant, enabled).

Background

We would like to make a single call and understand if a feature is enabled and what variant is applicable, if any. Instead we have to make 2 calls to understand the distinction. I'm surprised that this hasn't been brought up already and I'm curious how others are using this library in production with variants.

Solution suggestions

There are 2 potential solutions I see:

  1. Fixing the fallback options. Currently the descriptions of WithVariantFallback and WithVariantFallbackFunc are wrong. Those are actually used when a feature is not found. I filed this as WithVariantFallback and WithVariantFallbackFunc are called when feature isn't found #160. A new option could be added that is used to fallback when a feature is not found and the existing fallbacks could be correctly used when there are no variants on the feature. This would be a breaking change though, but I'm not sure how many people realize the existing options are not doing what they say they do.
  2. Add a new method that returns a variant and if it's enabled or not. This could also return a struct similar to the StrategyResult struct so it could be added to in the future if more things need to be returned.

Personally we're fine with either but the options being broken does seem like it should be fixed and might lend itself to just adding a new option.

@jameshartig

Thanks for pointing this out, it's definitely a gap we're looking to close. When this SDK was first created it was based on our node-client, which had this interface already. As we have SDKs in multiple different languages, we do strive to keep the API surface as similar as possible, both to avoid SDK bloat but also to keep the mental model clean across language boundaries.

Expanding the API for one SDK is really something we want to try to avoid. Especially since we have started this journey already in our python SDK here. Would it be acceptable for now to add a similar property to the GetVariant response?

Look forward to hearing from you

@jameshartig
Copy link
Contributor Author

Would it be acceptable for now to add a similar property to the GetVariant response?

You're talking about adding IsFeatureEnabled to api.Variant? Yes, that seems fine. I appreciate the quick reply!

@FredrikOseberg
Copy link
Contributor

FredrikOseberg commented Dec 8, 2023 via email

jameshartig added a commit to jameshartig/unleash-client-go that referenced this issue Dec 8, 2023
FeatureEnabled is similar to Enabled except in the case where the feature
is enabled but there are no variants defined. This follows the client
specification case [1].

Fixes Unleash#159

[1] https://github.com/Unleash/client-specification/blob/c0169d7ace35db66cdf41a7b1b4e390a4a843c3b/specifications/08-variants.json#L448
jameshartig added a commit to jameshartig/unleash-client-go that referenced this issue Dec 11, 2023
FeatureEnabled is similar to Enabled except in the case where the feature
is enabled but there are no variants defined. This follows the client
specification case [1].

Fixes Unleash#159

[1] https://github.com/Unleash/client-specification/blob/c0169d7ace35db66cdf41a7b1b4e390a4a843c3b/specifications/08-variants.json#L448
FredrikOseberg pushed a commit that referenced this issue Dec 12, 2023
FeatureEnabled is similar to Enabled except in the case where the feature
is enabled but there are no variants defined. This follows the client
specification case [1].

Fixes #159

[1] https://github.com/Unleash/client-specification/blob/c0169d7ace35db66cdf41a7b1b4e390a4a843c3b/specifications/08-variants.json#L448
@github-project-automation github-project-automation bot moved this from New to Done in Issues and PRs Dec 12, 2023
jameshartig added a commit to jameshartig/unleash-client-go that referenced this issue Dec 13, 2023
FeatureEnabled is similar to Enabled except in the case where the feature
is enabled but there are no variants defined. This follows the client
specification case [1].

Fixes Unleash#159

[1] https://github.com/Unleash/client-specification/blob/c0169d7ace35db66cdf41a7b1b4e390a4a843c3b/specifications/08-variants.json#L448
FredrikOseberg added a commit that referenced this issue Dec 13, 2023
* feat: add FeatureEnabled to Variant and fix spec testing

FeatureEnabled is similar to Enabled except in the case where the feature
is enabled but there are no variants defined. This follows the client
specification case [1].

Fixes #159

[1] https://github.com/Unleash/client-specification/blob/c0169d7ace35db66cdf41a7b1b4e390a4a843c3b/specifications/08-variants.json#L448

* fix: add workflow to build PRs

---------

Co-authored-by: Fredrik Oseberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
2 participants