Skip to content

Commit

Permalink
Merge pull request #15 from homedepot/rc
Browse files Browse the repository at this point in the history
Rc
  • Loading branch information
mphillipson authored Sep 3, 2020
2 parents cc5fa09 + b57e19b commit 7c528dc
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 301 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ ASALocalRun/

# End of https://www.gitignore.io/api/linux,osx,windows,python,vim,visualstudio

metREx/favicon.ico

# Docker
docker-compose.yml

Expand Down
3 changes: 2 additions & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ services:
ports:
- 5000:5000
volumes:
- .:/usr/src
- .:/usr/src
- ./favicon.ico:/usr/src/metREx/favicon.ico
2 changes: 1 addition & 1 deletion metREx/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .main.controller.scheduler_controller import api as scheduler_ns

__title__ = 'metREx'
__version__ = '0.4.0.post3'
__version__ = '0.5.0'
__description__ = 'SQL query and monitoring system metrics exporter for Prometheus'

blueprint = Blueprint('api', __name__)
Expand Down
23 changes: 19 additions & 4 deletions metREx/app/main/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging

from datetime import datetime, timedelta

Expand Down Expand Up @@ -51,6 +52,12 @@ def create_app(config_name):

app.config.from_object(config_obj)

if not app.debug:
logger = logging.getLogger('werkzeug')
logger.setLevel(logging.ERROR)

# app.logger.setLevel(logging.ERROR)

db.init_app(app)
aa.init_app(app)

Expand All @@ -73,10 +80,14 @@ def create_app(config_name):
def delete_job(job_name, pushgateways):
if job_name in registered_collectors.keys():
if len(pushgateways):
options = {}
options = {
'grouping_key': {
'job': job_name
}
}

if registered_collectors[job_name].instance:
options['grouping_key'] = {'instance': registered_collectors[job_name].instance}
options['grouping_key']['instance'] = registered_collectors[job_name].instance

for service, pushgateway in pushgateways.items():
try:
Expand Down Expand Up @@ -143,10 +154,14 @@ def set_job_collector_metrics(job_name, collector_metrics):
if registered_collectors[job_name].instance is None:
generate_latest(job_collector_registry)

options = {}
options = {
'grouping_key': {
'job': job_name
}
}

if registered_collectors[job_name].instance:
options['grouping_key'] = {'instance': registered_collectors[job_name].instance}
options['grouping_key']['instance'] = registered_collectors[job_name].instance

for service, pushgateway in pushgateways.items():
try:
Expand Down
12 changes: 12 additions & 0 deletions metREx/app/main/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from dotenv import load_dotenv

from sqlalchemy.pool import NullPool, SingletonThreadPool

from .util import api_helper
from .util import apscheduler_helper
from .util.misc_helper import str_to_bool
Expand Down Expand Up @@ -87,6 +89,10 @@ class Config:

PUSHGATEWAYS = {}

SQLALCHEMY_ENGINE_OPTIONS = {
'poolclass': NullPool
}

SQLALCHEMY_TRACK_MODIFICATIONS = False

SCHEDULER_API_ENABLED = False
Expand Down Expand Up @@ -181,6 +187,10 @@ class TestingConfig(Config):
TESTING = True
PRESERVE_CONTEXT_ON_EXCEPTION = False

SQLALCHEMY_ENGINE_OPTIONS = {
'poolclass': SingletonThreadPool
}

def __init__(self):
database_service_name = service_prefix['SQLALCHEMY'] + 'TEST'

Expand Down Expand Up @@ -208,6 +218,8 @@ def __init__(self):
class ProductionConfig(Config):
DEBUG = str_to_bool(os.getenv('DEBUG', False))

ERROR_INCLUDE_MESSAGE = str_to_bool(os.getenv('ERROR_INCLUDE_MESSAGE', False))


config_by_name = dict(
dev=DevelopmentConfig,
Expand Down
19 changes: 7 additions & 12 deletions metREx/app/main/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@


class DatabaseAccessLayer:
_db_session = None
_engine = None
_session = None

def __init__(self, db):
self._db = db

def execute(self, statement):
result = self._db_session.execute(text(statement).execution_options(autocommit=False))

self._db_session.rollback()
result = self._session.execute(text(statement).execution_options(autocommit=False))

return result

def init_db(self, bind):
self._engine = self._db.get_engine(bind=bind)
engine = self._db.get_engine(bind=bind)

self._db_session = self._db.create_scoped_session({
'bind': self._engine
self._session = self._db.create_scoped_session({
'autocommit': False,
'autoflush': False,
'bind': engine
})

def __del__(self):
if self._engine is not None:
self._engine.dispose()
Loading

0 comments on commit 7c528dc

Please sign in to comment.