Skip to content

feat(OptimizelyConfig): Add new fields to OptimizelyConfig. #322

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

Merged
merged 9 commits into from
Sep 3, 2021

Conversation

yasirfolio3
Copy link
Contributor

@yasirfolio3 yasirfolio3 commented Aug 31, 2021

Summary

The following new public properties are added to OptimizelyConfig:

  • sdkKey
  • environmentKey
  • attributes
  • audiences
  • events
  • experimentRules and deliveryRules to OptimizelyFeature
  • audiences to OptimizelyExperiment

Test plan

All FSC tests OPTIMIZELY_CONFIG_V2 tests should pass.
FSC OptimizelyConfig link

Dependent PR

https://github.com/optimizely/fullstack-sdk-compatibility-suite/pull/526

Issues

Here's the simple snippet when you will run multiple times, it will give you different result. Maps are randomly picked.

package main

import (
	"fmt"
)

func main() {
	m := map[string]int {
	  "key1": 1,
	  "key6": 6,
	  "key4": 4,
	  "key3": 3,
	  "key7": 7,
	  "key2": 2,					
	}
	
	for key, val := range m {
		fmt.Println(key)
		fmt.Println(val)		
	}
	fmt.Println("Hello, playground")
}

https://stackoverflow.com/questions/55925822/why-are-iterations-over-maps-random


rolloutMap := mappers.MapRollouts(datafile.Rollouts)
rollouts, rolloutMap := mappers.MapRollouts(datafile.Rollouts)
events := []entities.Event{}
Copy link
Contributor

Choose a reason for hiding this comment

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

move this code to MapEvents?

featureMap := mappers.MapFeatures(datafile.FeatureFlags, rolloutMap, experimentMap)
features, featureMap := mappers.MapFeatures(datafile.FeatureFlags, rolloutMap, experimentMap)
attributes := []entities.Attribute{}
for _, attribute := range datafile.Attributes {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

@@ -28,6 +28,11 @@ import (
var errEmptyTree = errors.New("empty tree")
var json = jsoniter.ConfigCompatibleWithStandardLibrary

// GetDefaultOperators returns default conditional operators
func GetDefaultOperators() []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

can't you directly assign instead of method.

@msohailhussain msohailhussain marked this pull request as ready for review August 31, 2021 17:28
@msohailhussain msohailhussain requested a review from a team as a code owner August 31, 2021 17:28
@@ -34,12 +35,15 @@ func MapAudiences(audiences []datafileEntities.Audience) map[string]entities.Aud
// @TODO: handle error
func() {}() // cheat the linters

Choose a reason for hiding this comment

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

Should we clean this up maybe, while we are touching the audiences.?

// if audience condition is "NOT" then add "NOT" at start.
// Otherwise check if there is already audience id in serializedAudience
// then append condition between serializedAudience and item
if serializedAudience != "" || cond == "NOT" {
Copy link

@The-inside-man The-inside-man Aug 31, 2021

Choose a reason for hiding this comment

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

Should use a constant for the Operands here.

func evaluateSubAudience(subAudience, serializedAudience, cond *string) {
// Checks if sub audience is empty or not
if *subAudience != "" {
if *serializedAudience != "" || *cond == "NOT" {

Choose a reason for hiding this comment

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

Same comment here for the operands, then we can reuse the constants.

if experiment.AudienceConditions == nil {
return ""
}
return getSerializedAudiences(experiment.AudienceConditions, audiencesByID)

Choose a reason for hiding this comment

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

if getSerializedAudiences returns an empty string when experiment.AudienceConditions is nil then we dont need the first check here and can just use the getSerializedAudiences function.

Copy link

@The-inside-man The-inside-man left a comment

Choose a reason for hiding this comment

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

Overall LGTM just a few suggestions. Please see comments.

Copy link

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

Overall looks great. Some changes suggested.

dustin-sier
dustin-sier approved these changes Sep 1, 2021
Copy link

@dustin-sier dustin-sier left a comment

Choose a reason for hiding this comment

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

LGTM baring changes discussed

Copy link

@dustin-sier dustin-sier left a comment

Choose a reason for hiding this comment

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

This will approve it

Copy link

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

LGTM with nits

Comment on lines 31 to 37
tmpAttribute := entities.Attribute{
ID: attribute.ID,
Key: attribute.Key,
}
_, ok := attributeMap[attribute.ID]
if !ok {
attributeMap[attribute.ID] = entities.Attribute{
ID: attribute.ID,
Key: attribute.Key,
}
attributeMap[attribute.ID] = tmpAttribute
Copy link

Choose a reason for hiding this comment

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

What's the point of this change?

@@ -67,7 +67,7 @@ func TestMapExperiments(t *testing.T) {
rawExperiments := []datafileEntities.Experiment{rawExperiment}
experimentGroupMap := map[string]string{"11111": "15"}

experiments, experimentKeyMap := MapExperiments(rawExperiments, experimentGroupMap)
experimentsId, experimentKeyMap := MapExperiments(rawExperiments, experimentGroupMap)
Copy link

Choose a reason for hiding this comment

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

"experimentsId" name misleading. Shouldn't it be experimentMap or experimentIdMap?

@@ -133,7 +134,7 @@ func TestMapExperimentsWithStringAudienceCondition(t *testing.T) {
rawExperiments := []datafileEntities.Experiment{rawExperiment}
experimentGroupMap := map[string]string{"11111": "15"}

experiments, experimentKeyMap := MapExperiments(rawExperiments, experimentGroupMap)
experimentsIdMap, experimentKeyMap := MapExperiments(rawExperiments, experimentGroupMap)
Copy link

Choose a reason for hiding this comment

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

experimentIdMap? to be consistent with experimentKeyMap

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm

@msohailhussain msohailhussain merged commit 9d97c16 into master Sep 3, 2021
@msohailhussain msohailhussain deleted the yasir/config-v2 branch September 3, 2021 18:41
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