-
Notifications
You must be signed in to change notification settings - Fork 18
refact(audience-logs): Added and refactored audience evaluation logs. #280
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
| @@ -1,45 +0,0 @@ | |||
| /**************************************************************************** | |||
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 deleted this file?
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 file wasn't being used anywhere throughout the sdk and was throwing syntax errors due to the changes made in this PR.
pkg/decision/evaluator/condition.go
Outdated
| if condition.Type != customAttributeType { | ||
| return false, fmt.Errorf(`unable to evaluator condition of type "%s"`, condition.Type) | ||
|
|
||
| c.logger.Warning(fmt.Sprintf(string(logging.UnknownConditionType), condition.StringRepresentation)) |
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 string is needed? string(logging.UnknownConditionType)
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.
Since UnknownConditionType is of custom type, we must convert it to string before formatting.
pkg/decision/evaluator/condition.go
Outdated
| case exactMatchType: | ||
| matcher = matchers.ExactMatcher{ | ||
| Condition: condition, | ||
| Logger: c.logger, |
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 logger not passed in existsMatchType
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 logs were required inside exists.
msohailhussain
left a comment
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.
first pass
pkg/decision/evaluator/condition.go
Outdated
| Logger: c.logger, | ||
| } | ||
| default: | ||
| c.logger.Warning(fmt.Sprintf(string(logging.UnknownMatchType), condition.StringRepresentation)) |
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 use format specifier.
| } | ||
|
|
||
| return false, fmt.Errorf("audience condition %s evaluated to NULL because the condition value type is not supported", m.Condition.Name) | ||
| return matchGtOrLt(user, m.Condition, m.Logger, 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.
Why we didn't only add log 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.
since both gt and lt matchers were very similar, linter was throwing lines are duplicate error.
| } | ||
|
|
||
| // GetAttribute returns the value for the specified attribute name in the attributes map. Returns error if not found. | ||
| func (u UserContext) GetAttribute(attrName string) (interface{}, 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.
Why added this method?
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.
for InvalidAttributeValueType log, we required the raw attribute value to log its original type.
pkg/logging/log_messages.go
Outdated
| @@ -0,0 +1,60 @@ | |||
| /**************************************************************************** | |||
| * Copyright 2019-2020, Optimizely, Inc. and contributors * | |||
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.
Is it started in 2019?
| package logging | ||
|
|
||
| // LogMessage defines string type for log messages | ||
| type LogMessage string |
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 am not sure if this is the right location to add log messages. Let's discuss offline.
pkg/decision/evaluator/condition.go
Outdated
| if condition.Type != customAttributeType { | ||
| return false, fmt.Errorf(`unable to evaluator condition of type "%s"`, condition.Type) | ||
|
|
||
| c.logger.Warning(fmt.Sprintf(string(logging.UnknownConditionType), condition.StringRepresentation)) |
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 don't really need two Strings. Just pass the same in fmt.Errorf
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 will confirm and let you know.
…o-sdk into yasir/fix-audienceeval-logs
|
|
||
| if !user.CheckAttributeExists(m.Condition.Name) { | ||
| m.Logger.Debug(fmt.Sprintf(logging.NullUserAttribute.String(), m.Condition.StringRepresentation, m.Condition.Name)) | ||
| return false, fmt.Errorf(`no attribute named "%s"`, m.Condition.Name) |
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 we don't return same logging message?
mikecdavis
left a comment
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, one nit on the matchGtOrLt refactor.
| return matchGtOrLt(condition, user, logger, true) | ||
| } | ||
|
|
||
| func matchGtOrLt(condition entities.Condition, user entities.UserContext, logger logging.OptimizelyLogProducer, gtMatch bool) (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.
Nit, but If we make this a pure comparator and return (int, bool) e.g. -1, 0, 1, then we can drop the gtMatch bool which is a bit awkward. Then consumers would look like:
func GtMatcher(condition entities.Condition, user entities.UserContext, logger logging.OptimizelyLogProducer) (bool, error) {
res, err := compare(condition, user, logger)
if err := nil {
return false, err
}
return res > 0, nil
}
func LtMatcher(condition entities.Condition, user entities.UserContext, logger logging.OptimizelyLogProducer) (bool, error) {
res, err := compare(condition, user, logger)
if err := nil {
return false, err
}
return res < 0, nil
}This would match the logic in the semver PR here
msohailhussain
left a comment
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
Summary
Testplan
Performance
There was no significant hit observed.
Used this code to measure performance.
Issues
https://optimizely.atlassian.net/browse/OASIS-6816