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

consolidate default value type comparisons into local bucketing code #247

Draft
wants to merge 3 commits into
base: remove-indirection
Choose a base branch
from

Conversation

ajwootto
Copy link
Contributor

@ajwootto ajwootto commented Apr 22, 2024

  • 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)

Copy link
Contributor Author

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ajwootto and the rest of your teammates on Graphite Graphite

@@ -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)
Copy link
Member

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 != ""
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Comment on lines +318 to +319
case variable_utils.ErrInvalidDefaultValue:
return "INVALID_DEFAULT_VALUE"
Copy link
Member

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"
)

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants