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

variants in strategies #148

Merged
merged 15 commits into from
Aug 24, 2023
Merged

variants in strategies #148

merged 15 commits into from
Aug 24, 2023

Conversation

gardleopard
Copy link
Collaborator

@gardleopard gardleopard commented Aug 22, 2023

Description
Implementation of Strategy Variants

Type of change
Please delete options that are not relevant.

New feature (non-breaking change which adds functionality)
How Has This Been Tested?
By running specifications locally

Just ready for early review
@gardleopard gardleopard marked this pull request as ready for review August 22, 2023 10:30
@coveralls
Copy link

coveralls commented Aug 22, 2023

Pull Request Test Coverage Report for Build 5961861904

  • 85 of 85 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.06%) to 97.011%

Totals Coverage Status
Change from base Build 5463810032: 0.06%
Covered Lines: 2499
Relevant Lines: 2576

💛 - Coveralls

@gardleopard gardleopard changed the title variants in strategies passes tests variants in strategies Aug 22, 2023
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.

Note: not linted any of my examples, or ran QA on all suggestions.

But i think it was mostly these things that I noticed at this time:

  • would like a few more tests specially for feature_toggle
  • prefer to keep original tests untouched, unless required.
  • move parsing logic for variant_definitions up the stack.
  • extract evaluation_result to it's own FeatureEvaluationResult class
  • ruby idiomatic: is_enabled -> enabled possibly even add enabled? method
  • lots of bike shedding (variants -> variant_definitions)
  • need of == method / use of Comparable in VariantDefinition
  • tiny issues in debugging message within evaluate()

spec/unleash/activation_strategy_spec.rb Show resolved Hide resolved
lib/unleash/activation_strategy.rb Outdated Show resolved Hide resolved
lib/unleash/variant_definition.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/activation_strategy.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
spec/unleash/feature_toggle_spec.rb Show resolved Hide resolved
@gardleopard
Copy link
Collaborator Author

@rarruda ready for round two imho:)

@rarruda
Copy link
Collaborator

rarruda commented Aug 23, 2023

I can take a look a second look at the PR this evening!

@gardleopard
Copy link
Collaborator Author

Super, then ill check it tomorrow @rarruda :)


def evaluate(context)
evaluation_result = {
is_enabled: false,
Copy link
Collaborator

@rarruda rarruda Aug 23, 2023

Choose a reason for hiding this comment

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

Actually the most ruby idiomatic would be:

  • :enabled?

But if you don't like that suggestion maybe consider:

  • :is_enabled?

Either way would be nice to have your opinion here, even if it is that you intend to keep it as is.

Comment on lines 75 to 78
evaluation_result = {
is_enabled: false,
strategy: nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to re-iterate my recommendation for using an object here in the second review. Even a Struct would do the job. Passing around fixed hashes feels dirty/hacky.


Unleash.logger.debug "Unleash::FeatureToggle (enabled:#{self.enabled} " \
"and Strategies combined with contraints returned #{result})"
"and Strategies combined with contraints returned #{evaluation_result[:result]})"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This bug is still pending resolution.

variant_weight = Unleash::Strategy::Util.get_normalized_number(variant_salt(context, stickiness), self.name, sum_variant_defs_weights)
def variant_from_weights(context, stickiness, variants, group_id)
variant_weight = Unleash::Strategy::Util.get_normalized_number(
variant_salt(context, stickiness), group_id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think it would make it for more readable code if you added a new line here.

if self.strategies.empty?
evaluation_result[:is_enabled] = true
else
evaluation_result[:strategy] = self.strategies.find(proc{ nil }) do |s|
Copy link
Collaborator

Choose a reason for hiding this comment

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

You didn't address this yet.

Comment on lines 58 to 59
variant_definitions = evaluation_result[:strategy]&.variant_definitions || self.variant_definitions
variant_definitions = self.variant_definitions if variant_definitions.empty?
Copy link
Collaborator

@rarruda rarruda Aug 23, 2023

Choose a reason for hiding this comment

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

nit pick/bike shedding for legibility:

(So there is only one override of values, with all the conditions clearly outlined in one line)

Suggested change
variant_definitions = evaluation_result[:strategy]&.variant_definitions || self.variant_definitions
variant_definitions = self.variant_definitions if variant_definitions.empty?
variant_definitions = evaluation_result[:strategy]&.variant_definitions
variant_definitions = self.variant_definitions if variant_definitions.nil? || variant_definitions.empty?

lib/unleash/variant_definition.rb Outdated Show resolved Hide resolved
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.

I think it was mostly these things that I noticed at this time:

  1. ruby idiomatic: is_enabled -> enabled possibly even enabled?
  2. == method is still present
  3. debugging message within evaluate() still contains a bug
  4. simplify by converting.fetch -> .to_h.[] ||
  5. legibility improvement :self.strategies.find(proc{ nil }) do -> self.strategies.find do.
  6. legibility improvement : only one override of values when possible
  7. legibility improvement : line break
  8. extract evaluation_result to it's own FeatureEvaluationResult class
  9. simplify logic in evaluate() by making the three scenarios explicit via if/elsif/else

Some where just not addressed from the previous review.

But I think things will look really great if you can address the things i mentioned. 😄

lib/unleash/variant_definition.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
@gardleopard
Copy link
Collaborator Author

resolves #147

@rarruda
Copy link
Collaborator

rarruda commented Aug 24, 2023

Bikeshedding, det handler om styl. Og er ikke viktig. Men siden man bruke Struct for FeatureEvaluationResult, hadde kanskje ble penere å behandle den som objekt og bruke access metoder, istede av å hente verdi via [:enabled]?

lib/unleash/feature_toggle.rb Outdated Show resolved Hide resolved
@gardleopard gardleopard merged commit a3eabdf into main Aug 24, 2023
44 checks passed
@gardleopard gardleopard deleted the new_client_spec branch August 24, 2023 09:38
@gardleopard gardleopard mentioned this pull request Aug 24, 2023
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

5 participants