Merge pull request #45 from mxmeinhold/better-sentry

This commit is contained in:
Max Meinhold 2020-10-12 23:22:11 -04:00 committed by GitHub
commit 44c72c0b2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 8 deletions

View file

@ -1,6 +1,7 @@
[MASTER]
ignore = ,input
persistent = yes
load-plugins = pylint_quotes
[MESSAGES CONTROL]
disable =

View file

@ -5,4 +5,4 @@ python:
install:
- "pip install -r requirements.txt"
script:
- "pylint --load-plugins pylint_quotes proxstar"
- "pylint proxstar"

View file

@ -16,10 +16,13 @@ It is available to house members at [proxstar.csh.rit.edu](https://proxstar.csh.
## Contributing
1. [Fork](https://help.github.com/en/articles/fork-a-repo) this repository
- Optionally create a new [git branch](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell) if your change is more than a small tweak (`git checkout -b BRANCH-NAME-HERE`)
- Optionally create a new [git branch](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell) if your change is more than a small tweak (`git checkout -b BRANCH-NAME-HERE`)
3. Make your changes locally, commit, and push to your fork
- If you want to test locally, you should copy `config.py` to `config_local.py`, and talk to an RTP about filling in secrets.
- Lint your local changes with `pylint proxstar`
- You'll need dependencies installed locally to do this. You should do that in a [venv](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments) of some sort to keep your system clean. All the dependencies are listed in [requirements.txt](./requirements.txt), so you can install everything with `pip install -r requirements.txt`. You'll need python 3.6 at minimum, though things should work up to python 3.8.
4. Create a [Pull Request](https://help.github.com/en/articles/about-pull-requests) on this repo for our Webmasters to review
## Questions/Concerns
Please file an [Issue](https://github.com/ComputerScienceHouse/proxstar/issues/new) on this repository.
Please file an [Issue](https://github.com/ComputerScienceHouse/proxstar/issues/new) on this repository.

View file

@ -60,3 +60,9 @@ WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH',
'/opt/app-root/bin/websockify')
WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE',
'/opt/app-root/src/targets')
# SENTRY
# If you set the sentry dsn locally, make sure you use the local-dev or some
# other local environment, so we can separate local errors from production
SENTRY_DSN = environ.get("PROXSTAR_SENTRY_DSN", "")
SENTRY_ENV = environ.get("PROXSTAR_SENTRY_ENV", "local-dev")

View file

@ -13,6 +13,10 @@ from rq_scheduler import Scheduler
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from flask import Flask, render_template, request, redirect, session, abort, url_for
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.rq import RqIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
from proxstar.db import (Base, datetime, get_pool_cache, renew_vm_expire, set_user_usage_limits, get_template,
get_templates, get_allowed_users, add_ignored_pool, delete_ignored_pool, add_allowed_user,
delete_allowed_user,
@ -31,15 +35,22 @@ app = Flask(__name__)
app.config.from_object(rq_dashboard.default_settings)
if os.path.exists(
os.path.join(
app.config.get('ROOT_DIR', os.getcwd()), 'config.local.py')):
app.config.get('ROOT_DIR', os.getcwd()), 'config_local.py')):
config = os.path.join(
app.config.get('ROOT_DIR', os.getcwd()), 'config.local.py')
app.config.get('ROOT_DIR', os.getcwd()), 'config_local.py')
else:
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), 'config.py')
app.config.from_pyfile(config)
app.config['GIT_REVISION'] = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip()
# Sentry setup
sentry_sdk.init(
dsn=app.config['SENTRY_DSN'],
integrations=[FlaskIntegration(), RqIntegration(), SqlalchemyIntegration()],
environment=app.config['SENTRY_ENV']
)
with open('proxmox_ssh_key', 'w') as ssh_key_file:
ssh_key_file.write(app.config['PROXMOX_SSH_KEY'])

View file

@ -5,9 +5,8 @@ gunicorn==19.9.0
paramiko==2.4.2
proxmoxer==1.0.3
psutil==5.6.6
psycopg2-binary==2.7.5
psycopg2-binary==2.8.6
python-dateutil==2.7.3
raven~=6.10.0
redis==2.10.6
requests==2.20.1
rq==0.12.0
@ -19,3 +18,5 @@ tenacity==5.0.2
websockify==0.8.0
pylint==2.3.1
pylint-quotes==0.2.1
sentry-sdk[flask]
sentry-sdk~=0.18.0

15
rqsettings.py Normal file
View file

@ -0,0 +1,15 @@
import os
import sentry_sdk
from sentry_sdk.integrations.rq import RqIntegration
if os.path.exists('config_local.py'):
import config_local as config
else:
import config
sentry_sdk.init(
config.SENTRY_DSN,
integrations=[RqIntegration()],
environment=config.SENTRY_ENV
)

View file

@ -1,3 +1,3 @@
#!/bin/sh
/opt/app-root/bin/rq worker -u "$PROXSTAR_REDIS_URL" --sentry-dsn "$PROXSTAR_SENTRY_DSN"
/opt/app-root/bin/rq worker -u "$PROXSTAR_REDIS_URL" --sentry-dsn "" -c rqsettings