-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
Just ready for early review
Pull Request Test Coverage Report for Build 5961861904
💛 - Coveralls |
cfa7a92
to
53aadf8
Compare
53aadf8
to
78c1e48
Compare
There was a problem hiding this 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 addenabled?
method - lots of bike shedding (
variants
->variant_definitions
) - need of
==
method / use ofComparable
inVariantDefinition
- tiny issues in debugging message within
evaluate()
@rarruda ready for round two imho:) |
I can take a look a second look at the PR this evening! |
Super, then ill check it tomorrow @rarruda :) |
lib/unleash/feature_toggle.rb
Outdated
|
||
def evaluate(context) | ||
evaluation_result = { | ||
is_enabled: false, |
There was a problem hiding this comment.
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.
lib/unleash/feature_toggle.rb
Outdated
evaluation_result = { | ||
is_enabled: false, | ||
strategy: nil | ||
} |
There was a problem hiding this comment.
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.
lib/unleash/feature_toggle.rb
Outdated
|
||
Unleash.logger.debug "Unleash::FeatureToggle (enabled:#{self.enabled} " \ | ||
"and Strategies combined with contraints returned #{result})" | ||
"and Strategies combined with contraints returned #{evaluation_result[:result]})" |
There was a problem hiding this comment.
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.
lib/unleash/feature_toggle.rb
Outdated
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, |
There was a problem hiding this comment.
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.
lib/unleash/feature_toggle.rb
Outdated
if self.strategies.empty? | ||
evaluation_result[:is_enabled] = true | ||
else | ||
evaluation_result[:strategy] = self.strategies.find(proc{ nil }) do |s| |
There was a problem hiding this comment.
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.
lib/unleash/feature_toggle.rb
Outdated
variant_definitions = evaluation_result[:strategy]&.variant_definitions || self.variant_definitions | ||
variant_definitions = self.variant_definitions if variant_definitions.empty? |
There was a problem hiding this comment.
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)
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? |
There was a problem hiding this 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:
- ruby idiomatic:
is_enabled
->enabled
possibly evenenabled?
==
method is still present- debugging message within
evaluate()
still contains a bug - simplify by converting
.fetch
->.to_h.[] ||
- legibility improvement :
self.strategies.find(proc{ nil }) do
->self.strategies.find do
. - legibility improvement : only one override of values when possible
- legibility improvement : line break
- extract evaluation_result to it's own FeatureEvaluationResult class
- simplify logic in
evaluate()
by making the three scenarios explicit viaif
/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. 😄
resolves #147 |
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]? |
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