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 variant strategy support #135

Merged
merged 9 commits into from
Aug 3, 2023
Merged

feat: add variant strategy support #135

merged 9 commits into from
Aug 3, 2023

Conversation

sjaanus
Copy link
Contributor

@sjaanus sjaanus commented Aug 2, 2023

No description provided.

@sonatype-lift
Copy link

sonatype-lift bot commented Aug 2, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@@ -15,7 +15,7 @@ jobs:
name: Checkout client specifications
with:
repository: Unleash/client-specification
ref: refs/tags/v4.1.0
ref: refs/tags/v4.3.1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update client spec to latest

api/feature.go Outdated
}

// Get variant for a given feature which is considered as enabled
func (f Feature) GetVariant(ctx *context.Context) *Variant {
if f.Enabled && len(f.Variants) > 0 {
func (f VariantCollection) GetVariant(ctx *context.Context) *Variant {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of feature, now variant can be resolved from Strategy.

}

// isEnabled abstracts away the details of checking if a toggle is turned on or off
// without metrics
func (uc *Client) isEnabled(feature string, options ...FeatureOption) (enabled bool) {
func (uc *Client) isEnabled(feature string, options ...FeatureOption) api.StrategyResult {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of simple boolean, we are now returning complex object, that includes variant.

if s.Variants != nil && len(s.Variants) > 0 {
groupIdValue := s.Parameters[strategy.ParamGroupId]
groupId, ok := groupIdValue.(string)
if !ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If strategy does not have groupId, then bad data and return disabled

}.GetVariant(ctx),
}
} else {
return api.StrategyResult{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If strategy does not have variants, just return true and use old variants.

if len(f.Variants) == 0 {
return defaultVariant
}

return f.GetVariant(ctx)
return api.VariantCollection{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If code runs here, then strategy variants were not found, use old variants

@kwasniew kwasniew self-requested a review August 3, 2023 07:34
@sjaanus sjaanus merged commit 04170c1 into v3 Aug 3, 2023
9 checks passed
@sjaanus sjaanus deleted the variant-strategy branch August 3, 2023 07:37
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.

None yet

2 participants