Skip to content

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

Merged
merged 7 commits into from
Jun 13, 2018
Merged

Added BotFiltering #184

merged 7 commits into from
Jun 13, 2018

Conversation

mnoman09
Copy link
Contributor

@mnoman09 mnoman09 commented Jun 5, 2018

  • Added BotFiltering
  • Added unit tests

mnoman09 and others added 2 commits June 4, 2018 17:38
* 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
@mnoman09 mnoman09 closed this Jun 5, 2018
@mnoman09 mnoman09 reopened this Jun 5, 2018
@coveralls
Copy link

coveralls commented Jun 5, 2018

Pull Request Test Coverage Report for Build 528

  • 53 of 53 (100.0%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 89.045%

Totals Coverage Status
Change from base Build 523: 0.2%
Covered Lines: 2219
Relevant Lines: 2492

💛 - Coveralls

@@ -140,6 +145,7 @@ public ProjectConfig(String accountId, String projectId, String version, String
// v4 constructor
public ProjectConfig(String accountId,
boolean anonymizeIP,
Boolean botFiltering,
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 this Boolean and not boolean like anonymizeIP or vice versa?

Copy link
Contributor Author

@mnoman09 mnoman09 Jun 7, 2018

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.

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

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 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
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor

@thomaszurkan-optimizely thomaszurkan-optimizely left a 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,
Copy link
Contributor

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

@thomaszurkan-optimizely
Copy link
Contributor

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()) &&
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 the idea is to allow all attributes starting with $opt_ to go through. This is being very restrictive.

Copy link
Contributor

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,
Copy link
Contributor

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?

@mnoman09
Copy link
Contributor Author

build

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a 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;
Copy link
Contributor

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

Copy link
Contributor

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.
Copy link
Contributor

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;
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 the point @thomaszurkan-optimizely and I were trying to make is that perhaps anonymizeIPalso 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,
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 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())) {
Copy link
Contributor

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(
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 confused by the styling here. Shouldn't this be botFilteringFeature?

@aliabbasrizvi
Copy link
Contributor

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.

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a 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);
Copy link
Contributor

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?

@aliabbasrizvi aliabbasrizvi merged commit 3485072 into master Jun 13, 2018
@aliabbasrizvi aliabbasrizvi deleted the mnoman/BotFiltering branch June 13, 2018 21:15
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.

5 participants