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

feat(OptimizelyConfig): Add new fields to OptimizelyConfig #230

Merged
merged 9 commits into from
Aug 24, 2021

Conversation

ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Aug 22, 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.
https://app.travis-ci.com/github/optimizely/fullstack-sdk-compatibility-suite/builds/235923589

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 96.958% when pulling c56a186 on uzair/config-v2 into f15e5f7 on master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 96.958% when pulling c56a186 on uzair/config-v2 into f15e5f7 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 96.958% when pulling c56a186 on uzair/config-v2 into f15e5f7 on master.

@coveralls
Copy link

coveralls commented Aug 22, 2021

Coverage Status

Coverage decreased (-0.9%) to 96.958% when pulling 5304778 on uzair/config-v2 into f15e5f7 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 96.958% when pulling c56a186 on uzair/config-v2 into f15e5f7 on master.

@ozayr-zaviar ozayr-zaviar removed their assignment Aug 23, 2021
@ozayr-zaviar ozayr-zaviar marked this pull request as ready for review August 23, 2021 06:23
@ozayr-zaviar ozayr-zaviar requested a review from a team as a code owner August 23, 2021 06:23
@@ -51,6 +51,37 @@ public function getBotFiltering();
*/
public function getRevision();

/**
* @return string String represnting environment key of the datafile.
Copy link

Choose a reason for hiding this comment

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

Use "representing" instead of "represnting" if you want . If you leave a comment, try to keep in mind the text. This is a minor correction, however--I wouldn't gate an entire review on it.

Copy link
Contributor

@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.

Looks good. Need some changes.

Comment on lines 274 to 275
$this->audiences = isset($config['audiences']) ? $config['audiences'] : [];
$this->events = $config['events'] ?: [];
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 we "?:" consistently for all these props?

Comment on lines 234 to 273
$this->_botFiltering = isset($config['botFiltering'])? $config['botFiltering'] : null;
$this->attributes = isset($config['attributes']) ? $config['attributes'] : [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming rule? I see inconsistency with and without "_" prefix though they're all private

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 39 to 41
* Map of rollout Experiments Keys to OptimizelyExperiments.
*
* @var <String, OptimizelyExperiment> associative array
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Map of rollout Experiments Keys to OptimizelyExperiments.
*
* @var <String, OptimizelyExperiment> associative array
* Array of delivery rules.
*
* @var [OptimizelyExperiment]

Comment on lines 32 to 34
* Map of Experiment Keys to OptimizelyExperiments.
*
* @var <String, OptimizelyExperiment> associative array
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Map of Experiment Keys to OptimizelyExperiments.
*
* @var <String, OptimizelyExperiment> associative array
* Array of experiment rules.
*
* @var [OptimizelyExperiment]

Comment on lines 214 to 215
$experimentMapFlag1 = $optimizelyConfig->getFeaturesMap()['flag1']->getExperimentsMap(); // 9300000007569
$experimentMapFlag2 = $optimizelyConfig->getFeaturesMap()['flag2']->getExperimentsMap(); // 9300000007573
Copy link
Contributor

Choose a reason for hiding this comment

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

Change these to use "->getExperimentRules()" instead of "->getExperimentsMap()"

array("3468206642"),
array('and', array('or', '3468206642', '3988293899'), '3988293898'),
array('and', 'and'),
array(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have one more test for non-matching audience-id: '[“or”, “1”, “100000”]' in TDD

}

public function testgetConfigAudiences()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see tests for validating typeAudiences and audiences merged properly (filtering duplicate ones and $opt_dummy_audience? Please add if missed.

* @var string sdkKey of the config.
*/
private $sdkKey;

Copy link
Contributor

Choose a reason for hiding this comment

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

(1) add warning message about duplicated keys to "experimentsMap" of OptimizelyConfig
(2) add deprecation warning to "getExperimentsMap" of OptimizelyFeature.

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

Overall Comment about Variable and Method doc comments. I see multiple patterns of commenting. Can we decide and use one. In some cases, there is a comment line and a return type line. In others, there is a single line which casually talks about a type.

