Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/requests-2.31.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeshmukh15 authored Jan 22, 2025
2 parents 0188344 + 63fcc1e commit 4696123
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 11 deletions.
9 changes: 5 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: 218546966473.dkr.ecr.us-east-1.amazonaws.com/circle-ci:stitch-tap-tester
- image: 218546966473.dkr.ecr.us-east-1.amazonaws.com/circle-ci:stitch-tap-tester-3-11-dev
steps:
- checkout
- add_ssh_keys
Expand All @@ -14,7 +14,7 @@ jobs:
source dev_env.sh
python3 -m venv /usr/local/share/virtualenvs/tap-mixpanel
source /usr/local/share/virtualenvs/tap-mixpanel/bin/activate
pip install -U 'pip<19.2' 'setuptools<51.0.0'
pip install -U 'pip==23.3.2' 'setuptools<51.0.0'
pip install .[dev]
pip install pytest-cov
- run:
Expand All @@ -33,8 +33,9 @@ jobs:
name: 'Unit Tests'
command: |
source /usr/local/share/virtualenvs/tap-mixpanel/bin/activate
pip install nose coverage parameterized
nosetests --with-coverage --cover-erase --cover-package=tap_mixpanel --cover-html-dir=htmlcov tests/unittests
pip install nose2 parameterized nose2[coverage_plugin]>=0.6.5
pip install parameterized
nose2 --with-coverage -v -s tests/unittests
- store_test_results:
path: test_output/report.xml
- store_artifacts:
Expand Down
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@

# Rollback steps
- revert this branch

#### AI generated code
https://internal.qlik.dev/general/ways-of-working/code-reviews/#guidelines-for-ai-generated-code
- [ ] this PR has been written with the help of GitHub Copilot or another generative AI tool
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Changelog


## 1.6.0
* Requirement updates to run on python 3.11.7 [#63](https://github.com/singer-io/tap-mixpanel/pull/63)

## 1.5.1
* Dependabot update [#60](https://github.com/singer-io/tap-mixpanel/pull/60)
* Add retry logic for `ChunkedEncodingError`s [#61](https://github.com/singer-io/tap-mixpanel/pull/61)

## 1.5.0
* Adds `export_events` as optional param to filter the data for export stream based on event names [#56](https://github.com/singer-io/tap-mixpanel/pull/56)

## 1.4.3
* Code Refactoring [#55](https://github.com/singer-io/tap-mixpanel/pull/55)
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from setuptools import setup, find_packages

setup(name='tap-mixpanel',
version='1.5.0',
version='1.6.0',
description='Singer.io tap for extracting data from the mixpanel API',
author='[email protected]',
classifiers=['Programming Language :: Python :: 3 :: Only'],
py_modules=['tap_mixpanel'],
install_requires=[
'backoff==1.8.0',
'requests==2.31.0',
'singer-python==5.12.1',
'backoff==2.2.1',
'requests==2.22.0',
'singer-python==6.0.0',
'jsonlines==1.2.0'
],
entry_points='''
Expand Down
4 changes: 2 additions & 2 deletions tap_mixpanel/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jsonlines
import requests
import singer
from requests.exceptions import ConnectionError, Timeout
from requests.exceptions import ChunkedEncodingError, ConnectionError, Timeout
from requests.models import ProtocolError
from singer import metrics

Expand Down Expand Up @@ -204,7 +204,7 @@ def check_access(self):

@backoff.on_exception(
backoff.expo,
(Server5xxError, Server429Error, ReadTimeoutError, ConnectionError, Timeout, ProtocolError),
(Server5xxError, Server429Error, ReadTimeoutError, ConnectionError, Timeout, ProtocolError, ChunkedEncodingError),
max_tries=BACKOFF_MAX_TRIES_REQUEST,
factor=3,
logger=LOGGER,
Expand Down
9 changes: 9 additions & 0 deletions tap_mixpanel/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import urllib
import pytz
import requests
import backoff
import singer
from singer import Transformer, metadata, metrics, utils
from singer.utils import strptime_to_utc
Expand Down Expand Up @@ -695,6 +697,13 @@ class Export(MixPanel):
replication_method = "INCREMENTAL"
params = {}


@backoff.on_exception(
backoff.expo,
(requests.exceptions.ChunkedEncodingError,),
max_tries=5,
factor=2,
)
def get_and_transform_records(
self,
querystring,
Expand Down
39 changes: 39 additions & 0 deletions tests/unittests/test_error_handling.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest
import requests

import jsonlines
from unittest import mock
from parameterized import parameterized

from tap_mixpanel import client
from tap_mixpanel import streams

# Mock response
REQUEST_TIMEOUT = 300
Expand Down Expand Up @@ -249,3 +251,40 @@ def test_check_access_handle_timeout_error(self, mock_request, mock_time):

# Verify that requests.Session.request is called 5 times
self.assertEqual(mock_request.call_count, 5)

@mock.patch("jsonlines.jsonlines.Reader.iter", side_effect=requests.exceptions.ChunkedEncodingError)
def test_ChunkedEncodingError(self, mock_jsonlines, mock_time):
"""
Check whether the request backoffs properly for `check_access` method for 5 times in case of Timeout error.
"""
mock_client = client.MixpanelClient(api_secret="mock_api_secret", api_domain="mock_api_domain", request_timeout=REQUEST_TIMEOUT)
mock_client._MixpanelClient__verified = True

fake_response = MockResponse(500)
fake_response.iter_lines = lambda : []
mock_client.perform_request = lambda *args, **kwargs: fake_response

stream = streams.Export(mock_client)

with self.assertRaises(requests.exceptions.ChunkedEncodingError) as error:
stream.get_and_transform_records(
querystring={},
project_timezone=None,
max_bookmark_value=None,
state=None,
config=None,
catalog=None,
selected_streams=None,
last_datetime=None,
endpoint_total=None,
limit=None,
total_records=None,
parent_total=None,
record_count=None,
page=None,
offset=None,
parent_record=None,
date_total=None,
)

self.assertEqual(mock_jsonlines.call_count, 5)

0 comments on commit 4696123

Please sign in to comment.