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

Make cyclops working with sentry 9 and tornado 5.1 #36

Open
wants to merge 1 commit 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
39 changes: 26 additions & 13 deletions cyclops/handlers/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zlib import decompress
from base64 import b64decode
from random import randint
from urlparse import urlparse

import tornado.web
from ujson import dumps, loads
Expand All @@ -13,8 +14,8 @@

from cyclops.handlers.base import BaseHandler

SENTRY_KEY = re.compile(r'sentry_key\=(.+),')
SENTRY_SECRET = re.compile(r'sentry_secret\=(.+),?')
SENTRY_KEY = re.compile(r'sentry_key\=([^,]+),?')
SENTRY_SECRET = re.compile(r'sentry_secret\=([^,]+),?')


class BaseRouterHandler(BaseHandler):
Expand Down Expand Up @@ -76,11 +77,8 @@ def backend_request(self, project_id=None):
sentry_key = sentry_key.groups()[0]

sentry_secret = SENTRY_SECRET.search(auth)
if not sentry_secret:
self._404()
return

sentry_secret = sentry_secret.groups()[0]
if sentry_secret:
sentry_secret = sentry_secret.groups()[0]

if project_id is None:
project_id = self.get_project_id(sentry_key, sentry_secret)
Expand All @@ -92,12 +90,19 @@ def backend_request(self, project_id=None):
self._404()
return

base_url = self.application.config.SENTRY_BASE_URL.replace('http://', '').replace('https://', '')
base_url = "%s://%s:%s@%s" % (self.request.protocol, sentry_key, sentry_secret, base_url)
uri = urlparse(self.application.config.SENTRY_BASE_URL)
if sentry_secret:
base_url = "%s://%s:%s@%s" % (uri.scheme, sentry_key, sentry_secret, uri.netloc)
else:
base_url = "%s://%s@%s" % (uri.scheme, sentry_key, uri.netloc)

url = "%s%s?%s" % (base_url, self.request.path, self.request.query)

try:
payload = loads(self.request.body)
if 'Content-Encoding' in self.request.headers and self.request.headers['Content-Encoding'] == 'deflate':
payload = loads(decompress(self.request.body))
else:
payload = loads(self.request.body)
except ValueError:
payload = loads(decompress(b64decode(self.request.body)))

Expand All @@ -116,15 +121,23 @@ def backend_request(self, project_id=None):

def get_project_id(self, public_key, secret_key):
for project_id, keys in self.application.project_keys.iteritems():
if public_key in keys['public_key'] and secret_key in keys['secret_key']:
return project_id
if public_key in keys['public_key']:
if not secret_key:
return project_id
if secret_key in keys['secret_key']:
return project_id
return None

def are_valid_keys(self, project_id, public_key, secret_key):
keys = self.application.project_keys.get(project_id)
if keys is None:
return False
return public_key in keys['public_key'] and secret_key in keys['secret_key']
if public_key in keys['public_key']:
if not secret_key:
return True

return secret_key in keys['secret_key']
return False

def frontend_request(self, project_id):
if self.application.config.RESTRICT_API_ACCESS:
Expand Down
4 changes: 1 addition & 3 deletions cyclops/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def start(self):
periodic_task = PeriodicCallback(
self.update,
self.application.config.UPDATE_PERIOD * 1000,
io_loop=self.main_loop
)
periodic_task.start()

Expand All @@ -42,7 +41,6 @@ def start(self):
periodic_task = PeriodicCallback(
self.update,
20,
io_loop=self.main_loop
)
periodic_task.start()

Expand Down Expand Up @@ -103,7 +101,7 @@ def update(self):
logging.debug("Sending to sentry at %s", url)
self.start_time = time.time()
self.last_sent = time.time()
http_client = AsyncHTTPClient(io_loop=self.main_loop)
http_client = AsyncHTTPClient()
http_client.fetch(request, self.get_handle_request(project_id))
except Queue.Empty:
pass
Expand Down
86 changes: 36 additions & 50 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,60 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages
from setuptools import find_packages, setup

from cyclops import __version__

mysql_requires = [
'torndb==0.1',
'MySQL-python'
]
tests_require = mysql_requires + [
'nose',
'coverage',
'yanc',
'preggy',
'nose',
]
mysql_requires = ["torndb==0.1", "MySQL-python"]
tests_require = mysql_requires + ["nose", "coverage", "yanc", "preggy", "nose"]

setup(
name='cyclops',
name="cyclops",
version=__version__,
description="cyclops is a high-performance gateway for sentry.",
long_description="""
cyclops is a high-performance gateway for sentry.
It keeps items in memory and dumps them at sentry in regular intervals.
""",
keywords='bug monitoring tornado',
author='Bernardo Heynemann',
author_email='[email protected]',
url='https://github.com/heynemann/cyclops',
license='MIT',
keywords="bug monitoring tornado",
author="Bernardo Heynemann",
author_email="[email protected]",
url="https://github.com/heynemann/cyclops",
license="MIT",
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: MacOS',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
],

packages=find_packages(),
include_package_data=True,
zip_safe=False,

extras_require={
'tests': tests_require,
'mysql': mysql_requires,
'postgres': [
'psycopg2',
],
"tests": tests_require,
"mysql": mysql_requires,
"postgres": ["psycopg2"],
},

install_requires=[
'tornado>=4.3,<4.5',
'derpconf==0.3.3',
'pycurl>=7.19.5.1,<7.20',
'requests',
'ujson==1.30',
'msgpack-python==0.3.0',
'redis==2.7.2',
'redis-lock==0.2.0',
'argparse==1.2.1',
"tornado>=5.1.1",
"derpconf==0.3.3",
"pycurl>=7.19.5.1,<7.20",
"requests",
"ujson==1.30",
"msgpack-python==0.3.0",
"redis==2.7.2",
"redis-lock==0.2.0",
"argparse==1.2.1",
],

entry_points={
'console_scripts': [
'cyclops=cyclops.server:main',
'cyclops-init=cyclops.init:main',
'cyclops-count=cyclops.count:main',
],
}
"console_scripts": [
"cyclops=cyclops.server:main",
"cyclops-init=cyclops.init:main",
"cyclops-count=cyclops.count:main",
]
},
)