-
Notifications
You must be signed in to change notification settings - Fork 14
Added SQS transport support #14
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [report] | ||
| include = raven_python_lambda/*.py | ||
| omit = raven_python_lambda/__about__.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| language: python | ||
|
|
||
| python: | ||
| - "2.7" | ||
| - "3.5" | ||
| - "3.6" | ||
|
|
||
| install: | ||
| - pip install tox-travis coveralls | ||
|
|
||
| script: | ||
| - tox | ||
|
|
||
| after_success: | ||
| - coveralls | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Kevin Glisson <kevgliss> | ||
| Mike Grima <mikegrima> @THISisPLACEHLDR | ||
| Michal Przytulski <mprzytulski> | ||
| Björn Andersson <bjorn-spire> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """ | ||
| .. module: raven_python_lambda.sqs_transport | ||
| :platform: Unix | ||
| :copyright: (c) 2017 by Netflix Inc., see AUTHORS for more | ||
| :license: Apache, see LICENSE for more details. | ||
|
|
||
| .. moduleauthor:: Mike Grima <mikegrima> @THISisPLACEHLDR | ||
| """ | ||
| import base64 | ||
| import json | ||
|
|
||
| import boto3 | ||
|
|
||
| from raven.utils.compat import string_types | ||
| from raven.conf import defaults | ||
| from raven.transport.base import Transport | ||
|
|
||
|
|
||
| class SQSTransport(Transport): | ||
| scheme = ['sqs+https', 'sqs+http'] | ||
|
|
||
| def __init__(self, sqs_region, sqs_account, sqs_name, | ||
| timeout=defaults.TIMEOUT, verify_ssl=True, | ||
| ca_certs=defaults.CA_BUNDLE): | ||
| # Stuff the docs require: | ||
| if isinstance(timeout, string_types): | ||
| timeout = int(timeout) | ||
| if isinstance(verify_ssl, string_types): | ||
| verify_ssl = bool(int(verify_ssl)) | ||
|
|
||
| self.timeout = timeout | ||
| self.verify_ssl = verify_ssl | ||
| self.ca_certs = ca_certs | ||
| ##################### | ||
|
|
||
| # Stuff SQS requires: | ||
| self.sqs_name = sqs_name | ||
| self.sqs_account = sqs_account | ||
| self.sqs_client = boto3.client("sqs", region_name=sqs_region) | ||
| self.queue_url = None | ||
|
|
||
| def send(self, url, data, headers): | ||
| """ | ||
| Sends a request to an SQS queue -- to be later popped off | ||
| later for submission into Sentry. | ||
| Note: This will simply raise any Boto ClientErrors that are encountered. | ||
| """ | ||
| if not self.queue_url: | ||
| self.queue_url = self.sqs_client.get_queue_url(QueueName=self.sqs_name, | ||
| QueueOwnerAWSAccountId=self.sqs_account)["QueueUrl"] | ||
|
|
||
| payload = { | ||
| "url": url, | ||
| "headers": headers, | ||
| "data": base64.b64encode(data).decode("utf-8") | ||
| } | ||
|
|
||
| self.sqs_client.send_message(QueueUrl=self.queue_url, | ||
| MessageBody=json.dumps(payload)) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """ | ||
| .. module: raven_python_lambda.tests.conftest | ||
| :platform: Unix | ||
| :copyright: (c) 2017 by Netflix Inc., see AUTHORS for more | ||
| :license: Apache, see LICENSE for more details. | ||
|
|
||
| .. moduleauthor:: Mike Grima <mikegrima> @THISisPLACEHLDR | ||
| """ | ||
|
|
||
| from moto import mock_sqs | ||
| import boto3 | ||
| import pytest | ||
| import os | ||
|
|
||
|
|
||
| class DsnEnvVar: | ||
| def __init__(self): | ||
| self.old_dsn = os.environ.get("SENTRY_DSN") | ||
|
|
||
| def __enter__(self): | ||
| os.environ["SENTRY_DSN"] = "https://asdfasdfds:Lasdfasdfadfs@somesentry.com/project" \ | ||
| "?sqs_name=sentry-queue&sqs_region=us-east-1&sqs_account=123456789012" | ||
|
|
||
| def __exit__(self, *args): | ||
| if self.old_dsn: | ||
| os.environ["SENTRY_DSN"] = self.old_dsn | ||
| else: | ||
| del os.environ["SENTRY_DSN"] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def sqs(): | ||
| with mock_sqs(): | ||
| yield boto3.client("sqs", region_name="us-east-1") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def sqs_queue(sqs): | ||
| with DsnEnvVar(): | ||
| sqs.create_queue(QueueName="sentry-queue") | ||
| yield sqs.get_queue_url(QueueName="sentry-queue", | ||
| QueueOwnerAWSAccountId="123456789012")["QueueUrl"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """ | ||
| .. module: raven_python_lambda.tests.test_decorator | ||
| :platform: Unix | ||
| :copyright: (c) 2017 by Netflix Inc., see AUTHORS for more | ||
| :license: Apache, see LICENSE for more details. | ||
|
|
||
| .. moduleauthor:: Mike Grima <mikegrima> @THISisPLACEHLDR | ||
| """ | ||
| import boto3 | ||
|
|
||
| from raven_python_lambda.sqs_transport import SQSTransport | ||
| from raven.base import Client | ||
|
|
||
| # Simplify comparing dicts with primitive values: | ||
| from raven.utils import json | ||
| import zlib | ||
|
|
||
| import base64 | ||
|
|
||
|
|
||
| def test_sqs_transport(sqs_queue): | ||
| sqs = boto3.client("sqs", region_name="us-east-1") | ||
|
|
||
| c = Client(dsn="mock://some_username:some_password@localhost:8143/1" | ||
| "?sqs_region=us-east-1&sqs_account=123456789012&sqs_name=sentry-queue", | ||
| transport=SQSTransport) | ||
|
|
||
| data = dict(a=42, b=55, c=list(range(50))) | ||
| expected_message = zlib.decompress(c.encode(data)) | ||
|
|
||
| c.send(**data) | ||
|
|
||
| transport = c._transport_cache["mock://some_username:some_password@localhost:8143/1" | ||
| "?sqs_region=us-east-1&sqs_account=123456789012" | ||
| "&sqs_name=sentry-queue"].get_transport() | ||
|
|
||
| assert transport.sqs_account == "123456789012" | ||
| assert transport.sqs_name == "sentry-queue" | ||
| assert type(transport.sqs_client).__name__ == type(sqs).__name__ | ||
| assert transport.queue_url == "https://queue.amazonaws.com/123456789012/sentry-queue" | ||
|
|
||
| # Check SQS for the message that was sent over: | ||
| messages = sqs.receive_message(QueueUrl=transport.queue_url)["Messages"] | ||
| assert len(messages) == 1 | ||
|
|
||
| body = json.loads(messages[0]["Body"]) | ||
|
|
||
| assert body["url"] == "mock://localhost:8143/api/1/store/" | ||
| assert "sentry_secret=some_password" in body["headers"]["X-Sentry-Auth"] | ||
|
|
||
| decoded_data = base64.b64decode(body["data"]) | ||
|
|
||
| assert json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True) == \ | ||
| json.dumps(c.decode(decoded_data), sort_keys=True) # noqa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,9 @@ | |
|
|
||
| tests_require = [ | ||
| 'pytest', | ||
| 'coverall' | ||
| 'moto', | ||
| 'coveralls', | ||
| 'tox' | ||
| ] | ||
|
|
||
| setup( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lambda doesn't support 3.5