From d72d911b614e01809abcaa437b097d808ce49e51 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Sun, 8 Apr 2018 22:08:03 -0400 Subject: [PATCH] Add support for configuring sqlalchemy pool size, timeout and recycle These are especially useful when using remote database servers. We need to be able to tweak when timeouts and recycling are occuring on the client side in order to prevent server-side timeouts to be happening. Change-Id: I7ced5ad644da212c80d9f3fcf0e3e1bad44e2e41 --- ara/config/base.py | 18 ++++++++++++++++++ ara/tests/unit/test_config.py | 35 +++++++++++++++++++---------------- doc/source/configuration.rst | 11 +++++++++++ 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/ara/config/base.py b/ara/config/base.py index c5986335..bcbc2349 100644 --- a/ara/config/base.py +++ b/ara/config/base.py @@ -41,6 +41,24 @@ class BaseConfig(object): ) self.SQLALCHEMY_DATABASE_URI = self.ARA_DATABASE self.SQLALCHEMY_TRACK_MODIFICATIONS = False + self.SQLALCHEMY_POOL_SIZE = ara_config( + 'sqlalchemy_pool_size', + 'SQLALCHEMY_POOL_SIZE', + None, + value_type='integer' + ) + self.SQLALCHEMY_POOL_TIMEOUT = ara_config( + 'sqlalchemy_pool_timeout', + 'SQLALCHEMY_POOL_TIMEOUT', + None, + value_type='integer' + ) + self.SQLALCHEMY_POOL_RECYCLE = ara_config( + 'sqlalchemy_pool_recycle', + 'SQLALCHEMY_POOL_RECYCLE', + None, + value_type='integer' + ) self.DB_MIGRATIONS = os.path.join(ara_location, 'db') self.ARA_HOST = ara_config('host', 'ARA_HOST', '127.0.0.1') diff --git a/ara/tests/unit/test_config.py b/ara/tests/unit/test_config.py index b63c7f58..420dfea0 100644 --- a/ara/tests/unit/test_config.py +++ b/ara/tests/unit/test_config.py @@ -34,24 +34,27 @@ class TestConfig(TestAra): # TODO: Improve those def test_config_base(self): base_config = BaseConfig() - db = "sqlite:///%s/ansible.sqlite" % os.path.expanduser('~/.ara') + db = 'sqlite:///%s/ansible.sqlite' % os.path.expanduser('~/.ara') defaults = { - "FREEZER_IGNORE_MIMETYPE_WARNINGS": True, - "FREEZER_DEFAULT_MIMETYPE": "text/html", - "FREEZER_IGNORE_404_NOT_FOUND": True, - "ARA_DIR": os.path.expanduser('~/.ara'), - "SQLALCHEMY_DATABASE_URI": db, - "ARA_HOST": "127.0.0.1", - "ARA_AUTOCREATE_DATABASE": True, - "ARA_PORT": "9191", - "ARA_DATABASE": db, - "ARA_IGNORE_EMPTY_GENERATION": True, - "ARA_IGNORE_PARAMETERS": [ - "extra_vars" + 'FREEZER_IGNORE_MIMETYPE_WARNINGS': True, + 'FREEZER_DEFAULT_MIMETYPE': 'text/html', + 'FREEZER_IGNORE_404_NOT_FOUND': True, + 'ARA_DIR': os.path.expanduser('~/.ara'), + 'SQLALCHEMY_DATABASE_URI': db, + 'ARA_HOST': '127.0.0.1', + 'ARA_AUTOCREATE_DATABASE': True, + 'ARA_PORT': "9191", + 'ARA_DATABASE': db, + 'ARA_IGNORE_EMPTY_GENERATION': True, + 'ARA_IGNORE_PARAMETERS': [ + 'extra_vars' ], - "FREEZER_RELATIVE_URLS": True, - "SQLALCHEMY_TRACK_MODIFICATIONS": False, - "DB_MIGRATIONS": os.path.join(ara_location, 'db') + 'FREEZER_RELATIVE_URLS': True, + 'SQLALCHEMY_TRACK_MODIFICATIONS': False, + 'SQLALCHEMY_POOL_SIZE': None, + 'SQLALCHEMY_POOL_TIMEOUT': None, + 'SQLALCHEMY_POOL_RECYCLE': None, + 'DB_MIGRATIONS': os.path.join(ara_location, 'db') } for key, value in base_config.config.items(): diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index aff0655b..65c5777b 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -139,6 +139,17 @@ Parameters and their defaults +-------------------------------+----------------------------+-------------------------------------------+ | ARA_RESULT_PER_PAGE_ | result_per_page | 25  | +-------------------------------+----------------------------+-------------------------------------------+ +| SQLALCHEMY_POOL_SIZE_ | sqlalchemy_pool_size | None (default managed by flask-sqlalchemy)| ++-------------------------------+----------------------------+-------------------------------------------+ +| SQLALCHEMY_POOL_TIMEOUT_ | sqlalchemy_pool_timeout | None (default managed by flask-sqlalchemy)| ++-------------------------------+----------------------------+-------------------------------------------+ +| SQLALCHEMY_POOL_RECYCLE_ | sqlalchemy_pool_recycle | None (default managed by flask-sqlalchemy)| ++-------------------------------+----------------------------+-------------------------------------------+ + +.. _SQLALCHEMY_POOL_SIZE: http://flask-sqlalchemy.pocoo.org/2.3/config/#configuration-keys +.. _SQLALCHEMY_POOL_TIMEOUT: http://flask-sqlalchemy.pocoo.org/2.3/config/#configuration-keys +.. _SQLALCHEMY_POOL_RECYCLE: http://flask-sqlalchemy.pocoo.org/2.3/config/#configuration-keys + ARA_DIR ~~~~~~~