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

fix: flexible rollout strategy without context #146

Merged

Conversation

gardleopard
Copy link
Collaborator

The flexible rollout strategy should evaluate default and random stickiness even if context is not provided.

The flexible rollout strategy should evaluate default and random stickiness even if context is not provided.
@coveralls
Copy link

coveralls commented Jul 4, 2023

Pull Request Test Coverage Report for Build 5463576496

  • 29 of 29 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 96.947%

Totals Coverage Status
Change from base Build 5268638037: 0.07%
Covered Lines: 2445
Relevant Lines: 2522

💛 - Coveralls

@gardleopard gardleopard force-pushed the support_random_and_default_stickiness_if_context_is_not_set branch from 2b046a0 to 2341bb7 Compare July 4, 2023 13:53
Copy link
Collaborator

@rarruda rarruda left a comment

Choose a reason for hiding this comment

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

just some 2c.


stickiness = params.fetch('stickiness', 'default')
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)
Copy link
Collaborator

@rarruda rarruda Jul 4, 2023

Choose a reason for hiding this comment

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

This is a bit complex logic. Any chance to try to extract the check into a private method, and use the method name to document what the check is trying to accomplish?


stickiness = params.fetch('stickiness', 'default')
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)
Copy link
Collaborator

@rarruda rarruda Jul 4, 2023

Choose a reason for hiding this comment

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

Suggested change
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)
return false if is_context_invalid?(context, stickiness)
# Context is always valid when using random or default strategies.
def is_context_invalid?(context, stickiness)
    !context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)
end

Copy link
Collaborator

Choose a reason for hiding this comment

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

Feel free to rename the method, not sure it's the most appropriate. Just a suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did it slightly different in order to keep the argument order and be more explicit.


stickiness = params.fetch('stickiness', 'default')
return false unless context_is_sufficient?(stickiness, context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any way we can simplify further by turning the unless to a if ?

Would a name like context_required?/context_needed?/context_valid?/context_invalid? be more descriptive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok i can change it

@@ -32,6 +33,12 @@ def is_enabled?(params = {}, context = nil)

private

def context_is_sufficient?(stickiness, context)
return true if ['random', 'default'].include?(stickiness)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that it will not evaluate the strategy randomly when the stickiness is set to random.

You sure that's the desired behaviour?

Maybe it's worth having a rspec test just for the'stickiness' => 'radom' case? (where a couple of different seeds are hard coded?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this will just let it continue to the resolve stickiness like it did before, this is just a safe guard. It returns to the is_enabled method, not to the caller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

but what happens up the stack, in the is_enabled? method? it returns right away, no? or is the boolean logic a bit hard to read?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it only returns false when its supposed to, if the context is sufficient it continues...

}

expect(strategy.is_enabled?(params, unleash_context)).to be_falsey
expect(strategy.is_enabled?(params, nil)).to be_falsey
Copy link
Collaborator

@rarruda rarruda Jul 5, 2023

Choose a reason for hiding this comment

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

Can you check that this also passes? (if you deem that necessary)

Suggested change
expect(strategy.is_enabled?(params, nil)).to be_falsey
expect(strategy.is_enabled?(params, "invalid_context")).to be_falsey
expect(strategy.is_enabled?(params, nil)).to be_falsey

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice catch, i fixed it now

Copy link
Collaborator

@rarruda rarruda left a comment

Choose a reason for hiding this comment

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

Thanks for the patience. Looks great now!

Copy link
Collaborator

@rarruda rarruda left a comment

Choose a reason for hiding this comment

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

Thanks for the patience. Looks great now!

@gardleopard gardleopard merged commit fa10458 into main Jul 5, 2023
44 checks passed
@gardleopard gardleopard deleted the support_random_and_default_stickiness_if_context_is_not_set branch July 5, 2023 11:23
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

4 participants