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

Introduce Bot Filtering #121

Merged
merged 13 commits into from
Jun 28, 2018
Merged

Introduce Bot Filtering #121

merged 13 commits into from
Jun 28, 2018

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented May 31, 2018

No description provided.

@coveralls
Copy link

coveralls commented May 31, 2018

Coverage Status

Coverage increased (+0.005%) to 99.653% when pulling fe607b4 on oakbani/bot-filtering into 6ed11d7 on master.

@@ -172,19 +182,39 @@ def _get_attributes(self, attributes):
if not attributes:
return []

for attribute_key in attributes.keys():
for attribute_key in sorted(attributes.keys()):
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 sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

attributes is a dict. Order of keys is not guaranteed to be same for all python versions. Hence for eventpayload unit tests to pass for all versions, we need to ensure that they get appended in the same order.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does ordering matter? Let us not do this. It seems unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aliabbasrizvi attributes is a dict. Order of keys is not guaranteed to be same for all python versions. Hence for eventpayload unit tests to pass for all versions, we need to ensure that they get appended in the same order.
https://travis-ci.org/optimizely/python-sdk/builds/389076889

attribute = self.config.get_attribute(attribute_key)
if attribute:
# Check for reserved attributes
reserved_attrs = [ReservedAttributes.BUCKETING_ID, ReservedAttributes.USER_AGENT]
Copy link
Contributor

Choose a reason for hiding this comment

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

this must be outside, as it will be initialized again and again.


# Append Bot Filtering Attribute
attribute_key = ReservedAttributes.BOT_FILTERING
params.append({
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add condition which was placed in javascript code. If no botFiltering is given or old datafile is used, in that case it shouldn't send the value of botFiltering.
https://github.com/optimizely/javascript-sdk/pull/99/files#diff-1fbd9d0f02956a420aeef6959fc24caaR73

@@ -56,6 +56,7 @@ def __init__(self, datafile, logger, error_handler):
self.feature_flags = config.get('featureFlags', [])
self.rollouts = config.get('rollouts', [])
self.anonymize_ip = config.get('anonymizeIP', False)
self.bot_filtering = config.get('botFiltering', False)
Copy link
Contributor

Choose a reason for hiding this comment

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

default is NULL, not false. Please recheck it.

})

else:
attribute = self.config.get_attribute(attribute_key)
if attribute:
Copy link
Contributor

Choose a reason for hiding this comment

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

in case attribute is not found, pruning that attribute but where's the log? Add log or I would suggest revise it as per javascript code.


# Assert bot filtering is False when not provided in data file
self.assertTrue('botFiltering' not in self.config_dict)
self.assertEqual(False, self.project_config.get_bot_filtering_value())
Copy link
Contributor

Choose a reason for hiding this comment

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

I need to check, when botFiltering is not in dictionary what it's supposed to return? it MUST be NULL, i haven't seen such condition in JS.

tests/base.py Outdated
@@ -150,6 +150,7 @@ def setUp(self):
'accountId': '12001',
'projectId': '111111',
'version': '4',
'botFiltering': False,
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be included or not included, don't add it here. Let's discuss tonight.

@msohailhussain
Copy link
Contributor

First revise the code and align with JS & then correct test cases. Right now, not reviewing test cases anymore.

@@ -18,6 +18,7 @@

from . import version
from .helpers import event_tag_utils
from .helpers.enums import ControlAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. I would usually just import enums and refer to enums.ControlAttributes

""" Get bot filtering bool

Returns:
'botFiltering' value in the datafile.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Boolean representing whether bot filtering is enabled or not.

I would similarly also change the comment for IP anonymization in the method above to

Boolean representing whether IP anonymization is enabled or not.

@@ -172,19 +182,39 @@ def _get_attributes(self, attributes):
if not attributes:
return []

for attribute_key in attributes.keys():
for attribute_key in sorted(attributes.keys()):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does ordering matter? Let us not do this. It seems unnecessary.

'key': attribute_key,
'type': self.EventParams.CUSTOM,
'value': attribute_value,
})

# Append Bot Filtering Attribute
if isinstance(self._get_bot_filtering(), bool):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

'entity_id': ControlAttributes.BOT_FILTERING,
'key': ControlAttributes.BOT_FILTERING,
'type': self.EventParams.CUSTOM,
'value': self._get_bot_filtering(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets call self._get_bot_filtering at line 198 and use that.

'value': attribute_value,
})
if isinstance(attributes, dict):
for attribute_key in sorted(attributes.keys()):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do no sort these.


return attribute.id

if has_reserved_prefix and attribute_key != enums.ControlAttributes.BOT_FILTERING:
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 not condition? I do not thing it is needed. Lets remove the second condition.

# Assert bot filtering is retrieved as provided in the data file
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
project_config = opt_obj.config
self.assertEqual(self.config_dict_with_features['botFiltering'],
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 styling seems wrong

self.assertEqual(
  self.config_dict_with_features['botFiltering'],
  project_config.get_bot_filtering_value()
)

""" Test that Attribute Key is returned as ID when provided attribute key is not
present in the datafile but has $opt prefix. """
self.assertEqual('$opt_interesting',
self.project_config.get_attribute_id('$opt_interesting'))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Indentation seems off. s of self should align with the '

@oakbani
Copy link
Contributor Author

oakbani commented Jun 13, 2018

@aliabbasrizvi Please review the changes.

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

@aliabbasrizvi aliabbasrizvi merged commit fc7bf6c into master Jun 28, 2018
@aliabbasrizvi aliabbasrizvi deleted the oakbani/bot-filtering branch June 28, 2018 02: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.

4 participants