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

TDL-15317: Fix Primary Key for Feature Events #48

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
name: 'Unit Tests'
command: |
source /usr/local/share/virtualenvs/tap-pendo/bin/activate
pip install coverage
pip install nose coverage
nosetests --with-coverage --cover-erase --cover-package=tap_pendo --cover-html-dir=htmlcov tests/unittests
coverage html
- store_test_results:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This tap:
**[feature_events](https://developers.pendo.io/docs/?bash#get-an-account-by-id)**

- Endpoint: [https://api/v1/aggregation](https://app.pendo.io/api/v1/aggregation)
- Primary key fields: `visitor_id`, `account_id`, `server`, `remote_ip`
- Primary key fields: `feature_id`, `visitor_id`, `account_id`, `server`, `remote_ip`, `user_agent`, `day` or `hour`
- Replication strategy: INCREMENTAL (query filtered)
- Bookmark: `day` or `hour`
- Transformations: Camel to snake case.
Expand Down
6 changes: 5 additions & 1 deletion tap_pendo/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ def get_body(self):
class FeatureEvents(EventsBase):
name = "feature_events"
replication_method = "INCREMENTAL"
key_properties = ['visitor_id', 'account_id', 'server', 'remote_ip']
key_properties = ['feature_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']

def __init__(self, config):
super().__init__(config=config)
self.key_properties.append("day" if self.period == 'dayRange' else "hour")
Copy link
Contributor

Choose a reason for hiding this comment

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

@savan-chovatiya can you please write a unit test case for the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added unit tests for the key_properties.


def get_body(self, key_id, period, first):
return {
Expand Down
14 changes: 8 additions & 6 deletions tests/tap_tester/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TestPendoBase(unittest.TestCase):
START_DATE_FORMAT = "%Y-%m-%dT00:00:00Z"
BOOKMARK_COMPARISON_FORMAT = "%Y-%m-%dT%H:%M%S%z"
start_date = ""
is_day_range = True

@staticmethod
def name():
Expand All @@ -39,6 +40,7 @@ def get_type():

def expected_metadata(self):
"""The expected streams and metadata about the streams"""
event_replication_key = 'day' if self.is_day_range else 'hour'
return {
"accounts": {
self.PRIMARY_KEYS: {'account_id'},
Expand Down Expand Up @@ -79,19 +81,19 @@ def expected_metadata(self):
self.REPLICATION_KEYS: {'last_updated_at'}
},
"feature_events":{
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.PRIMARY_KEYS: {"feature_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", event_replication_key},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"page_events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"guide_events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server_name", "remote_ip"},
Expand All @@ -106,7 +108,7 @@ def expected_metadata(self):
"track_events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"metadata_accounts": {
self.REPLICATION_METHOD: self.FULL_TABLE,
Expand Down Expand Up @@ -136,7 +138,7 @@ def get_properties(self, original: bool = True):
return_value = {
"start_date": "2020-09-10T00:00:00Z",
"lookback_window": "1",
"period": "dayRange",
"period": "dayRange" if self.is_day_range else "hourRange",
}
if original:
return return_value
Expand Down
13 changes: 11 additions & 2 deletions tests/tap_tester/test_bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PendoBookMarkTest(TestPendoBase):
def name(self):
return "pendo_bookmark_test"

def test_run(self):
def run_test(self):
"""
Verify that for each stream you can do a sync which records bookmarks.
That the bookmark is the maximum value sent to the target for the replication key.
Expand Down Expand Up @@ -191,4 +191,13 @@ def test_run(self):

# Verify at least 1 record was replicated in the second sync
self.assertGreater(
second_sync_count, 0, msg="We are not fully testing bookmarking for {}".format(stream))
second_sync_count, 0, msg="We are not fully testing bookmarking for {}".format(stream))

def test_run(self):
# test for hourRange period
self.is_day_range = False
self.run_test()

# test for dayRange period
self.is_day_range = True
self.run_test()
12 changes: 11 additions & 1 deletion tests/tap_tester/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PendoDiscoverTest(TestPendoBase):
def name(self):
return "pendo_discover_test"

def test_run(self):
def discovery_test_run(self):
streams_to_test = self.expected_streams()

conn_id = connections.ensure_connection(self, payload_hook=None)
Expand Down Expand Up @@ -123,3 +123,13 @@ def test_run(self):
and item.get("breadcrumb", ["properties", None])[1]
not in actual_automatic_fields}),
msg="Not all non key properties are set to available in metadata")

def test_run(self):

#Discovery test for hourRange period
self.is_day_range = False
self.discovery_test_run()

#Discovery test for dayRange period
self.is_day_range = True
self.discovery_test_run()
30 changes: 30 additions & 0 deletions tests/unittests/test_feature_events_primary_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest
from tap_pendo.streams import FeatureEvents

class TestFeatureEventsPrimaryKeys(unittest.TestCase):

def test_feature_event_primary_key_with_hourRange(self):
'''
Verify that primary keys should have expected fields with 'hour' field when period is hourRange
'''
# Reset key properties to default value
FeatureEvents.key_properties = ['feature_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']
config = {"period": "hourRange"} # set hourRange as a period
expected_primary_keys = ["feature_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", "hour"]

feature_event_stream1 = FeatureEvents(config) # Initialize FeatuereEvents object which sets primary keys

self.assertEqual(feature_event_stream1.key_properties, expected_primary_keys)

def test_feature_event_primary_key_with_dayRange(self):
'''
Verify that primary keys should have expected fields with 'day' field when period is dayRange
'''
# Reset key properties to default value
FeatureEvents.key_properties = ['feature_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']
config = {"period": "dayRange"} # set dayRange as a period
expected_primary_keys = ["feature_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", "day"]

feature_event_stream2 = FeatureEvents(config) # Initialize Events object which sets primary keys

self.assertEqual(feature_event_stream2.key_properties, expected_primary_keys)