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: add FeatureEnabled to Variant #164

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

jameshartig
Copy link
Contributor

About the changes

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].

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

Closes #159

Important files

api/variant.go

Discussion points

It's a bit unclear what should happen with api.DISABLED_VARIANT. Personally I think GetDefaultVariant should be deprecated and instead users should be checking Enabled on the variant but I'm not sure what other SDKs are doing. I added a new GetDefaultVariantFeatureEnabled method to return the feature-enabled default variant but it's not obvious how anyone outside of the unleash client should be using the GetDefaultVariant method(s). There might need to be more clarification on the methods to discourage or guide usage.

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

@jameshartig

Thank you! This looks good to me.

I agree that the disabled variant should be deprecated. Perhaps the GetDefaultVariant method could be enhanced to take in a parameter and dynamically create the disabled variant with the new FeatureEnabled property? Then we wouldn't have to maintain two methods and two statically defined variants. Would require some additional changes in getVariantWithoutMetrics though.

I'm not actually sure why these methods are public. I can't see any good reason why they should be. I'll make a note of investigating if we can make them private in an upcoming major version.

EDIT: Seems like we merged some adjustments to the tests. Can I ask you to resolve them when you have a free second? Thank you.

@jameshartig
Copy link
Contributor Author

Perhaps the GetDefaultVariant method could be enhanced to take in a parameter and dynamically create the disabled variant with the new FeatureEnabled property?

I thought about that but it would be a breaking change. After thinking about it more, what do you think about removing the GetDefaultVariantFeatureEnabled I added to discourage use, especially if we plan to remove the existing method later?

I can move the new variant to not be defined in the api package so it's not public easier.

My thinking is just that it's always easier to expose something if its needed later than to do the opposite.

@FredrikOseberg
Copy link
Contributor

Perhaps the GetDefaultVariant method could be enhanced to take in a parameter and dynamically create the disabled variant with the new FeatureEnabled property?

I thought about that but it would be a breaking change. After thinking about it more, what do you think about removing the GetDefaultVariantFeatureEnabled I added to discourage use, especially if we plan to remove the existing method later?

I can move the new variant to not be defined in the api package so it's not public easier.

My thinking is just that it's always easier to expose something if its needed later than to do the opposite.

Absolutely. We'd have to bump to 5 in that case. Yeah, I think that's a good idea for now, let's keep the new stuff internal and we can always expose it later if it makes sense.

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
Copy link
Contributor Author

@FredrikOseberg thanks for the quick replies! I updated the PR with those changes and added some clarification to the existing method.

@FredrikOseberg
Copy link
Contributor

Fantastic. Thank you! Merging this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Return variant and feature enabled from a single method
2 participants