Skip to content

Commit

Permalink
Merge in master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
nd4p90x committed Jan 29, 2025
2 parents b01701e + c8e4c56 commit 310d7ef
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 48 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/create_jira.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create Jira Ticket

on:
issues:
types:
- opened

jobs:
create_jira:
name: Create Jira Ticket
runs-on: ubuntu-latest
environment: IssueTracker
steps:
- name: Checkout
uses: actions/checkout@master
- name: Login
uses: atlassian/gajira-login@master
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_TOKEN }}
JIRA_EPIC_KEY: ${{ secrets.JIRA_EPIC_KEY }}
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}

- name: Create
id: create
uses: atlassian/gajira-create@master
with:
project: ${{ secrets.JIRA_PROJECT }}
issuetype: Bug
summary: |
[${{ github.event.repository.name }}] (${{ github.event.issue.number }}): ${{ github.event.issue.title }}
description: |
Github Link: ${{ github.event.issue.html_url }}
${{ github.event.issue.body }}
fields: '{"parent": {"key": "${{ secrets.JIRA_EPIC_KEY }}"}}'

- name: Log created issue
run: echo "Issue ${{ steps.create.outputs.issue }} was created"
12 changes: 3 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
- name: Install Python 3
uses: actions/setup-python@v3
with:
python-version: 3.7
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install python-dateutil backoff monotonic
pip install --user .
sudo pip install pylint==2.8.0 flake8 mock==3.0.5 python-dateutil aiohttp==3.9.1
sudo pip install pylint==3.3.1 flake8 mock==3.0.5 python-dateutil aiohttp==3.9.1
- name: Run tests
run: python -m unittest discover -s segment

Expand All @@ -41,17 +41,11 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# python: ['3.7', '3.8', '3.9', '3.10', '3.11']
# python: ['3.9', '3.10', '3.11']
# coverage: [false]
# experimental: [false]
# include:
# # Run code coverage.
# - python: '3.7'
# coverage: true
# experimental: false
# - python: '3.8'
# coverage: true
# experimental: false
# - python: '3.9'
# coverage: true
# experimental: false
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Run with setup-python 3.7
uses: actions/setup-python@v5
with:
python-version: '3.7'
- name: Setup required modules
run: python -m pip install -r requirements.txt
- name: Run tests
run: python -m unittest discover -s segment

- name: Run with setup-python 3.8
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Setup required modules
run: python -m pip install -r requirements.txt
- name: Run tests
run: python -m unittest discover -s segment

- name: Run with setup-python 3.9
uses: actions/setup-python@v5
with:
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.3.3 / 2024-10-07
- Update time handling and OAuth

# 2.3.2 / 2024-02-15
- Updating version to create a release wheel without the outdated /analytics files

# 2.3.1 / 2024-02-07
- Fixing dependency for JWT

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

