-
Notifications
You must be signed in to change notification settings - Fork 19
feat(decide): Adding support for decide options and decision reasons. #298
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
Conversation
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 understand that this PR extends existing interface to support changes for new decide APIs. It looks good in that sense.
Not sure if you plan to add them later, but I do not see collecting log messages into DecisionReasons.
|
||
// AddError appends given message to the error list. | ||
func (o *DefaultDecisionReasons) AddError(format string, arguments ...interface{}) { | ||
o.mutex.Lock() |
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.
Decision reasons should be managed per decision, so no need for concurrency control.
"github.com/optimizely/go-sdk/pkg/entities" | ||
"github.com/optimizely/go-sdk/pkg/logging" | ||
) | ||
|
||
// CompositeFeatureService is the default out-of-the-box feature decision service | ||
type CompositeFeatureService struct { | ||
featureServices []FeatureService | ||
logger logging.OptimizelyLogProducer | ||
logger logging.OptimizelyLogProducer |
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.
remove extra spaces
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 indentation fix is on purpose, it should be aligned with the text above.
pkg/decision/evaluator/condition.go
Outdated
"github.com/optimizely/go-sdk/pkg/decision/evaluator/matchers" | ||
"github.com/optimizely/go-sdk/pkg/entities" | ||
"github.com/optimizely/go-sdk/pkg/logging" | ||
) | ||
|
||
// ItemEvaluator evaluates a condition against the given user's attributes | ||
type ItemEvaluator interface { | ||
Evaluate(interface{}, *entities.TreeParameters) (bool, error) | ||
Evaluate(interface{}, *entities.TreeParameters, decide.OptimizelyDecideOptions, decide.DecisionReasons) (bool, error) |
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.
No need for OptimizelyDecideOptions here
pkg/decision/evaluator/condition.go
Outdated
@@ -61,7 +61,7 @@ func (c CustomAttributeConditionEvaluator) Evaluate(condition entities.Condition | |||
return false, fmt.Errorf(`invalid Condition matcher "%s"`, condition.Match) |
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.
Don't we need this to reasons? Basically, we should add all error/warning/info (and some of debug) log messages into reasons when they're decision-related.
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.
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.
we can probably put it within the reasons
pkg/decision/evaluator/condition.go
Outdated
// We should only be evaluating custom attributes | ||
|
||
if condition.Type != customAttributeType { | ||
|
||
c.logger.Warning(fmt.Sprintf(logging.UnknownConditionType.String(), condition.StringRepresentation)) | ||
return false, fmt.Errorf(`unable to evaluate condition of type "%s"`, condition.Type) |
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.
Don't we need add this message to reasons?
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.
|
||
// ToReport returns reasons to be reported. | ||
func (o *DefaultDecisionReasons) ToReport() []string { | ||
o.mutex.RLock() |
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.
Same. no need for mutex control here.
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.
why do we need mutex here ?
s.mockExperimentService.On("GetDecision", s.testDecisionContext, testUserContext).Return(s.testComputedDecision, nil) | ||
s.options = decide.OptimizelyDecideOptions{} | ||
s.reasons = decide.NewDecisionReasons(s.options) | ||
s.mockExperimentService.On("GetDecision", s.testDecisionContext, testUserContext, s.options, s.reasons).Return(s.testComputedDecision, nil) | ||
} | ||
|
||
func (s *PersistingExperimentServiceTestSuite) TestNilUserProfileService() { |
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.
Not sure if it's planned to add later, but we need test cases to validate "IgnoreUPS" option here.
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.
yes these tests are included in the succeeding PR. #299
yes i was waiting for one of the PR's on other sdk's to finalize so that i can add messages to decision reasons, will do that in another PR. |
s.logger.Debug(fmt.Sprintf(logging.ExperimentAudiencesEvaluatedTo.String(), experiment.Key, evalResult)) | ||
if !evalResult { | ||
s.logger.Debug(fmt.Sprintf(logging.UserNotInExperiment.String(), userContext.ID, experiment.Key)) | ||
experimentDecision.Reason = reasons.FailedAudienceTargeting | ||
experimentDecision.Reason = pkgReasons.FailedAudienceTargeting |
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 comment was originally added by @jaeopt but got accidentally deleted:
This message should go into new DecisionReasons as well.
Wondering how we can merge this existing "Reason" with new DecisionReasons.
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.
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.
yeah, these make sense
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.
LGTM - I expect all reasons collecting in new PRs
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.
reasons are passed to Evaluator, condition and Matchers, but I don't think they are used.
Please either clean them up (remove them) or use them.
ExcludeVariables: true, | ||
} | ||
reasons := NewDecisionReasons(options) | ||
reasons.AddError("error message") |
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.
can you add a test with arguments ?
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.
done 👍
We will be using them in a separate PR just dedicated to reasons with all the unit tests. 👍 |
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.
lgtm
pkg/client/client.go
Outdated
@@ -49,6 +49,8 @@ type OptimizelyClient struct { | |||
defaultDecideOptions decide.OptimizelyDecideOptions | |||
} | |||
|
|||
// Decide API |
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.
Please remove
Summary
A part of multiple PRs for Decide API:
Tests