-
Notifications
You must be signed in to change notification settings - Fork 32
Added BotFiltering #184
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
Added BotFiltering #184
Conversation
mnoman09
commented
Jun 5, 2018
- Added BotFiltering
- Added unit tests
* Updated and added botfiltering * Added BotFilteringAttribute attribute to fix existing unit tests * Added enum of reserved attributes
using startsWith instead of indexof in project config
Pull Request Test Coverage Report for Build 528
💛 - Coveralls |
@@ -140,6 +145,7 @@ public ProjectConfig(String accountId, String projectId, String version, String | |||
// v4 constructor | |||
public ProjectConfig(String accountId, | |||
boolean anonymizeIP, | |||
Boolean botFiltering, |
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.
Why is this Boolean
and not boolean
like anonymizeIP
or vice versa?
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.
In Java, "Boolean" is nullable and "boolean" is not. we need botfiltering variable to be nullable so that if botfiltering is not in datafile than we assign null value to it and we won't add botfiltering attribute in attributesList.
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.
The interesting thing about what you are saying here is that anonymizeIP is also optional based on datafile type (for instance v2 does not contain anonymizeIP).
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.
Yeah precisely. Shouldn't anonymizeIP
be Boolean
then?
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.
anonymizeIp default value is false and we are not checking in our sdk if its null it's just getting passed false if not set, but for botfiltering we have three values which are True, False and Null, if botFiltering value is null than we don't add its attribute in list.
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.
The same holds true for anonymizeIP
as it can be null in an older datafile.
@@ -285,6 +292,35 @@ public Experiment getExperimentForKey(@Nonnull String experimentKey, | |||
return groupExperiments; | |||
} | |||
|
|||
/** | |||
* Checks is attributeKey is reserved or not and is it exist in attributeKeyMapping |
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.
nit. and ...if it exists..
and not ...is it exist...
*/ | ||
package com.optimizely.ab.internal; | ||
|
||
public enum ReservedAttributeKey { |
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.
Perhaps call it ControlAttribute
like other SDKs.
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.
Can we also make sure it passes compatibility tests?
@@ -140,6 +145,7 @@ public ProjectConfig(String accountId, String projectId, String version, String | |||
// v4 constructor | |||
public ProjectConfig(String accountId, | |||
boolean anonymizeIP, | |||
Boolean botFiltering, |
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.
The interesting thing about what you are saying here is that anonymizeIP is also optional based on datafile type (for instance v2 does not contain anonymizeIP).
build |
@@ -765,7 +766,8 @@ public UserProfileService getUserProfileService() { | |||
Map<String, Attribute> attributeKeyMapping = projectConfig.getAttributeKeyMapping(); | |||
for (Map.Entry<String, String> attribute : attributes.entrySet()) { | |||
if (!attributeKeyMapping.containsKey(attribute.getKey()) && | |||
attribute.getKey() != com.optimizely.ab.bucketing.DecisionService.BUCKETING_ATTRIBUTE) { | |||
!attribute.getKey().equals(ControlAttribute.BUCKETING_ATTRIBUTE.toString()) && |
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 think the idea is to allow all attributes starting with $opt_
to go through. This is being very restrictive.
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.
Please note this will currently filter $opt_bot_filtering
. As a result the functionality is broken.
@@ -140,6 +145,7 @@ public ProjectConfig(String accountId, String projectId, String version, String | |||
// v4 constructor | |||
public ProjectConfig(String accountId, | |||
boolean anonymizeIP, | |||
Boolean botFiltering, |
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.
Yeah precisely. Shouldn't anonymizeIP
be Boolean
then?
…ibute which starts with $opt reserved key
build |
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 am still seeing issues when I run the end-to-end tests on this @msohailhussain . Details in JIRA. Can you try some manual testing at your end?
@@ -25,6 +25,7 @@ | |||
import com.optimizely.ab.error.ErrorHandler; | |||
import com.optimizely.ab.internal.ExperimentUtils; | |||
|
|||
import com.optimizely.ab.internal.ControlAttribute; |
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.
nit. This should be on line 27 closer to other Optimizely packages
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.
And then a new line after that.
@@ -749,7 +750,7 @@ public UserProfileService getUserProfileService() { | |||
* | |||
* @param projectConfig the current project config | |||
* @param attributes the attributes map to validate and potentially filter. The reserved key for bucketing id | |||
* {@link DecisionService#BUCKETING_ATTRIBUTE} is kept. | |||
* {@link DecisionService#{ProjectConfig.RESERVED_ATTRIBUTE_PREFIX} is kept. |
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.
DecisionService
should not be mentioned here any more right?
@@ -73,6 +74,7 @@ public String toString() { | |||
private final String revision; | |||
private final String version; | |||
private final boolean anonymizeIP; |
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 think the point @thomaszurkan-optimizely and I were trying to make is that perhaps anonymizeIP
also needs to be Boolean
and not boolean
@@ -140,6 +145,7 @@ public ProjectConfig(String accountId, String projectId, String version, String | |||
// v4 constructor | |||
public ProjectConfig(String accountId, | |||
boolean anonymizeIP, | |||
Boolean botFiltering, |
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.
The same holds true for anonymizeIP
as it can be null in an older datafile.
*/ | ||
public String getAttributeId(ProjectConfig projectConfig, String attributeKey) { | ||
String attributeIdOrKey = null; | ||
if (!attributeKey.equals(ControlAttribute.BOT_FILTERING_ATTRIBUTE.toString())) { |
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 check is unnecessary. I know why you put it here, but it is an overkill.
com.optimizely.ab.event.internal.payload.Attribute.CUSTOM_ATTRIBUTE_TYPE, | ||
"Chrome"); | ||
|
||
com.optimizely.ab.event.internal.payload.Attribute BotFilteringFeature = new com.optimizely.ab.event.internal.payload.Attribute( |
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 am confused by the styling here. Shouldn't this be botFilteringFeature
?
I think I know the problem now. You need to pass in bot filtering in attributes as boolean and not as string. That is a requirement of the API. |
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.
LGTM.
*/ | ||
public String getAttributeId(ProjectConfig projectConfig, String attributeKey) { | ||
String attributeIdOrKey = null; | ||
com.optimizely.ab.config.Attribute attribute = projectConfig.getAttributeKeyMapping().get(attributeKey); |
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.
Why the inline import? Why not at the head of the file?