analytics-python is a python client for [Segment](https://segment.com)

### ⚠️ Maintenance ⚠️
This library is in maintenance mode. It will send data as intended, but receive no new feature support and only critical maintenance updates from Segment.

<div align="center">
<img src="https://user-images.githubusercontent.com/16131737/53616895-a1142d80-3b99-11e9-8e0e-594c0b0dcdc9.png"/>
<p><b><i>You can't fix what you can't measure</i></b></p>
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
backoff==2.2.1
cryptography==41.0.3
flake8==3.7.9
cryptography==44.0.0
flake8==7.1.1
mock==2.0.0
PyJWT==2.8.0
pylint==2.8.0
pylint==3.3.3
PyJWT==2.10.1
python-dateutil==2.8.2
requests==2.31.0
requests==2.32.3
2 changes: 1 addition & 1 deletion segment/analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _enqueue(self, msg):
"""Push a new `msg` onto the queue, return `(success, msg)`"""
timestamp = msg['timestamp']
if timestamp is None:
timestamp = datetime.utcnow().replace(tzinfo=tzutc())
timestamp = datetime.now(tz=tzutc())
message_id = msg.get('messageId')
if message_id is None:
message_id = uuid4()
Expand Down
8 changes: 4 additions & 4 deletions segment/analytics/oauth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def _poller_loop(self):

elif response.status_code == 429:
self.retry_count += 1
rate_limit_reset_timestamp = None
rate_limit_reset_time = None
try:
rate_limit_reset_timestamp = int(response.headers.get("X-RateLimit-Reset"))
rate_limit_reset_time = int(response.headers.get("X-RateLimit-Reset"))
except Exception as e:
self.log.error("OAuth rate limit response did not have a valid rest time: {} | {}".format(response, e))
if rate_limit_reset_timestamp:
refresh_timer_ms = rate_limit_reset_timestamp - time.time() * 1000
if rate_limit_reset_time:
refresh_timer_ms = rate_limit_reset_time * 1000
else:
refresh_timer_ms = 5 * 1000

Expand Down
2 changes: 1 addition & 1 deletion segment/analytics/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def post(write_key, host=None, gzip=False, timeout=15, proxies=None, oauth_manag
log = logging.getLogger('segment')
body = kwargs
if not "sentAt" in body.keys():
body["sentAt"] = datetime.utcnow().replace(tzinfo=tzutc()).isoformat()
body["sentAt"] = datetime.now(tz=tzutc()).isoformat()
body["writeKey"] = write_key
url = remove_trailing_slash(host or 'https://api.segment.io') + '/v1/batch'
auth = None
Expand Down
6 changes: 3 additions & 3 deletions segment/analytics/test/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def json(self):
elif kwargs['url'] == 'http://127.0.0.1:400/token':
return MockResponse({"reason": "test_reason", "json_data" : {"error":"unrecoverable", "error_description":"nah"}}, 400)
elif kwargs['url'] == 'http://127.0.0.1:429/token':
return MockResponse({"reason": "test_reason", "headers" : {"X-RateLimit-Reset": time.time()*1000 + 2000}}, 429)
return MockResponse({"reason": "test_reason", "headers" : {"X-RateLimit-Reset": 234}}, 429)
elif kwargs['url'] == 'http://127.0.0.1:500/token':
return MockResponse({"reason": "test_reason", "json_data" : {"error":"recoverable", "error_description":"nah"}}, 500)
elif kwargs['url'] == 'http://127.0.0.1:501/token':
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_oauth_fail_with_retries(self, mock_post):
def test_oauth_rate_limit_delay(self, mock_sleep, mock_post):
manager = segment.analytics.oauth_manager.OauthManager("id", privatekey, "keyid", "http://127.0.0.1:429")
manager._poller_loop()
self.assertTrue(mock_sleep.call_args[0][0] > 1.9 and mock_sleep.call_args[0][0] <= 2.0)
mock_sleep.assert_called_with(234)

class TestOauthIntegration(unittest.TestCase):
def fail(self, e, batch=[]):
Expand Down Expand Up @@ -152,4 +152,4 @@ def test_oauth_integration_fail_bad_key(self, mock_post):
self.assertTrue(self.failed)

if __name__ == '__main__':
unittest.main()
unittest.main()
2 changes: 1 addition & 1 deletion segment/analytics/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.3.1'
VERSION = '2.3.3'
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"requests~=2.7",
"backoff~=2.1",
"python-dateutil~=2.2",
"PyJWT~=2.8.0"
"PyJWT~=2.10.1"
]

tests_require = [
"mock==2.0.0",
"pylint==2.8.0",
"pylint==3.3.1",
"flake8==3.7.9",
]

Expand All @@ -42,7 +42,7 @@
maintainer_email='[email protected]',
test_suite='segment.analytics.test.all',
packages=['segment.analytics', 'segment.analytics.test'],
python_requires='>=3.6.0',
python_requires='>=3.9.0',
license='MIT License',
install_requires=install_requires,
extras_require={
Expand All @@ -56,9 +56,6 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down

0 comments on commit 310d7ef

Please sign in to comment.