/**
* list of Typed Audiences that will be parsed from the datafile
*
* @var [typed_audience]
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure but assuming it represents the type, should'nt it be [AUDIENCE] instead of [typed_audience]

Comment on lines 561 to 566
return array_filter(
array_values($this->_experimentIdMap),
function ($experiment) use ($rolloutExperimentIds) {
return !in_array($experiment->getId(), $rolloutExperimentIds);
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this diff needed. it looks like only indentation/formatting change?

Comment on lines +65 to +68
* Array of events as OptimizelyEvent.
*
* @var [OptimizelyEvent]
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

As a common pattern, i see two ways of variable and function doc comments here. one is this and one is along the lines of @var string sdkKey of the config. why two standards and not one?

{
$finalAudiences = [];
$uniqueIdsMap = [];
$normalAudiences = $this->projectConfig->getAudiences();
Copy link
Contributor

Choose a reason for hiding this comment

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

normalAudiences sounds like an awkward variable name. You can call it audiences?

Comment on lines 178 to 188
foreach ($audiencesArray as $audience) {
$id = $audience['id'];
if ($id != '$opt_dummy_audience') {
$optlyAudience = new OptimizelyAudience(
$id,
$audience['name'],
$audience['conditions']
);
array_push($finalAudiences, $optlyAudience);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You dont probably need a third loop if you keep building the finalAudiences array while iterating through the first two

Comment on lines 355 to 359
if ($finalAudiences !== '') {
$finalAudiences = $finalAudiences . ' ';
} else {
$finalAudiences = $finalAudiences;
}
Copy link
Contributor

@zashraf1985 zashraf1985 Aug 23, 2021

Choose a reason for hiding this comment

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

Suggested change
if ($finalAudiences !== '') {
$finalAudiences = $finalAudiences . ' ';
} else {
$finalAudiences = $finalAudiences;
}
if ($finalAudiences !== '') {
$finalAudiences .= ' ';
}

}
}
// Checks if sub audience is empty or not
if (strval($subAudience !== '')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is strVal needed when you are already initializing it to empty string at the top?

*
* @param string feature rollout id.
*
* @return array of optimizelyExperiments as delivery rules .
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @return array of optimizelyExperiments as delivery rules .
* @return array of optimizelyExperiments as delivery rules.

Comment on lines +437 to +438
$expId = $exp->getId();
$expKey = $exp->getKey();
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Why do you need to assign these to vars. Cant they be used directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But these values are again required below to assign values in $experimentsKeyMap and $experimentsIdMap

}

/**
* @return string event conditions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you correct the comment? copy paste error maybe?

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.

initial review.

$this->_revision = $config['revision'];
$this->_sendFlagDecisions = isset($config['sendFlagDecisions']) ? $config['sendFlagDecisions'] : false;

$groups = $config['groups'] ?: [];
$experiments = $config['experiments'] ?: [];
$events = $config['events'] ?: [];
Copy link
Contributor

Choose a reason for hiding this comment

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

don't understand why these are removed from here. all three.

$typedAudiences = $this->projectConfig->getTypedAudiences();
$audiencesArray = $typedAudiences;
foreach ($audiencesArray as $key => $typedAudience) {
$uniqueIdsMap[$typedAudience['id']] = $typedAudience['id'];
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 we push it in array and check if that id exists or not?

*
* @return array of OptimizelyEvents.
*/
protected function getConfigAudiences()
Copy link
Contributor

Choose a reason for hiding this comment

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

please revise the variable names.
finalAudiences, normalAudiences seems weird.

@@ -145,6 +249,7 @@ protected function getVariablesMap(Experiment $experiment, Variation $variation)
}

$featureFlag = $this->experimentIdFeatureMap[$experimentId];

Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line.

$subAudience = $this->getSerializedAudiences($var);

$subAudience = '(' . $subAudience . ')';
} elseif (in_array($var, array('and', 'or', 'not'), true)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have 'and', 'or', 'not' in constants.

$optExp = new OptimizelyExperiment(
$expId,
$expKey,
$this->getVariationsMap($exp),
Copy link
Contributor

Choose a reason for hiding this comment

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

i am not sure, when we get variation, without passing featureFlag, how featurevariables will be merged.

Copy link
Contributor

@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.

All changes look good.
Deprecation warning for "getExperimentsMap()" should be moved from OptimizelyConfig to OptimizelyFeature.

@@ -124,6 +128,7 @@ public function getDatafile()
*/
public function getExperimentsMap()
{
# This experimentsMap is deprecated. Use experimentRules and deliveryRules instead.
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 deprecation message to "getExperimentsMap()" of OptimizelyFeature. The same-named one here for OptimizelyConfig is not deprecated.

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

Looks Good! Great work.

Copy link
Contributor

@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

@msohailhussain msohailhussain dismissed their stale review August 24, 2021 22:58

zeeshan and jae already done, dismissing my review.

@msohailhussain msohailhussain merged commit 930400f into master Aug 24, 2021
@msohailhussain msohailhussain deleted the uzair/config-v2 branch August 24, 2021 22:58
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