Skip to content

Conversation

@msohailhussain
Copy link
Contributor

Summary

Temporary changes in go-sdk for adding a new method GetDetailedFeatureDecisionUnsafe
This is added to support some agent features. Which will be removed later on.

Testplan

  • All FSC should be passed.

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Small suggestions. Can we add basic tests for this method?

}
}

out, typedError := o.getTypedValue(val, v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: out isn't an ideal variable name IMO. What does it mean?

if decisionInfo.Enabled {
if variable, ok := featureDecision.Variation.Variables[v.ID]; ok {
val = variable.Value
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ok is false, let's log an error.

decisionNotification.Type = notification.AllFeatureVariables

if err = o.notificationCenter.Send(notification.Decision, *decisionNotification); err != nil {
o.logger.Warning("Problem with sending notification")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's log err here so the user can see what the problem was.


func (o *OptimizelyClient) getTypedValue(value string, variable entities.Variable) (out interface{}, err error) {
out = value
switch varType := variable.Type; varType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to use a new variable varType? Does this not work?

Suggested change
switch varType := variable.Type; varType {
switch variable.Type {

Comment on lines 465 to 466
decisionInfo.VariationKey = featureDecision.Variation.Key
decisionInfo.ExperimentKey = featureDecision.Experiment.Key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only assign these when featureDecision.Source == decision.FeatureTest. Keys from a rollout experiment should not be exposed.

Copy link
Contributor

@mikecdavis mikecdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve pending requests made by @mjc1283

return nil
}

func (o *OptimizelyClient) getTypedValue(value string, variable entities.Variable) (out interface{}, err error) {
Copy link
Contributor

@pawels-optimizely pawels-optimizely Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to pass the whole variable ? Seems like only type will be enough. that will also simplify switch statement

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are pretty verbose, @pawels-optimizely any ideas on how to make them more concise?

Requesting 2 changes related to test setup.

Comment on lines 1783 to 1789
type variable struct {
key string
defaultVal string
varVal string
varType entities.VariableType
expected interface{}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same struct type is declared in the previous test. I suggest declaring it only once inside this file.

Comment on lines 1694 to 1722
variables := []variable{
{key: "var_str", defaultVal: "default", varVal: "var", varType: entities.String, expected: "var"},
{key: "var_bool", defaultVal: "false", varVal: "true", varType: entities.Boolean, expected: true},
{key: "var_int", defaultVal: "10", varVal: "20", varType: entities.Integer, expected: 20},
{key: "var_double", defaultVal: "1.0", varVal: "2.0", varType: entities.Double, expected: 2.0},
{key: "var_json", defaultVal: "{}", varVal: "{\"field1\":12.0, \"field2\": \"some_value\"}", varType: entities.JSON,
expected: map[string]interface{}{"field1": 12.0, "field2": "some_value"}},
}

mockConfig := new(MockProjectConfig)
variableMap := make(map[string]entities.Variable)
varVariableMap := make(map[string]entities.VariationVariable)

for i, v := range variables {
id := strconv.Itoa(i)
varVariableMap[id] = entities.VariationVariable{
ID: id,
Value: v.varVal,
}

variableMap[id] = entities.Variable{
DefaultValue: v.defaultVal,
ID: id,
Key: v.key,
Type: v.varType,
}

mockConfig.On("GetVariableByKey", testFeatureKey, v.key).Return(v.varVal, nil)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is repeated in several tests, please factor this out into a helper function.

@pawels-optimizely
Copy link
Contributor

The tests are pretty verbose, @pawels-optimizely any ideas on how to make them more concise?

Requesting 2 changes related to test setup.

the client tests with GetFeatureVariable were rewritten some time back using test tables for variable results. We can try to look other tests and see what else all tests share in common. however, if you are referring to DecisionUnsafe tests then these would be gone anyway.

So to make tests more concise, you init common things in the setup and then use test tables.

@msohailhussain msohailhussain removed their assignment Jun 3, 2020
Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still requesting changes for 2 inline comments from earlier

@mjc1283 mjc1283 merged commit 16569ae into master Jun 4, 2020
@mjc1283 mjc1283 deleted the yasir/exp-var-key branch June 4, 2020 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants