-
Notifications
You must be signed in to change notification settings - Fork 4
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
consolidate default value type comparisons into local bucketing code #247
base: remove-indirection
Are you sure you want to change the base?
consolidate default value type comparisons into local bucketing code #247
Conversation
ajwootto
commented
Apr 22, 2024
•
edited
Loading
edited
- move the value type comparison happening in client.go into the bucketing code and report on it with a variable defaulted (before if this case was hit it would be tracked as a variable evaluated)
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@@ -212,7 +214,9 @@ func GenerateBucketedConfig(sdkKey string, user api.PopulatedUser, clientCustomD | |||
}, nil | |||
} | |||
|
|||
func VariableForUser(sdkKey string, user api.PopulatedUser, variableKey string, expectedVariableType string, eventQueue *EventQueue, clientCustomData map[string]interface{}) (variableType string, variableValue any, err error) { | |||
func VariableForUser(sdkKey string, user api.PopulatedUser, variableKey string, defaultValue interface{}, eventQueue *EventQueue, clientCustomData map[string]interface{}) (variableType string, variableValue any, err error) { | |||
expectedVariableType, err := variable_utils.VariableTypeFromValue(variableKey, defaultValue, true) |
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.
check the error result here
@@ -222,9 +226,17 @@ func VariableForUser(sdkKey string, user api.PopulatedUser, variableKey string, | |||
return "", nil, err | |||
} | |||
|
|||
if !isVariableTypeValid(variableType, expectedVariableType) && expectedVariableType != "" { | |||
typeFieldMismatch := !isVariableTypeValid(variableType, expectedVariableType) && expectedVariableType != "" |
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 kind of one liner is discouraged - and should be done in the if statement to make it more transparent.
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 found it so much harder to read the if statement condition when i inlined it all
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.
if you really want to make it oneliner'd - move the explicit variable call checks first to make it more visible.
case variable_utils.ErrInvalidDefaultValue: | ||
return "INVALID_DEFAULT_VALUE" |
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 should make these accessible constants still.
"fmt" | ||
"reflect" | ||
) | ||
|
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 could add the default reasons 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.
feels like they should go in the same place as the error definitions that cause them, which is all in the bucketing package
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.
really it doesn't matter where - they can be imported from anywhere